From 521ff39eb00df1e3475d09c1b776fc55ae475edd Mon Sep 17 00:00:00 2001 From: Senthamil Sindhu Date: Fri, 19 Jul 2024 07:48:12 -0700 Subject: [PATCH] Resolve conflicts --- src/hooks/useKnockoutExplorer.ts | 34 ++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/hooks/useKnockoutExplorer.ts b/src/hooks/useKnockoutExplorer.ts index e261dfbf5..fcf1d314e 100644 --- a/src/hooks/useKnockoutExplorer.ts +++ b/src/hooks/useKnockoutExplorer.ts @@ -453,25 +453,33 @@ function configureEmulator(): Explorer { return explorer; } -async function fetchAndUpdateKeys(subscriptionId: string, resourceGroup: string, account: string) { +export async function fetchAndUpdateKeys(subscriptionId: string, resourceGroup: string, account: string) { + Logger.logInfo(`Fetching keys for ${userContext.apiType} account ${account}`, "Explorer/fetchAndUpdateKeys"); + let keys; try { - Logger.logInfo(`Fetching keys for ${userContext.apiType} account ${account}`, "Explorer/fetchAndUpdateKeys"); - const keys = await listKeys(subscriptionId, resourceGroup, account); + keys = await listKeys(subscriptionId, resourceGroup, account); Logger.logInfo(`Keys fetched for ${userContext.apiType} account ${account}`, "Explorer/fetchAndUpdateKeys"); updateUserContext({ masterKey: keys.primaryMasterKey, }); - Logger.logInfo( - `User context updated with Master key for ${userContext.apiType} account ${account}`, - "Explorer/fetchAndUpdateKeys", - ); } catch (error) { - logConsoleError(`Error occurred fetching keys for the account." ${error.message}`); - Logger.logError( - `Error during fetching keys or updating user context: ${error} for ${userContext.apiType} account ${account}`, - "Explorer/fetchAndUpdateKeys", - ); - throw error; + if (error.code === "AuthorizationFailed") { + keys = await getReadOnlyKeys(subscriptionId, resourceGroup, account); + Logger.logInfo( + `Read only Keys fetched for ${userContext.apiType} account ${account}`, + "Explorer/fetchAndUpdateKeys", + ); + updateUserContext({ + masterKey: keys.primaryReadonlyMasterKey, + }); + } else { + logConsoleError(`Error occurred fetching keys for the account." ${error.message}`); + Logger.logError( + `Error during fetching keys or updating user context: ${error} for ${userContext.apiType} account ${account}`, + "Explorer/fetchAndUpdateKeys", + ); + throw error; + } } }