Address errors and checks

This commit is contained in:
Senthamil Sindhu 2024-06-19 21:00:55 -07:00
parent 8849526fab
commit 4792e2d1c7
5 changed files with 55 additions and 101 deletions

View File

@ -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);

View File

@ -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}`;
}

View File

@ -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<boolean>(isRUThresholdEnabled());
const [ruThreshold, setRUThreshold] = useState<number>(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<HTMLInputElement>, option: IChoiceGroupOption): void => {
const handleOnDataPlaneRBACOptionChange = (
ev: React.FormEvent<HTMLInputElement>,
option: IChoiceGroupOption,
): void => {
setEnableDataPlaneRBACOption(option.key);
};
@ -413,7 +407,7 @@ export const SettingsPane: FunctionComponent<{ explorer: Explorer }> = ({
</div>
</div>
)}
{(
{
<div className="settingsSection">
<div className="settingsSectionPart">
<fieldset>
@ -421,7 +415,8 @@ export const SettingsPane: FunctionComponent<{ explorer: Explorer }> = ({
Enable DataPlane RBAC
</legend>
<InfoTooltip>
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
</InfoTooltip>
<ChoiceGroup
ariaLabelledBy="enableDataPlaneRBACOptions"
@ -433,28 +428,7 @@ export const SettingsPane: FunctionComponent<{ explorer: Explorer }> = ({
</fieldset>
</div>
</div>
)}
{(
<div className="settingsSection">
<div className="settingsSectionPart">
<fieldset>
<legend id="enableDataPlaneRBACOptions" className="settingsSectionLabel legendLabel">
Enable DataPlane RBAC
</legend>
<InfoTooltip>
Choose Automatic to enable DataPlane RBAC automatically. True/False to voluntarily enable/disable DataPlane RBAC
</InfoTooltip>
<ChoiceGroup
ariaLabelledBy="enableDataPlaneRBACOptions"
selectedKey={enableDataPlaneRBACOption}
options={dataPlaneRBACOptionsList}
styles={choiceButtonStyles}
onChange={handleOnDataPlaneRBACOptionChange}
/>
</fieldset>
</div>
</div>
)}
}
{userContext.apiType === "SQL" && (
<>
<div className="settingsSection">

View File

@ -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 {
);
}
}
}

View File

@ -273,30 +273,26 @@ async function configureHostedWithAAD(config: AAD): Promise<Explorer> {
}
}
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<Explorer> {
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<Explorer> {
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<Explorer> {
// 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<Explorer> {
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<Explorer> {
},
false,
);
sendReadyMessage();
});
}
function shouldForwardMessage(message: PortalMessage, messageOrigin: string) {