diff --git a/src/Common/CosmosClient.ts b/src/Common/CosmosClient.ts index a56f644ea..fcd623981 100644 --- a/src/Common/CosmosClient.ts +++ b/src/Common/CosmosClient.ts @@ -26,14 +26,13 @@ export const tokenProvider = async (requestInfo: Cosmos.RequestInfo) => { return authorizationToken; } - if ((userContext.dataPlaneRbacEnabled) && userContext.authorizationToken) { - console.log(` Getting Portal Auth token `) - const AUTH_PREFIX = `type=aad&ver=1.0&sig=`; - const authorizationToken = `${AUTH_PREFIX}${userContext.authorizationToken}`; + if (userContext.dataPlaneRbacEnabled && userContext.authorizationToken) { + console.log(` Getting Portal Auth token `); + const authorizationToken = `${userContext.authorizationToken}`; console.log(`Returning Portal Auth token`); return authorizationToken; } - + if (configContext.platform === Platform.Emulator) { // TODO This SDK method mutates the headers object. Find a better one or fix the SDK. await Cosmos.setAuthorizationTokenHeaderUsingMasterKey(verb, resourceId, resourceType, headers, EmulatorMasterKey); diff --git a/src/Common/MongoProxyClient.ts b/src/Common/MongoProxyClient.ts index 860be2bee..d9aa0fb4c 100644 --- a/src/Common/MongoProxyClient.ts +++ b/src/Common/MongoProxyClient.ts @@ -710,4 +710,3 @@ async function errorHandling(response: Response, action: string, params: unknown export function getARMCreateCollectionEndpoint(params: DataModels.MongoParameters): string { return `subscriptions/${params.sid}/resourceGroups/${params.rg}/providers/Microsoft.DocumentDB/databaseAccounts/${userContext.databaseAccount.name}/mongodbDatabases/${params.db}/collections/${params.coll}`; } - diff --git a/src/Explorer/Panes/SettingsPane/SettingsPane.tsx b/src/Explorer/Panes/SettingsPane/SettingsPane.tsx index 8abb52ee9..98b22d8e8 100644 --- a/src/Explorer/Panes/SettingsPane/SettingsPane.tsx +++ b/src/Explorer/Panes/SettingsPane/SettingsPane.tsx @@ -48,8 +48,8 @@ export const SettingsPane: FunctionComponent<{ explorer: Explorer }> = ({ LocalStorageUtility.getEntryString(StorageKey.DataPlaneRbacEnabled) === Constants.RBACOptions.setAutomaticRBACOption ? Constants.RBACOptions.setAutomaticRBACOption : LocalStorageUtility.getEntryString(StorageKey.DataPlaneRbacEnabled) === Constants.RBACOptions.setTrueRBACOption - ? Constants.RBACOptions.setTrueRBACOption - : Constants.RBACOptions.setFalseRBACOption + ? Constants.RBACOptions.setTrueRBACOption + : Constants.RBACOptions.setFalseRBACOption, ); const [ruThresholdEnabled, setRUThresholdEnabled] = useState(isRUThresholdEnabled()); const [ruThreshold, setRUThreshold] = useState(getRUThreshold()); @@ -129,16 +129,7 @@ export const SettingsPane: FunctionComponent<{ explorer: Explorer }> = ({ LocalStorageUtility.setEntryNumber(StorageKey.CustomItemPerPage, customItemPerPage); - LocalStorageUtility.setEntryString( - StorageKey.DataPlaneRbacEnabled, - enableDataPlaneRBACOption - ); - - - LocalStorageUtility.setEntryString( - StorageKey.DataPlaneRbacEnabled, - enableDataPlaneRBACOption - ); + LocalStorageUtility.setEntryString(StorageKey.DataPlaneRbacEnabled, enableDataPlaneRBACOption); LocalStorageUtility.setEntryBoolean(StorageKey.RUThresholdEnabled, ruThresholdEnabled); LocalStorageUtility.setEntryBoolean(StorageKey.QueryTimeoutEnabled, queryTimeoutEnabled); @@ -230,7 +221,7 @@ export const SettingsPane: FunctionComponent<{ explorer: Explorer }> = ({ const dataPlaneRBACOptionsList: IChoiceGroupOption[] = [ { key: Constants.RBACOptions.setAutomaticRBACOption, text: "Automatic" }, { key: Constants.RBACOptions.setTrueRBACOption, text: "True" }, - { key: Constants.RBACOptions.setFalseRBACOption, text: "False"} + { key: Constants.RBACOptions.setFalseRBACOption, text: "False" }, ]; const defaultQueryResultsViewOptionList: IChoiceGroupOption[] = [ @@ -249,7 +240,10 @@ export const SettingsPane: FunctionComponent<{ explorer: Explorer }> = ({ setPageOption(option.key); }; - const handleOnDataPlaneRBACOptionChange = (ev: React.FormEvent, option: IChoiceGroupOption): void => { + const handleOnDataPlaneRBACOptionChange = ( + ev: React.FormEvent, + option: IChoiceGroupOption, + ): void => { setEnableDataPlaneRBACOption(option.key); }; @@ -413,7 +407,7 @@ export const SettingsPane: FunctionComponent<{ explorer: Explorer }> = ({ )} - {( + {
@@ -421,7 +415,8 @@ export const SettingsPane: FunctionComponent<{ explorer: Explorer }> = ({ Enable DataPlane RBAC - Choose Automatic to enable DataPlane RBAC automatically. True/False to voluntarily enable/disable DataPlane RBAC + Choose Automatic to enable DataPlane RBAC automatically. True/False to voluntarily enable/disable + DataPlane RBAC = ({
- )} - {( -
-
-
- - Enable DataPlane RBAC - - - Choose Automatic to enable DataPlane RBAC automatically. True/False to voluntarily enable/disable DataPlane RBAC - - -
-
-
- )} + } {userContext.apiType === "SQL" && ( <>
diff --git a/src/Explorer/Tables/TableDataClient.ts b/src/Explorer/Tables/TableDataClient.ts index 80e4b1ec5..a9d7c96a6 100644 --- a/src/Explorer/Tables/TableDataClient.ts +++ b/src/Explorer/Tables/TableDataClient.ts @@ -749,10 +749,6 @@ export class CassandraAPIDataClient extends TableDataClient { CassandraProxyEndpoints.Prod, ]; let canAccessCassandraProxy: boolean = userContext.databaseAccount.properties.publicNetworkAccess === "Enabled"; - if ( - configContext.CASSANDRA_PROXY_ENDPOINT !== CassandraProxyEndpoints.Development && - userContext.databaseAccount.properties.ipRules?.length > 0 - ) { if ( configContext.CASSANDRA_PROXY_ENDPOINT !== CassandraProxyEndpoints.Development && userContext.databaseAccount.properties.ipRules?.length > 0 @@ -767,4 +763,3 @@ export class CassandraAPIDataClient extends TableDataClient { ); } } -} diff --git a/src/hooks/useKnockoutExplorer.ts b/src/hooks/useKnockoutExplorer.ts index 70af4e603..60b10ae81 100644 --- a/src/hooks/useKnockoutExplorer.ts +++ b/src/hooks/useKnockoutExplorer.ts @@ -273,30 +273,26 @@ async function configureHostedWithAAD(config: AAD): Promise { } } try { - if(LocalStorageUtility.hasItem(StorageKey.DataPlaneRbacEnabled)) { - var isDataPlaneRbacSetting = LocalStorageUtility.getEntryString(StorageKey.DataPlaneRbacEnabled); - if (isDataPlaneRbacSetting == Constants.RBACOptions.setAutomaticRBACOption) - { - if (!account.properties.disableLocalAuth) { - keys = await listKeys(subscriptionId, resourceGroup, account.name); - } - else { - updateUserContext({ - dataPlaneRbacEnabled: true - }); - } - } - else if(isDataPlaneRbacSetting == Constants.RBACOptions.setTrueRBACOption) { - updateUserContext({ - dataPlaneRbacEnabled: true - }); - } - else { + if (LocalStorageUtility.hasItem(StorageKey.DataPlaneRbacEnabled)) { + const isDataPlaneRbacSetting = LocalStorageUtility.getEntryString(StorageKey.DataPlaneRbacEnabled); + if (isDataPlaneRbacSetting === Constants.RBACOptions.setAutomaticRBACOption) { + if (!account.properties.disableLocalAuth) { keys = await listKeys(subscriptionId, resourceGroup, account.name); + } else { updateUserContext({ - dataPlaneRbacEnabled: false + dataPlaneRbacEnabled: true, }); } + } else if (isDataPlaneRbacSetting === Constants.RBACOptions.setTrueRBACOption) { + updateUserContext({ + dataPlaneRbacEnabled: true, + }); + } else { + keys = await listKeys(subscriptionId, resourceGroup, account.name); + updateUserContext({ + dataPlaneRbacEnabled: false, + }); + } } } catch (e) { if (userContext.features.enableAadDataPlane) { @@ -418,10 +414,9 @@ async function configurePortal(): Promise { updateUserContext({ authType: AuthType.AAD, }); - - + let explorer: Explorer; - return new Promise(async (resolve) => { + 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 if (process.env.NODE_ENV === "development" && !window.location.search.includes("disablePortalInitCache")) { @@ -435,7 +430,6 @@ async function configurePortal(): Promise { updateContextsFromPortalMessage(message); explorer = new Explorer(); - // In development mode, save the iframe message from the portal in session storage. // This allows webpack hot reload to funciton properly if (process.env.NODE_ENV === "development") { @@ -459,7 +453,7 @@ async function configurePortal(): Promise { // Check for init message const message: PortalMessage = event.data?.data; - const inputs = message?.inputs; + const inputs = message?.inputs; const openAction = message?.openAction; if (inputs) { if ( @@ -478,39 +472,34 @@ async function configurePortal(): Promise { setTimeout(() => explorer.openNPSSurveyDialog(), 3000); } - let keys: DatabaseAccountListKeysResult = {}; const account = userContext.databaseAccount; const subscriptionId = userContext.subscriptionId; const resourceGroup = userContext.resourceGroup; - if(LocalStorageUtility.hasItem(StorageKey.DataPlaneRbacEnabled)) { - var isDataPlaneRbacSetting = LocalStorageUtility.getEntryString(StorageKey.DataPlaneRbacEnabled); - if (isDataPlaneRbacSetting == Constants.RBACOptions.setAutomaticRBACOption) - { - if (!account.properties.disableLocalAuth) { - keys = await listKeys(subscriptionId, resourceGroup, account.name); - } - else { - updateUserContext({ - dataPlaneRbacEnabled: true, - authorizationToken: message.inputs.authorizationToken - }); - } - } - else if(isDataPlaneRbacSetting == Constants.RBACOptions.setTrueRBACOption) { + if (LocalStorageUtility.hasItem(StorageKey.DataPlaneRbacEnabled)) { + const isDataPlaneRbacSetting = LocalStorageUtility.getEntryString(StorageKey.DataPlaneRbacEnabled); + if (isDataPlaneRbacSetting === Constants.RBACOptions.setAutomaticRBACOption) { + if (!account.properties.disableLocalAuth) { + await listKeys(subscriptionId, resourceGroup, account.name); + } else { updateUserContext({ dataPlaneRbacEnabled: true, - authorizationToken: message.inputs.authorizationToken - }); - } - else { - keys = await listKeys(subscriptionId, resourceGroup, account.name); - updateUserContext({ - dataPlaneRbacEnabled: false + authorizationToken: message.inputs.authorizationToken, }); } + } else if (isDataPlaneRbacSetting === Constants.RBACOptions.setTrueRBACOption) { + updateUserContext({ + dataPlaneRbacEnabled: true, + authorizationToken: message.inputs.authorizationToken, + }); + } else { + await listKeys(subscriptionId, resourceGroup, account.name); + updateUserContext({ + dataPlaneRbacEnabled: false, + }); + } } - + if (openAction) { handleOpenAction(openAction, useDatabases.getState().databases, explorer); } @@ -531,11 +520,9 @@ async function configurePortal(): Promise { }, false, ); - + sendReadyMessage(); - }); - } function shouldForwardMessage(message: PortalMessage, messageOrigin: string) {