mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2026-01-06 19:19:56 +00:00
Support readers (#105)
This commit is contained in:
committed by
GitHub
parent
4f86015be7
commit
0f4ff0e49f
@@ -123,10 +123,18 @@ export abstract class ArmResourceUtils {
|
||||
|
||||
try {
|
||||
const fetchHeaders = await ArmResourceUtils._getAuthHeader(ArmResourceUtils._armAuthArea, tenantId);
|
||||
const url = `${ArmResourceUtils._armEndpoint}/${cosmosdbResourceId}/listKeys?api-version=${Constants.ArmApiVersions.documentDB}`;
|
||||
|
||||
const response: Response = await fetch(url, { headers: fetchHeaders, method: "POST" });
|
||||
const result: AccountKeys = response.status === 204 || response.status === 304 ? null : await response.json();
|
||||
const readWriteKeysUrl = `${ArmResourceUtils._armEndpoint}/${cosmosdbResourceId}/listKeys?api-version=${Constants.ArmApiVersions.documentDB}`;
|
||||
const readOnlyKeysUrl = `${ArmResourceUtils._armEndpoint}/${cosmosdbResourceId}/readOnlyKeys?api-version=${Constants.ArmApiVersions.documentDB}`;
|
||||
let response: Response = await fetch(readWriteKeysUrl, { headers: fetchHeaders, method: "POST" });
|
||||
if (response.status === Constants.HttpStatusCodes.Forbidden) {
|
||||
// fetch read only keys for readers
|
||||
response = await fetch(readOnlyKeysUrl, { headers: fetchHeaders, method: "POST" });
|
||||
}
|
||||
const result: AccountKeys =
|
||||
response.status === Constants.HttpStatusCodes.NoContent ||
|
||||
response.status === Constants.HttpStatusCodes.NotModified
|
||||
? null
|
||||
: await response.json();
|
||||
if (!response.ok) {
|
||||
throw result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user