mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-03-04 08:57:22 +00:00
Rough implementation of region selection of endpoint for cosmos client. Still need to:
1 - Use separate context var to track selected region. Directly updating database account context throws off token generation by acquireMSALTokenForAccount 2 - Remove href overrides in acquireMSALTokenForAccount.
This commit is contained in:
parent
26ff12613e
commit
9116c7172f
@ -253,10 +253,13 @@ export function client(): Cosmos.CosmosClient {
|
|||||||
|
|
||||||
const currentWriteRegion = await client.getWriteEndpoint();
|
const currentWriteRegion = await client.getWriteEndpoint();
|
||||||
console.log(`Current write endpoint: ${JSON.stringify(currentWriteRegion)}`);
|
console.log(`Current write endpoint: ${JSON.stringify(currentWriteRegion)}`);
|
||||||
|
console.log(`Current userContext endpoint: ${JSON.stringify(userContext?.endpoint)}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const options: Cosmos.CosmosClientOptions = {
|
const options: Cosmos.CosmosClientOptions = {
|
||||||
endpoint: endpoint() || "https://cosmos.azure.com", // CosmosClient gets upset if we pass a bad URL. This should never actually get called
|
endpoint: endpoint() || "https://cosmos.azure.com", // CosmosClient gets upset if we pass a bad URL. This should never actually get called
|
||||||
|
// endpoint: "https://test-craig-nosql-westus3.documents.azure.com:443/",
|
||||||
|
// endpoint: "https://test-craig-nosql-eastus2.documents.azure.com:443/",
|
||||||
key: userContext.dataPlaneRbacEnabled ? "" : userContext.masterKey,
|
key: userContext.dataPlaneRbacEnabled ? "" : userContext.masterKey,
|
||||||
tokenProvider,
|
tokenProvider,
|
||||||
userAgentSuffix: "Azure Portal",
|
userAgentSuffix: "Azure Portal",
|
||||||
|
@ -273,6 +273,26 @@ export const SettingsPane: FunctionComponent<{ explorer: Explorer }> = ({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if region selection has been updated. Update database account in user context accordingly.
|
||||||
|
const updatedDatabaseAccount = {
|
||||||
|
...userContext.databaseAccount,
|
||||||
|
properties: {
|
||||||
|
...userContext.databaseAccount.properties,
|
||||||
|
documentEndpoint: userContext?.databaseAccount?.properties?.readLocations?.find(
|
||||||
|
(loc) => loc.locationName === readRegion,
|
||||||
|
)?.documentEndpoint,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
updateUserContext({
|
||||||
|
databaseAccount: updatedDatabaseAccount,
|
||||||
|
hasCosmosClientRegionSettingChanged: true,
|
||||||
|
});
|
||||||
|
console.log(
|
||||||
|
`userContext?.databaseAccount?.properties?.documentEndpoint details: ${JSON.stringify(
|
||||||
|
userContext?.databaseAccount?.properties?.documentEndpoint,
|
||||||
|
)}`,
|
||||||
|
);
|
||||||
|
|
||||||
LocalStorageUtility.setEntryBoolean(StorageKey.RUThresholdEnabled, ruThresholdEnabled);
|
LocalStorageUtility.setEntryBoolean(StorageKey.RUThresholdEnabled, ruThresholdEnabled);
|
||||||
LocalStorageUtility.setEntryBoolean(StorageKey.QueryTimeoutEnabled, queryTimeoutEnabled);
|
LocalStorageUtility.setEntryBoolean(StorageKey.QueryTimeoutEnabled, queryTimeoutEnabled);
|
||||||
LocalStorageUtility.setEntryString(StorageKey.ReadRegion, readRegion);
|
LocalStorageUtility.setEntryString(StorageKey.ReadRegion, readRegion);
|
||||||
@ -425,23 +445,6 @@ export const SettingsPane: FunctionComponent<{ explorer: Explorer }> = ({
|
|||||||
|
|
||||||
const handleOnReadRegionOptionChange = (ev: React.FormEvent<HTMLInputElement>, option: IDropdownOption): void => {
|
const handleOnReadRegionOptionChange = (ev: React.FormEvent<HTMLInputElement>, option: IDropdownOption): void => {
|
||||||
// TODO: Region validation?
|
// TODO: Region validation?
|
||||||
const updatedDatabaseAccount = {
|
|
||||||
...userContext.databaseAccount,
|
|
||||||
properties: {
|
|
||||||
...userContext.databaseAccount.properties,
|
|
||||||
documentEndpoint: userContext?.databaseAccount?.properties?.readLocations?.find(
|
|
||||||
(loc) => loc.locationName === readRegion,
|
|
||||||
)?.documentEndpoint,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
updateUserContext({
|
|
||||||
databaseAccount: updatedDatabaseAccount,
|
|
||||||
});
|
|
||||||
console.log(
|
|
||||||
`userContext?.databaseAccount?.properties?.documentEndpoint details: ${JSON.stringify(
|
|
||||||
userContext?.databaseAccount?.properties?.documentEndpoint,
|
|
||||||
)}`,
|
|
||||||
);
|
|
||||||
setReadRegion(option.text);
|
setReadRegion(option.text);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -73,10 +73,11 @@ export async function acquireMsalTokenForAccount(
|
|||||||
if (userContext.databaseAccount.properties?.documentEndpoint === undefined) {
|
if (userContext.databaseAccount.properties?.documentEndpoint === undefined) {
|
||||||
throw new Error("Database account has no document endpoint defined");
|
throw new Error("Database account has no document endpoint defined");
|
||||||
}
|
}
|
||||||
const hrefEndpoint = new URL(userContext.databaseAccount.properties.documentEndpoint).href.replace(
|
// const hrefEndpoint = new URL(userContext.databaseAccount.properties.documentEndpoint).href.replace(
|
||||||
/\/+$/,
|
// /\/+$/,
|
||||||
"/.default",
|
// "/.default",
|
||||||
);
|
// );
|
||||||
|
const hrefEndpoint = new URL("https://test-craig-nosql.documents.azure.com").href.replace(/\/+$/, "/.default");
|
||||||
const msalInstance = await getMsalInstance();
|
const msalInstance = await getMsalInstance();
|
||||||
const knownAccounts = msalInstance.getAllAccounts();
|
const knownAccounts = msalInstance.getAllAccounts();
|
||||||
// If user_hint is provided, we will try to use it to find the account.
|
// If user_hint is provided, we will try to use it to find the account.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user