Only show networking settings warning for Mongo and Cassandra accounts (#1376)

This commit is contained in:
victor-meng 2023-01-18 11:12:10 -08:00 committed by GitHub
parent ab1409efb1
commit 5059917edf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,30 +11,34 @@ const PortalIPs: { [key: string]: string[] } = {
};
export const doNetworkSettingsAllowDataExplorerAccess = (): boolean => {
const accountProperties = userContext.databaseAccount?.properties;
if (userContext.apiType === "Cassandra" || userContext.apiType === "Mongo") {
const accountProperties = userContext.databaseAccount?.properties;
if (!accountProperties) {
return false;
}
// public network access is disabled
if (accountProperties.publicNetworkAccess !== "Enabled") {
return false;
}
const ipRules = accountProperties.ipRules;
// public network access is set to "All networks"
if (ipRules.length === 0) {
return true;
}
const portalIPs = PortalIPs[userContext.portalEnv];
let numberOfMatches = 0;
ipRules.forEach((ipRule) => {
if (portalIPs.indexOf(ipRule.ipAddressOrRange) !== -1) {
numberOfMatches++;
if (!accountProperties) {
return false;
}
});
return numberOfMatches === portalIPs.length;
// public network access is disabled
if (accountProperties.publicNetworkAccess !== "Enabled") {
return false;
}
const ipRules = accountProperties.ipRules;
// public network access is set to "All networks"
if (ipRules.length === 0) {
return true;
}
const portalIPs = PortalIPs[userContext.portalEnv];
let numberOfMatches = 0;
ipRules.forEach((ipRule) => {
if (portalIPs.indexOf(ipRule.ipAddressOrRange) !== -1) {
numberOfMatches++;
}
});
return numberOfMatches === portalIPs.length;
}
return true;
};