Address bug in fetching data for Tables Account
This commit is contained in:
parent
3e48393fbb
commit
4015b9275b
|
@ -90,6 +90,12 @@ export const tokenProvider = async (requestInfo: Cosmos.RequestInfo) => {
|
|||
}
|
||||
}
|
||||
|
||||
let retryAttempts: number = 50;
|
||||
while (retryAttempts > 0 && userContext.listKeysFetchInProgress) {
|
||||
retryAttempts--;
|
||||
await sleep(100);
|
||||
}
|
||||
|
||||
if (userContext.masterKey) {
|
||||
// TODO This SDK method mutates the headers object. Find a better one or fix the SDK.
|
||||
await Cosmos.setAuthorizationTokenHeaderUsingMasterKey(
|
||||
|
@ -127,6 +133,10 @@ export const tokenProvider = async (requestInfo: Cosmos.RequestInfo) => {
|
|||
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) => {
|
||||
requestContext.endpoint = new URL(configContext.PROXY_PATH, window.location.href).href;
|
||||
requestContext.headers["x-ms-proxy-target"] = endpoint();
|
||||
|
|
|
@ -73,6 +73,7 @@ export interface UserContext {
|
|||
readonly fabricContext?: FabricContext;
|
||||
readonly authType?: AuthType;
|
||||
readonly masterKey?: string;
|
||||
readonly listKeysFetchInProgress?: boolean;
|
||||
readonly subscriptionId?: string;
|
||||
readonly resourceGroup?: string;
|
||||
readonly databaseAccount?: DatabaseAccount;
|
||||
|
|
|
@ -503,10 +503,9 @@ async function configurePortal(): Promise<Explorer> {
|
|||
useDataPlaneRbac.setState({ dataPlaneRbacEnabled: dataPlaneRbacEnabled });
|
||||
}
|
||||
} else {
|
||||
const keys: DatabaseAccountListKeysResult = await listKeys(subscriptionId, resourceGroup, account.name);
|
||||
updateUserContext({
|
||||
masterKey: keys.primaryMasterKey,
|
||||
});
|
||||
(async () => {
|
||||
await fetchAndUpdateKeys(subscriptionId, resourceGroup, account.name);
|
||||
})();
|
||||
}
|
||||
|
||||
if (openAction) {
|
||||
|
@ -536,6 +535,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) {
|
||||
// Only allow forwarding messages from the same origin
|
||||
return messageOrigin === window.document.location.origin && message.type === MessageTypes.TelemetryInfo;
|
||||
|
@ -573,6 +584,7 @@ function updateContextsFromPortalMessage(inputs: DataExplorerInputsFrame) {
|
|||
collectionCreationDefaults: inputs.defaultCollectionThroughput,
|
||||
isTryCosmosDBSubscription: inputs.isTryCosmosDBSubscription,
|
||||
feedbackPolicies: inputs.feedbackPolicies,
|
||||
listKeysFetchInProgress: false,
|
||||
});
|
||||
|
||||
if (inputs.isPostgresAccount) {
|
||||
|
|
Loading…
Reference in New Issue