mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-04-07 18:33:24 +01:00
Support readers (#105)
This commit is contained in:
parent
4f86015be7
commit
0f4ff0e49f
@ -351,6 +351,7 @@ export class HttpStatusCodes {
|
|||||||
public static readonly Created: number = 201;
|
public static readonly Created: number = 201;
|
||||||
public static readonly Accepted: number = 202;
|
public static readonly Accepted: number = 202;
|
||||||
public static readonly NoContent: number = 204;
|
public static readonly NoContent: number = 204;
|
||||||
|
public static readonly NotModified: number = 304;
|
||||||
public static readonly Unauthorized: number = 401;
|
public static readonly Unauthorized: number = 401;
|
||||||
public static readonly Forbidden: number = 403;
|
public static readonly Forbidden: number = 403;
|
||||||
public static readonly NotFound: number = 404;
|
public static readonly NotFound: number = 404;
|
||||||
|
@ -437,10 +437,8 @@ export interface Tenant {
|
|||||||
export interface AccountKeys {
|
export interface AccountKeys {
|
||||||
primaryMasterKey: string;
|
primaryMasterKey: string;
|
||||||
secondaryMasterKey: string;
|
secondaryMasterKey: string;
|
||||||
properties: {
|
|
||||||
primaryReadonlyMasterKey: string;
|
primaryReadonlyMasterKey: string;
|
||||||
secondaryReadonlyMasterKey: string;
|
secondaryReadonlyMasterKey: string;
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AfecFeature {
|
export interface AfecFeature {
|
||||||
|
@ -123,10 +123,18 @@ export abstract class ArmResourceUtils {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const fetchHeaders = await ArmResourceUtils._getAuthHeader(ArmResourceUtils._armAuthArea, tenantId);
|
const fetchHeaders = await ArmResourceUtils._getAuthHeader(ArmResourceUtils._armAuthArea, tenantId);
|
||||||
const url = `${ArmResourceUtils._armEndpoint}/${cosmosdbResourceId}/listKeys?api-version=${Constants.ArmApiVersions.documentDB}`;
|
const readWriteKeysUrl = `${ArmResourceUtils._armEndpoint}/${cosmosdbResourceId}/listKeys?api-version=${Constants.ArmApiVersions.documentDB}`;
|
||||||
|
const readOnlyKeysUrl = `${ArmResourceUtils._armEndpoint}/${cosmosdbResourceId}/readOnlyKeys?api-version=${Constants.ArmApiVersions.documentDB}`;
|
||||||
const response: Response = await fetch(url, { headers: fetchHeaders, method: "POST" });
|
let response: Response = await fetch(readWriteKeysUrl, { headers: fetchHeaders, method: "POST" });
|
||||||
const result: AccountKeys = response.status === 204 || response.status === 304 ? null : await response.json();
|
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) {
|
if (!response.ok) {
|
||||||
throw result;
|
throw result;
|
||||||
}
|
}
|
||||||
|
@ -568,8 +568,9 @@ export default class Main {
|
|||||||
|
|
||||||
this._explorer.hideConnectExplorerForm();
|
this._explorer.hideConnectExplorerForm();
|
||||||
|
|
||||||
|
const masterKey = Main._getMasterKey(keys);
|
||||||
HostedExplorerFactory.reInitializeDocumentClientUtilityForExplorer(this._explorer);
|
HostedExplorerFactory.reInitializeDocumentClientUtilityForExplorer(this._explorer);
|
||||||
Main._setExplorerReady(this._explorer, keys.primaryMasterKey, account, authorizationToken);
|
Main._setExplorerReady(this._explorer, masterKey, account, authorizationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static _handleGetAccessAadSucceed(response: [DatabaseAccount, AccountKeys, string]) {
|
private static _handleGetAccessAadSucceed(response: [DatabaseAccount, AccountKeys, string]) {
|
||||||
@ -577,12 +578,21 @@ export default class Main {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const account = response[0];
|
const account = response[0];
|
||||||
const keys = response[1];
|
const masterKey = Main._getMasterKey(response[1]);
|
||||||
const authorizationToken = response[2];
|
const authorizationToken = response[2];
|
||||||
Main._setExplorerReady(this._explorer, keys.primaryMasterKey, account, authorizationToken);
|
Main._setExplorerReady(this._explorer, masterKey, account, authorizationToken);
|
||||||
this._getAadAccessDeferred.resolve(this._explorer);
|
this._getAadAccessDeferred.resolve(this._explorer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static _getMasterKey(keys: AccountKeys): string {
|
||||||
|
return (
|
||||||
|
keys?.primaryMasterKey ??
|
||||||
|
keys?.secondaryMasterKey ??
|
||||||
|
keys?.primaryReadonlyMasterKey ??
|
||||||
|
keys?.secondaryReadonlyMasterKey
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
private static _handleGetAccessAadFailed(error: any) {
|
private static _handleGetAccessAadFailed(error: any) {
|
||||||
this._getAadAccessDeferred.reject(error);
|
this._getAadAccessDeferred.reject(error);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user