Address bug in fetching data for Tables Account
This commit is contained in:
parent
8b4d9bd354
commit
9274f50500
|
@ -81,6 +81,12 @@ export const tokenProvider = async (requestInfo: Cosmos.RequestInfo) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let retryAttempts: number = 50;
|
||||||
|
while (retryAttempts > 0 && userContext.listKeysFetchInProgress) {
|
||||||
|
retryAttempts--;
|
||||||
|
await sleep(100);
|
||||||
|
}
|
||||||
|
|
||||||
if (userContext.masterKey) {
|
if (userContext.masterKey) {
|
||||||
// TODO This SDK method mutates the headers object. Find a better one or fix the SDK.
|
// TODO This SDK method mutates the headers object. Find a better one or fix the SDK.
|
||||||
await Cosmos.setAuthorizationTokenHeaderUsingMasterKey(
|
await Cosmos.setAuthorizationTokenHeaderUsingMasterKey(
|
||||||
|
@ -118,6 +124,10 @@ export const tokenProvider = async (requestInfo: Cosmos.RequestInfo) => {
|
||||||
return decodeURIComponent(result.PrimaryReadWriteToken);
|
return decodeURIComponent(result.PrimaryReadWriteToken);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function sleep(ms: number) {
|
||||||
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||||
|
}
|
||||||
|
|
||||||
export const requestPlugin: Cosmos.Plugin<any> = async (requestContext, diagnosticNode, next) => {
|
export const requestPlugin: Cosmos.Plugin<any> = async (requestContext, diagnosticNode, next) => {
|
||||||
requestContext.endpoint = new URL(configContext.PROXY_PATH, window.location.href).href;
|
requestContext.endpoint = new URL(configContext.PROXY_PATH, window.location.href).href;
|
||||||
requestContext.headers["x-ms-proxy-target"] = endpoint();
|
requestContext.headers["x-ms-proxy-target"] = endpoint();
|
||||||
|
|
|
@ -73,6 +73,7 @@ export interface UserContext {
|
||||||
readonly fabricContext?: FabricContext;
|
readonly fabricContext?: FabricContext;
|
||||||
readonly authType?: AuthType;
|
readonly authType?: AuthType;
|
||||||
readonly masterKey?: string;
|
readonly masterKey?: string;
|
||||||
|
readonly listKeysFetchInProgress?: boolean;
|
||||||
readonly subscriptionId?: string;
|
readonly subscriptionId?: string;
|
||||||
readonly resourceGroup?: string;
|
readonly resourceGroup?: string;
|
||||||
readonly databaseAccount?: DatabaseAccount;
|
readonly databaseAccount?: DatabaseAccount;
|
||||||
|
|
|
@ -499,10 +499,9 @@ async function configurePortal(): Promise<Explorer> {
|
||||||
useDataPlaneRbac.setState({ dataPlaneRbacEnabled: dataPlaneRbacEnabled });
|
useDataPlaneRbac.setState({ dataPlaneRbacEnabled: dataPlaneRbacEnabled });
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const keys: DatabaseAccountListKeysResult = await listKeys(subscriptionId, resourceGroup, account.name);
|
(async () => {
|
||||||
updateUserContext({
|
await fetchAndUpdateKeys(subscriptionId, resourceGroup, account.name);
|
||||||
masterKey: keys.primaryMasterKey,
|
})();
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (openAction) {
|
if (openAction) {
|
||||||
|
@ -530,6 +529,18 @@ async function configurePortal(): Promise<Explorer> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function fetchAndUpdateKeys(subscriptionId: string, resourceGroup: string, account: string) {
|
||||||
|
try {
|
||||||
|
updateUserContext({ listKeysFetchInProgress: true });
|
||||||
|
const keys = await listKeys(subscriptionId, resourceGroup, account);
|
||||||
|
|
||||||
|
updateUserContext({ masterKey: keys.primaryMasterKey, listKeysFetchInProgress: false });
|
||||||
|
} catch (error) {
|
||||||
|
updateUserContext({ listKeysFetchInProgress: false });
|
||||||
|
console.error("Error during fetching keys or updating user context:", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function shouldForwardMessage(message: PortalMessage, messageOrigin: string) {
|
function shouldForwardMessage(message: PortalMessage, messageOrigin: string) {
|
||||||
// Only allow forwarding messages from the same origin
|
// Only allow forwarding messages from the same origin
|
||||||
return messageOrigin === window.document.location.origin && message.type === MessageTypes.TelemetryInfo;
|
return messageOrigin === window.document.location.origin && message.type === MessageTypes.TelemetryInfo;
|
||||||
|
@ -567,6 +578,7 @@ function updateContextsFromPortalMessage(inputs: DataExplorerInputsFrame) {
|
||||||
collectionCreationDefaults: inputs.defaultCollectionThroughput,
|
collectionCreationDefaults: inputs.defaultCollectionThroughput,
|
||||||
isTryCosmosDBSubscription: inputs.isTryCosmosDBSubscription,
|
isTryCosmosDBSubscription: inputs.isTryCosmosDBSubscription,
|
||||||
feedbackPolicies: inputs.feedbackPolicies,
|
feedbackPolicies: inputs.feedbackPolicies,
|
||||||
|
listKeysFetchInProgress: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (inputs.isPostgresAccount) {
|
if (inputs.isPostgresAccount) {
|
||||||
|
|
Loading…
Reference in New Issue