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,10 +26,9 @@ export const tokenProvider = async (requestInfo: Cosmos.RequestInfo) => {
return authorizationToken; return authorizationToken;
} }
if ((userContext.dataPlaneRbacEnabled) && userContext.authorizationToken) { if (userContext.dataPlaneRbacEnabled && userContext.authorizationToken) {
console.log(` Getting Portal Auth token `) console.log(` Getting Portal Auth token `);
const AUTH_PREFIX = `type=aad&ver=1.0&sig=`; const authorizationToken = `${userContext.authorizationToken}`;
const authorizationToken = `${AUTH_PREFIX}${userContext.authorizationToken}`;
console.log(`Returning Portal Auth token`); console.log(`Returning Portal Auth token`);
return authorizationToken; return authorizationToken;
} }

View File

@ -710,4 +710,3 @@ async function errorHandling(response: Response, action: string, params: unknown
export function getARMCreateCollectionEndpoint(params: DataModels.MongoParameters): string { 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}`; return `subscriptions/${params.sid}/resourceGroups/${params.rg}/providers/Microsoft.DocumentDB/databaseAccounts/${userContext.databaseAccount.name}/mongodbDatabases/${params.db}/collections/${params.coll}`;
} }

View File

@ -49,7 +49,7 @@ export const SettingsPane: FunctionComponent<{ explorer: Explorer }> = ({
? Constants.RBACOptions.setAutomaticRBACOption ? Constants.RBACOptions.setAutomaticRBACOption
: LocalStorageUtility.getEntryString(StorageKey.DataPlaneRbacEnabled) === Constants.RBACOptions.setTrueRBACOption : LocalStorageUtility.getEntryString(StorageKey.DataPlaneRbacEnabled) === Constants.RBACOptions.setTrueRBACOption
? Constants.RBACOptions.setTrueRBACOption ? Constants.RBACOptions.setTrueRBACOption
: Constants.RBACOptions.setFalseRBACOption : Constants.RBACOptions.setFalseRBACOption,
); );
const [ruThresholdEnabled, setRUThresholdEnabled] = useState<boolean>(isRUThresholdEnabled()); const [ruThresholdEnabled, setRUThresholdEnabled] = useState<boolean>(isRUThresholdEnabled());
const [ruThreshold, setRUThreshold] = useState<number>(getRUThreshold()); const [ruThreshold, setRUThreshold] = useState<number>(getRUThreshold());
@ -129,16 +129,7 @@ export const SettingsPane: FunctionComponent<{ explorer: Explorer }> = ({
LocalStorageUtility.setEntryNumber(StorageKey.CustomItemPerPage, customItemPerPage); LocalStorageUtility.setEntryNumber(StorageKey.CustomItemPerPage, customItemPerPage);
LocalStorageUtility.setEntryString( LocalStorageUtility.setEntryString(StorageKey.DataPlaneRbacEnabled, enableDataPlaneRBACOption);
StorageKey.DataPlaneRbacEnabled,
enableDataPlaneRBACOption
);
LocalStorageUtility.setEntryString(
StorageKey.DataPlaneRbacEnabled,
enableDataPlaneRBACOption
);
LocalStorageUtility.setEntryBoolean(StorageKey.RUThresholdEnabled, ruThresholdEnabled); LocalStorageUtility.setEntryBoolean(StorageKey.RUThresholdEnabled, ruThresholdEnabled);
LocalStorageUtility.setEntryBoolean(StorageKey.QueryTimeoutEnabled, queryTimeoutEnabled); LocalStorageUtility.setEntryBoolean(StorageKey.QueryTimeoutEnabled, queryTimeoutEnabled);
@ -230,7 +221,7 @@ export const SettingsPane: FunctionComponent<{ explorer: Explorer }> = ({
const dataPlaneRBACOptionsList: IChoiceGroupOption[] = [ const dataPlaneRBACOptionsList: IChoiceGroupOption[] = [
{ key: Constants.RBACOptions.setAutomaticRBACOption, text: "Automatic" }, { key: Constants.RBACOptions.setAutomaticRBACOption, text: "Automatic" },
{ key: Constants.RBACOptions.setTrueRBACOption, text: "True" }, { key: Constants.RBACOptions.setTrueRBACOption, text: "True" },
{ key: Constants.RBACOptions.setFalseRBACOption, text: "False"} { key: Constants.RBACOptions.setFalseRBACOption, text: "False" },
]; ];
const defaultQueryResultsViewOptionList: IChoiceGroupOption[] = [ const defaultQueryResultsViewOptionList: IChoiceGroupOption[] = [
@ -249,7 +240,10 @@ export const SettingsPane: FunctionComponent<{ explorer: Explorer }> = ({
setPageOption(option.key); setPageOption(option.key);
}; };
const handleOnDataPlaneRBACOptionChange = (ev: React.FormEvent<HTMLInputElement>, option: IChoiceGroupOption): void => { const handleOnDataPlaneRBACOptionChange = (
ev: React.FormEvent<HTMLInputElement>,
option: IChoiceGroupOption,
): void => {
setEnableDataPlaneRBACOption(option.key); setEnableDataPlaneRBACOption(option.key);
}; };
@ -413,7 +407,7 @@ export const SettingsPane: FunctionComponent<{ explorer: Explorer }> = ({
</div> </div>
</div> </div>
)} )}
{( {
<div className="settingsSection"> <div className="settingsSection">
<div className="settingsSectionPart"> <div className="settingsSectionPart">
<fieldset> <fieldset>
@ -421,7 +415,8 @@ export const SettingsPane: FunctionComponent<{ explorer: Explorer }> = ({
Enable DataPlane RBAC Enable DataPlane RBAC
</legend> </legend>
<InfoTooltip> <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> </InfoTooltip>
<ChoiceGroup <ChoiceGroup
ariaLabelledBy="enableDataPlaneRBACOptions" ariaLabelledBy="enableDataPlaneRBACOptions"
@ -433,28 +428,7 @@ export const SettingsPane: FunctionComponent<{ explorer: Explorer }> = ({
</fieldset> </fieldset>
</div> </div>
</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" && ( {userContext.apiType === "SQL" && (
<> <>
<div className="settingsSection"> <div className="settingsSection">

View File

@ -749,10 +749,6 @@ export class CassandraAPIDataClient extends TableDataClient {
CassandraProxyEndpoints.Prod, CassandraProxyEndpoints.Prod,
]; ];
let canAccessCassandraProxy: boolean = userContext.databaseAccount.properties.publicNetworkAccess === "Enabled"; let canAccessCassandraProxy: boolean = userContext.databaseAccount.properties.publicNetworkAccess === "Enabled";
if (
configContext.CASSANDRA_PROXY_ENDPOINT !== CassandraProxyEndpoints.Development &&
userContext.databaseAccount.properties.ipRules?.length > 0
) {
if ( if (
configContext.CASSANDRA_PROXY_ENDPOINT !== CassandraProxyEndpoints.Development && configContext.CASSANDRA_PROXY_ENDPOINT !== CassandraProxyEndpoints.Development &&
userContext.databaseAccount.properties.ipRules?.length > 0 userContext.databaseAccount.properties.ipRules?.length > 0
@ -767,4 +763,3 @@ export class CassandraAPIDataClient extends TableDataClient {
); );
} }
} }
}

View File

@ -273,28 +273,24 @@ async function configureHostedWithAAD(config: AAD): Promise<Explorer> {
} }
} }
try { try {
if(LocalStorageUtility.hasItem(StorageKey.DataPlaneRbacEnabled)) { if (LocalStorageUtility.hasItem(StorageKey.DataPlaneRbacEnabled)) {
var isDataPlaneRbacSetting = LocalStorageUtility.getEntryString(StorageKey.DataPlaneRbacEnabled); const isDataPlaneRbacSetting = LocalStorageUtility.getEntryString(StorageKey.DataPlaneRbacEnabled);
if (isDataPlaneRbacSetting == Constants.RBACOptions.setAutomaticRBACOption) if (isDataPlaneRbacSetting === Constants.RBACOptions.setAutomaticRBACOption) {
{
if (!account.properties.disableLocalAuth) { if (!account.properties.disableLocalAuth) {
keys = await listKeys(subscriptionId, resourceGroup, account.name); keys = await listKeys(subscriptionId, resourceGroup, account.name);
} } else {
else {
updateUserContext({ updateUserContext({
dataPlaneRbacEnabled: true dataPlaneRbacEnabled: true,
}); });
} }
} } else if (isDataPlaneRbacSetting === Constants.RBACOptions.setTrueRBACOption) {
else if(isDataPlaneRbacSetting == Constants.RBACOptions.setTrueRBACOption) {
updateUserContext({ updateUserContext({
dataPlaneRbacEnabled: true dataPlaneRbacEnabled: true,
}); });
} } else {
else {
keys = await listKeys(subscriptionId, resourceGroup, account.name); keys = await listKeys(subscriptionId, resourceGroup, account.name);
updateUserContext({ updateUserContext({
dataPlaneRbacEnabled: false dataPlaneRbacEnabled: false,
}); });
} }
} }
@ -419,9 +415,8 @@ async function configurePortal(): Promise<Explorer> {
authType: AuthType.AAD, authType: AuthType.AAD,
}); });
let explorer: Explorer; let explorer: Explorer;
return new Promise(async (resolve) => { return new Promise((resolve) => {
// In development mode, try to load the iframe message from session storage. // In development mode, try to load the iframe message from session storage.
// This allows webpack hot reload to function properly in the portal // This allows webpack hot reload to function properly in the portal
if (process.env.NODE_ENV === "development" && !window.location.search.includes("disablePortalInitCache")) { if (process.env.NODE_ENV === "development" && !window.location.search.includes("disablePortalInitCache")) {
@ -435,7 +430,6 @@ async function configurePortal(): Promise<Explorer> {
updateContextsFromPortalMessage(message); updateContextsFromPortalMessage(message);
explorer = new Explorer(); explorer = new Explorer();
// In development mode, save the iframe message from the portal in session storage. // In development mode, save the iframe message from the portal in session storage.
// This allows webpack hot reload to funciton properly // This allows webpack hot reload to funciton properly
if (process.env.NODE_ENV === "development") { if (process.env.NODE_ENV === "development") {
@ -478,35 +472,30 @@ async function configurePortal(): Promise<Explorer> {
setTimeout(() => explorer.openNPSSurveyDialog(), 3000); setTimeout(() => explorer.openNPSSurveyDialog(), 3000);
} }
let keys: DatabaseAccountListKeysResult = {};
const account = userContext.databaseAccount; const account = userContext.databaseAccount;
const subscriptionId = userContext.subscriptionId; const subscriptionId = userContext.subscriptionId;
const resourceGroup = userContext.resourceGroup; const resourceGroup = userContext.resourceGroup;
if(LocalStorageUtility.hasItem(StorageKey.DataPlaneRbacEnabled)) { if (LocalStorageUtility.hasItem(StorageKey.DataPlaneRbacEnabled)) {
var isDataPlaneRbacSetting = LocalStorageUtility.getEntryString(StorageKey.DataPlaneRbacEnabled); const isDataPlaneRbacSetting = LocalStorageUtility.getEntryString(StorageKey.DataPlaneRbacEnabled);
if (isDataPlaneRbacSetting == Constants.RBACOptions.setAutomaticRBACOption) if (isDataPlaneRbacSetting === Constants.RBACOptions.setAutomaticRBACOption) {
{
if (!account.properties.disableLocalAuth) { if (!account.properties.disableLocalAuth) {
keys = await listKeys(subscriptionId, resourceGroup, account.name); await listKeys(subscriptionId, resourceGroup, account.name);
} } else {
else {
updateUserContext({ updateUserContext({
dataPlaneRbacEnabled: true, dataPlaneRbacEnabled: true,
authorizationToken: message.inputs.authorizationToken authorizationToken: message.inputs.authorizationToken,
}); });
} }
} } else if (isDataPlaneRbacSetting === Constants.RBACOptions.setTrueRBACOption) {
else if(isDataPlaneRbacSetting == Constants.RBACOptions.setTrueRBACOption) {
updateUserContext({ updateUserContext({
dataPlaneRbacEnabled: true, dataPlaneRbacEnabled: true,
authorizationToken: message.inputs.authorizationToken authorizationToken: message.inputs.authorizationToken,
}); });
} } else {
else { await listKeys(subscriptionId, resourceGroup, account.name);
keys = await listKeys(subscriptionId, resourceGroup, account.name);
updateUserContext({ updateUserContext({
dataPlaneRbacEnabled: false dataPlaneRbacEnabled: false,
}); });
} }
} }
@ -533,9 +522,7 @@ async function configurePortal(): Promise<Explorer> {
); );
sendReadyMessage(); sendReadyMessage();
}); });
} }
function shouldForwardMessage(message: PortalMessage, messageOrigin: string) { function shouldForwardMessage(message: PortalMessage, messageOrigin: string) {