mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-23 02:41:39 +00:00
Compare commits
44 Commits
master
...
users/sind
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
039136794d | ||
|
|
caf4e9f51f | ||
|
|
22144982bd | ||
|
|
3e48393fbb | ||
|
|
9274f50500 | ||
|
|
8b4d9bd354 | ||
|
|
2c78625f83 | ||
|
|
0079a9147f | ||
|
|
602a697fe9 | ||
|
|
28d8216b32 | ||
|
|
3b9261ef76 | ||
|
|
6be839991f | ||
|
|
72eca5ed79 | ||
|
|
473a6d34bd | ||
|
|
912688dc14 | ||
|
|
805d72c55b | ||
|
|
eb7c737066 | ||
|
|
478467bda5 | ||
|
|
fd3a83dcd8 | ||
|
|
713df1869a | ||
|
|
192a275139 | ||
|
|
77ee359adb | ||
|
|
a50108c375 | ||
|
|
d3fb5eabdb | ||
|
|
4792e2d1c7 | ||
|
|
8849526fab | ||
|
|
24af64a66d | ||
|
|
be871737ad | ||
|
|
4d8bb5c3ea | ||
|
|
10a8505b9a | ||
|
|
ef7c2fe2f7 | ||
|
|
4c7aca95e1 | ||
|
|
2243ad895a | ||
|
|
b2d5f91fe1 | ||
|
|
a712193477 | ||
|
|
5ee411693c | ||
|
|
16c7b2567b | ||
|
|
78d9a0cd8d | ||
|
|
c6ad538559 | ||
|
|
2bc09a6efe | ||
|
|
d3a3033b25 | ||
|
|
6bdc714e11 | ||
|
|
5042f28229 | ||
|
|
e1430fd06f |
@@ -3,12 +3,10 @@ import { getAuthorizationTokenUsingResourceTokens } from "Common/getAuthorizatio
|
||||
import { AuthorizationToken } from "Contracts/FabricMessageTypes";
|
||||
import { checkDatabaseResourceTokensValidity } from "Platform/Fabric/FabricUtil";
|
||||
import { LocalStorageUtility, StorageKey } from "Shared/StorageUtility";
|
||||
import { listKeys } from "Utils/arm/generatedClients/cosmos/databaseAccounts";
|
||||
import { DatabaseAccountListKeysResult } from "Utils/arm/generatedClients/cosmos/types";
|
||||
import { AuthType } from "../AuthType";
|
||||
import { PriorityLevel } from "../Common/Constants";
|
||||
import { Platform, configContext } from "../ConfigContext";
|
||||
import { updateUserContext, userContext } from "../UserContext";
|
||||
import { userContext } from "../UserContext";
|
||||
import { logConsoleError } from "../Utils/NotificationConsoleUtils";
|
||||
import * as PriorityBasedExecutionUtils from "../Utils/PriorityBasedExecutionUtils";
|
||||
import { EmulatorMasterKey, HttpHeaders } from "./Constants";
|
||||
@@ -91,22 +89,6 @@ export const tokenProvider = async (requestInfo: Cosmos.RequestInfo) => {
|
||||
userContext.masterKey,
|
||||
);
|
||||
return decodeURIComponent(headers.authorization);
|
||||
} else if (userContext.dataPlaneRbacEnabled == false) {
|
||||
const { databaseAccount: account, subscriptionId, resourceGroup } = userContext;
|
||||
const keys: DatabaseAccountListKeysResult = await listKeys(subscriptionId, resourceGroup, account.name);
|
||||
|
||||
if (keys.primaryMasterKey) {
|
||||
updateUserContext({ masterKey: keys.primaryMasterKey });
|
||||
// TODO This SDK method mutates the headers object. Find a better one or fix the SDK.
|
||||
await Cosmos.setAuthorizationTokenHeaderUsingMasterKey(
|
||||
verb,
|
||||
resourceId,
|
||||
resourceType,
|
||||
headers,
|
||||
keys.primaryMasterKey,
|
||||
);
|
||||
return decodeURIComponent(headers.authorization);
|
||||
}
|
||||
}
|
||||
|
||||
if (userContext.resourceToken) {
|
||||
@@ -190,6 +172,7 @@ export function client(): Cosmos.CosmosClient {
|
||||
|
||||
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
|
||||
key: userContext.dataPlaneRbacEnabled ? "" : userContext.masterKey,
|
||||
tokenProvider,
|
||||
userAgentSuffix: "Azure Portal",
|
||||
defaultHeaders: _defaultHeaders,
|
||||
|
||||
@@ -36,6 +36,8 @@ import Explorer from "../../Explorer";
|
||||
import { RightPaneForm, RightPaneFormProps } from "../RightPaneForm/RightPaneForm";
|
||||
import { AuthType } from "AuthType";
|
||||
import create, { UseStore } from "zustand";
|
||||
import { DatabaseAccountListKeysResult } from "@azure/arm-cosmosdb/esm/models";
|
||||
import { listKeys } from "Utils/arm/generatedClients/cosmos/databaseAccounts";
|
||||
|
||||
export interface DataPlaneRbacState {
|
||||
dataPlaneRbacEnabled: boolean;
|
||||
@@ -166,7 +168,14 @@ export const SettingsPane: FunctionComponent<{ explorer: Explorer }> = ({
|
||||
updateUserContext({
|
||||
dataPlaneRbacEnabled: false,
|
||||
});
|
||||
useDataPlaneRbac.setState({ dataPlaneRbacEnabled: false });
|
||||
const { databaseAccount: account, subscriptionId, resourceGroup } = userContext;
|
||||
const keys: DatabaseAccountListKeysResult = await listKeys(subscriptionId, resourceGroup, account.name);
|
||||
|
||||
if (keys.primaryMasterKey) {
|
||||
updateUserContext({ masterKey: keys.primaryMasterKey });
|
||||
|
||||
useDataPlaneRbac.setState({ dataPlaneRbacEnabled: false });
|
||||
}
|
||||
}
|
||||
|
||||
LocalStorageUtility.setEntryBoolean(StorageKey.RUThresholdEnabled, ruThresholdEnabled);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -417,11 +417,29 @@ function configureEmulator(): Explorer {
|
||||
return explorer;
|
||||
}
|
||||
|
||||
async function fetchAndUpdateKeys(subscriptionId: string, resourceGroup: string, account: string) {
|
||||
try {
|
||||
console.log("Starting to fetch keys...");
|
||||
const keys = await listKeys(subscriptionId, resourceGroup, account);
|
||||
console.log("Keys fetched:", keys);
|
||||
|
||||
updateUserContext({
|
||||
masterKey: keys.primaryMasterKey,
|
||||
});
|
||||
|
||||
console.log("User context updated with master key.");
|
||||
} catch (error) {
|
||||
console.error("Error during fetching keys or updating user context:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async function configurePortal(): Promise<Explorer> {
|
||||
updateUserContext({
|
||||
authType: AuthType.AAD,
|
||||
});
|
||||
let explorer: Explorer;
|
||||
|
||||
return new Promise((resolve) => {
|
||||
// In development mode, try to load the iframe message from session storage.
|
||||
// This allows webpack hot reload to function properly in the portal
|
||||
@@ -470,12 +488,6 @@ async function configurePortal(): Promise<Explorer> {
|
||||
}
|
||||
|
||||
updateContextsFromPortalMessage(inputs);
|
||||
explorer = new Explorer();
|
||||
resolve(explorer);
|
||||
|
||||
if (userContext.apiType === "Postgres" || userContext.apiType === "SQL" || userContext.apiType === "Mongo") {
|
||||
setTimeout(() => explorer.openNPSSurveyDialog(), 3000);
|
||||
}
|
||||
|
||||
const { databaseAccount: account, subscriptionId, resourceGroup } = userContext;
|
||||
|
||||
@@ -489,20 +501,30 @@ async function configurePortal(): Promise<Explorer> {
|
||||
} else {
|
||||
dataPlaneRbacEnabled = isDataPlaneRbacSetting === Constants.RBACOptions.setTrueRBACOption;
|
||||
}
|
||||
if (!dataPlaneRbacEnabled) {
|
||||
await fetchAndUpdateKeys(subscriptionId, resourceGroup, account.name);
|
||||
}
|
||||
|
||||
updateUserContext({ dataPlaneRbacEnabled });
|
||||
useDataPlaneRbac.setState({ dataPlaneRbacEnabled: dataPlaneRbacEnabled });
|
||||
} else {
|
||||
const dataPlaneRbacEnabled = account.properties.disableLocalAuth;
|
||||
|
||||
if (!dataPlaneRbacEnabled) {
|
||||
await fetchAndUpdateKeys(subscriptionId, resourceGroup, account.name);
|
||||
}
|
||||
|
||||
updateUserContext({ dataPlaneRbacEnabled });
|
||||
useDataPlaneRbac.setState({ dataPlaneRbacEnabled: dataPlaneRbacEnabled });
|
||||
}
|
||||
} else {
|
||||
const keys: DatabaseAccountListKeysResult = await listKeys(subscriptionId, resourceGroup, account.name);
|
||||
updateUserContext({
|
||||
masterKey: keys.primaryMasterKey,
|
||||
});
|
||||
await fetchAndUpdateKeys(subscriptionId, resourceGroup, account.name);
|
||||
}
|
||||
|
||||
explorer = new Explorer();
|
||||
resolve(explorer);
|
||||
if (userContext.apiType === "Postgres" || userContext.apiType === "SQL" || userContext.apiType === "Mongo") {
|
||||
setTimeout(() => explorer.openNPSSurveyDialog(), 3000);
|
||||
}
|
||||
|
||||
if (openAction) {
|
||||
@@ -547,6 +569,11 @@ function updateContextsFromPortalMessage(inputs: DataExplorerInputsFrame) {
|
||||
const authorizationToken = inputs.authorizationToken || "";
|
||||
const databaseAccount = inputs.databaseAccount;
|
||||
|
||||
if (userContext.apiType !== "SQL") {
|
||||
const masterKey = inputs.masterKey || "";
|
||||
updateUserContext({ masterKey });
|
||||
}
|
||||
|
||||
updateConfigContext({
|
||||
BACKEND_ENDPOINT: inputs.extensionEndpoint || configContext.BACKEND_ENDPOINT,
|
||||
ARM_ENDPOINT: normalizeArmEndpoint(inputs.csmEndpoint || configContext.ARM_ENDPOINT),
|
||||
@@ -567,6 +594,7 @@ function updateContextsFromPortalMessage(inputs: DataExplorerInputsFrame) {
|
||||
collectionCreationDefaults: inputs.defaultCollectionThroughput,
|
||||
isTryCosmosDBSubscription: inputs.isTryCosmosDBSubscription,
|
||||
feedbackPolicies: inputs.feedbackPolicies,
|
||||
listKeysFetchInProgress: false,
|
||||
});
|
||||
|
||||
if (inputs.isPostgresAccount) {
|
||||
|
||||
Reference in New Issue
Block a user