From 4b75e86b74148e32a53db39f35b10767a94c1b02 Mon Sep 17 00:00:00 2001
From: jawelton74 <103591340+jawelton74@users.noreply.github.com>
Date: Thu, 12 Dec 2024 15:44:28 -0800
Subject: [PATCH] Remove Network Warning banner from Data Explorer. (#2019)
---
src/Explorer/Tabs/Tabs.tsx | 29 +--------
src/Utils/NetworkUtility.test.ts | 104 -------------------------------
src/Utils/NetworkUtility.ts | 99 -----------------------------
src/hooks/useKnockoutExplorer.ts | 3 -
src/hooks/useTabs.ts | 4 --
5 files changed, 2 insertions(+), 237 deletions(-)
delete mode 100644 src/Utils/NetworkUtility.test.ts
delete mode 100644 src/Utils/NetworkUtility.ts
diff --git a/src/Explorer/Tabs/Tabs.tsx b/src/Explorer/Tabs/Tabs.tsx
index 3ee50992c..aa06858dc 100644
--- a/src/Explorer/Tabs/Tabs.tsx
+++ b/src/Explorer/Tabs/Tabs.tsx
@@ -1,9 +1,7 @@
-import { IMessageBarStyles, MessageBar, MessageBarButton, MessageBarType } from "@fluentui/react";
+import { IMessageBarStyles, MessageBar, MessageBarType } from "@fluentui/react";
import { CassandraProxyEndpoints, MongoProxyEndpoints } from "Common/Constants";
-import { sendMessage } from "Common/MessageHandler";
import { configContext } from "ConfigContext";
import { IpRule } from "Contracts/DataModels";
-import { MessageTypes } from "Contracts/ExplorerContracts";
import { CollectionTabKind } from "Contracts/ViewModels";
import Explorer from "Explorer/Explorer";
import { useCommandBar } from "Explorer/Menus/CommandBar/CommandBarComponentAdapter";
@@ -35,7 +33,7 @@ interface TabsProps {
}
export const Tabs = ({ explorer }: TabsProps): JSX.Element => {
- const { openedTabs, openedReactTabs, activeTab, activeReactTab, networkSettingsWarning } = useTabs();
+ const { openedTabs, openedReactTabs, activeTab, activeReactTab } = useTabs();
const [
showMongoAndCassandraProxiesNetworkSettingsWarningState,
setShowMongoAndCassandraProxiesNetworkSettingsWarningState,
@@ -60,29 +58,6 @@ export const Tabs = ({ explorer }: TabsProps): JSX.Element => {
return (
- {networkSettingsWarning && (
-
- sendMessage({
- type:
- userContext.apiType === "VCoreMongo"
- ? MessageTypes.OpenVCoreMongoNetworkingBlade
- : MessageTypes.OpenPostgresNetworkingBlade,
- })
- }
- >
- Change network settings
-
- }
- messageBarIconProps={{ iconName: "WarningSolid", className: "messageBarWarningIcon" }}
- >
- {networkSettingsWarning}
-
- )}
{showMongoAndCassandraProxiesNetworkSettingsWarningState && (
{
- describe("getNetworkSettingsWarningMessage", () => {
- const publicAccessMessagePart = "Please enable public access to proceed";
- const accessMessagePart = "Please allow access from Azure Portal to proceed";
- let warningMessageResult: string;
- const warningMessageFunc = (msg: string) => (warningMessageResult = msg);
-
- beforeEach(() => {
- warningMessageResult = undefined;
- });
-
- afterEach(() => {
- resetConfigContext();
- });
-
- it("should return no message when publicNetworkAccess is enabled", async () => {
- updateUserContext({
- databaseAccount: {
- properties: {
- publicNetworkAccess: "Enabled",
- },
- } as DatabaseAccount,
- });
-
- await getNetworkSettingsWarningMessage(warningMessageFunc);
- expect(warningMessageResult).toBeUndefined();
- });
-
- it("should return publicAccessMessage when publicNetworkAccess is disabled", async () => {
- updateUserContext({
- databaseAccount: {
- properties: {
- publicNetworkAccess: "Disabled",
- },
- } as DatabaseAccount,
- });
-
- await getNetworkSettingsWarningMessage(warningMessageFunc);
- expect(warningMessageResult).toContain(publicAccessMessagePart);
- });
-
- it(`should return no message when the appropriate ip rules are added to mongo/cassandra account per endpoint`, async () => {
- const portalBackendOutboundIPs: string[] = [
- ...PortalBackendOutboundIPs[PortalBackendEndpoints.Mpac],
- ...PortalBackendOutboundIPs[PortalBackendEndpoints.Prod],
- ...MongoProxyOutboundIPs[MongoProxyEndpoints.Mpac],
- ...MongoProxyOutboundIPs[MongoProxyEndpoints.Prod],
- ];
- updateUserContext({
- databaseAccount: {
- kind: "MongoDB",
- properties: {
- ipRules: portalBackendOutboundIPs.map((ip: string) => ({ ipAddressOrRange: ip }) as IpRule),
- publicNetworkAccess: "Enabled",
- },
- } as DatabaseAccount,
- });
-
- updateConfigContext({
- PORTAL_BACKEND_ENDPOINT: PortalBackendEndpoints.Mpac,
- MONGO_PROXY_ENDPOINT: MongoProxyEndpoints.Mpac,
- });
-
- let asyncWarningMessageResult: string;
- const asyncWarningMessageFunc = (msg: string) => (asyncWarningMessageResult = msg);
-
- await getNetworkSettingsWarningMessage(asyncWarningMessageFunc);
- expect(asyncWarningMessageResult).toBeUndefined();
- });
-
- it("should return accessMessage when incorrent ip rule is added to mongo/cassandra account per endpoint", async () => {
- updateUserContext({
- databaseAccount: {
- kind: "MongoDB",
- properties: {
- ipRules: [{ ipAddressOrRange: "1.1.1.1" }],
- publicNetworkAccess: "Enabled",
- },
- } as DatabaseAccount,
- });
-
- updateConfigContext({
- PORTAL_BACKEND_ENDPOINT: PortalBackendEndpoints.Mpac,
- MONGO_PROXY_ENDPOINT: MongoProxyEndpoints.Mpac,
- });
-
- let asyncWarningMessageResult: string;
- const asyncWarningMessageFunc = (msg: string) => (asyncWarningMessageResult = msg);
-
- await getNetworkSettingsWarningMessage(asyncWarningMessageFunc);
- expect(asyncWarningMessageResult).toContain(accessMessagePart);
- });
-
- // Postgres and vcore mongo account checks basically pass through to CheckFirewallRules so those
- // tests are omitted here and included in CheckFirewallRules.test.ts
- });
-});
diff --git a/src/Utils/NetworkUtility.ts b/src/Utils/NetworkUtility.ts
deleted file mode 100644
index 8c3b02e20..000000000
--- a/src/Utils/NetworkUtility.ts
+++ /dev/null
@@ -1,99 +0,0 @@
-import { CassandraProxyEndpoints, MongoProxyEndpoints, PortalBackendEndpoints } from "Common/Constants";
-import { configContext } from "ConfigContext";
-import { checkFirewallRules } from "Explorer/Tabs/Shared/CheckFirewallRules";
-import { userContext } from "UserContext";
-import { CassandraProxyOutboundIPs, MongoProxyOutboundIPs, PortalBackendOutboundIPs } from "Utils/EndpointUtils";
-
-export const getNetworkSettingsWarningMessage = async (
- setStateFunc: (warningMessage: string) => void,
-): Promise => {
- const accountProperties = userContext.databaseAccount?.properties;
- const accessMessage =
- "The Network settings for this account are preventing access from Data Explorer. Please allow access from Azure Portal to proceed.";
- const publicAccessMessage =
- "The Network settings for this account are preventing access from Data Explorer. Please enable public access to proceed.";
-
- if (userContext.apiType === "Postgres") {
- checkFirewallRules(
- "2022-11-08",
- (rule) => rule.properties.startIpAddress === "0.0.0.0" && rule.properties.endIpAddress === "255.255.255.255",
- undefined,
- setStateFunc,
- accessMessage,
- );
- return;
- } else if (userContext.apiType === "VCoreMongo") {
- checkFirewallRules(
- "2023-03-01-preview",
- (rule) =>
- rule.name.startsWith("AllowAllAzureServicesAndResourcesWithinAzureIps") ||
- (rule.properties.startIpAddress === "0.0.0.0" && rule.properties.endIpAddress === "255.255.255.255"),
- undefined,
- setStateFunc,
- accessMessage,
- );
- return;
- } else if (accountProperties) {
- // public network access is disabled
- if (
- accountProperties.publicNetworkAccess !== "Enabled" &&
- accountProperties.publicNetworkAccess !== "SecuredByPerimeter"
- ) {
- setStateFunc(publicAccessMessage);
- return;
- }
-
- const ipRules = accountProperties.ipRules;
- // public network access is NOT set to "All networks"
- if (ipRules?.length > 0) {
- const isProdOrMpacPortalBackendEndpoint: boolean = [
- PortalBackendEndpoints.Mpac,
- PortalBackendEndpoints.Prod,
- ].includes(configContext.PORTAL_BACKEND_ENDPOINT);
- const portalBackendOutboundIPs: string[] = isProdOrMpacPortalBackendEndpoint
- ? [
- ...PortalBackendOutboundIPs[PortalBackendEndpoints.Mpac],
- ...PortalBackendOutboundIPs[PortalBackendEndpoints.Prod],
- ]
- : PortalBackendOutboundIPs[configContext.PORTAL_BACKEND_ENDPOINT];
- let portalIPs: string[] = [...portalBackendOutboundIPs];
-
- if (userContext.apiType === "Mongo") {
- const isProdOrMpacMongoProxyEndpoint: boolean = [MongoProxyEndpoints.Mpac, MongoProxyEndpoints.Prod].includes(
- configContext.MONGO_PROXY_ENDPOINT,
- );
-
- const mongoProxyOutboundIPs: string[] = isProdOrMpacMongoProxyEndpoint
- ? [...MongoProxyOutboundIPs[MongoProxyEndpoints.Mpac], ...MongoProxyOutboundIPs[MongoProxyEndpoints.Prod]]
- : MongoProxyOutboundIPs[configContext.MONGO_PROXY_ENDPOINT];
-
- portalIPs = [...portalIPs, ...mongoProxyOutboundIPs];
- } else if (userContext.apiType === "Cassandra") {
- const isProdOrMpacCassandraProxyEndpoint: boolean = [
- CassandraProxyEndpoints.Mpac,
- CassandraProxyEndpoints.Prod,
- ].includes(configContext.CASSANDRA_PROXY_ENDPOINT);
-
- const cassandraProxyOutboundIPs: string[] = isProdOrMpacCassandraProxyEndpoint
- ? [
- ...CassandraProxyOutboundIPs[CassandraProxyEndpoints.Mpac],
- ...CassandraProxyOutboundIPs[CassandraProxyEndpoints.Prod],
- ]
- : CassandraProxyOutboundIPs[configContext.CASSANDRA_PROXY_ENDPOINT];
-
- portalIPs = [...portalIPs, ...cassandraProxyOutboundIPs];
- }
-
- let numberOfMatches = 0;
- ipRules.forEach((ipRule) => {
- if (portalIPs.indexOf(ipRule.ipAddressOrRange) !== -1) {
- numberOfMatches++;
- }
- });
-
- if (numberOfMatches !== portalIPs.length) {
- setStateFunc(accessMessage);
- }
- }
- }
-};
diff --git a/src/hooks/useKnockoutExplorer.ts b/src/hooks/useKnockoutExplorer.ts
index 605a70e49..0656c8a9b 100644
--- a/src/hooks/useKnockoutExplorer.ts
+++ b/src/hooks/useKnockoutExplorer.ts
@@ -14,7 +14,6 @@ import {
} from "Shared/AppStatePersistenceUtility";
import { LocalStorageUtility, StorageKey } from "Shared/StorageUtility";
import { useNewPortalBackendEndpoint } from "Utils/EndpointUtils";
-import { getNetworkSettingsWarningMessage } from "Utils/NetworkUtility";
import { logConsoleError } from "Utils/NotificationConsoleUtils";
import { useQueryCopilot } from "hooks/useQueryCopilot";
import { ReactTabKind, useTabs } from "hooks/useTabs";
@@ -742,8 +741,6 @@ function updateContextsFromPortalMessage(inputs: DataExplorerInputsFrame) {
}
}
- getNetworkSettingsWarningMessage(useTabs.getState().setNetworkSettingsWarning);
-
if (inputs.features) {
Object.assign(userContext.features, extractFeatures(new URLSearchParams(inputs.features)));
}
diff --git a/src/hooks/useTabs.ts b/src/hooks/useTabs.ts
index 16835aeb4..f29f34f72 100644
--- a/src/hooks/useTabs.ts
+++ b/src/hooks/useTabs.ts
@@ -18,7 +18,6 @@ export interface TabsState {
openedReactTabs: ReactTabKind[];
activeTab: TabsBase | undefined;
activeReactTab: ReactTabKind | undefined;
- networkSettingsWarning: string;
queryCopilotTabInitialInput: string;
isTabExecuting: boolean;
isQueryErrorThrown: boolean;
@@ -33,7 +32,6 @@ export interface TabsState {
closeAllNotebookTabs: (hardClose: boolean) => void;
openAndActivateReactTab: (tabKind: ReactTabKind) => void;
closeReactTab: (tabKind: ReactTabKind) => void;
- setNetworkSettingsWarning: (warningMessage: string) => void;
setQueryCopilotTabInitialInput: (input: string) => void;
setIsTabExecuting: (state: boolean) => void;
setIsQueryErrorThrown: (state: boolean) => void;
@@ -69,7 +67,6 @@ export const useTabs: UseStore = create((set, get) => ({
openedReactTabs: !isPlatformFabric ? [ReactTabKind.Home] : [],
activeTab: undefined,
activeReactTab: !isPlatformFabric ? ReactTabKind.Home : undefined,
- networkSettingsWarning: "",
queryCopilotTabInitialInput: "",
isTabExecuting: false,
isQueryErrorThrown: false,
@@ -190,7 +187,6 @@ export const useTabs: UseStore = create((set, get) => ({
set({ openedReactTabs: updatedOpenedReactTabs });
},
- setNetworkSettingsWarning: (warningMessage: string) => set({ networkSettingsWarning: warningMessage }),
setQueryCopilotTabInitialInput: (input: string) => set({ queryCopilotTabInitialInput: input }),
setIsTabExecuting: (state: boolean) => {
set({ isTabExecuting: state });