From 5331fe391bfc5a1981eb679791489b0363846aef Mon Sep 17 00:00:00 2001 From: Jonathan Brill Date: Wed, 10 Apr 2024 18:26:04 -0400 Subject: [PATCH] DEVPROD-4798 remove ssh keys from distro host settings (#41) --- apps/spruce/src/gql/generated/types.ts | 6 ----- apps/spruce/src/gql/mocks/getSpruceConfig.ts | 6 ----- apps/spruce/src/gql/queries/distro.graphql | 1 - .../src/gql/queries/spruce-config.graphql | 4 ---- .../distroSettings/tabs/HostTab/HostTab.tsx | 8 ++----- .../tabs/HostTab/getFormSchema.tsx | 14 +++++------ .../tabs/HostTab/schemaFields.tsx | 23 +++---------------- .../tabs/HostTab/transformers.test.ts | 1 - .../tabs/HostTab/transformers.ts | 3 --- .../distroSettings/tabs/HostTab/types.ts | 1 - .../src/pages/distroSettings/tabs/testData.ts | 1 - 11 files changed, 11 insertions(+), 57 deletions(-) diff --git a/apps/spruce/src/gql/generated/types.ts b/apps/spruce/src/gql/generated/types.ts index 9bc693a4c..b8141bdf0 100644 --- a/apps/spruce/src/gql/generated/types.ts +++ b/apps/spruce/src/gql/generated/types.ts @@ -5829,7 +5829,6 @@ export type DistroQuery = { providerSettingsList: Array; setup: string; setupAsSudo: boolean; - sshKey: string; sshOptions: Array; user: string; userSpawnAllowed: boolean; @@ -8263,11 +8262,6 @@ export type SpruceConfigQuery = { email?: string | null; host?: string | null; } | null; - keys?: Array<{ - __typename?: "SSHKey"; - location: string; - name: string; - }> | null; providers?: { __typename?: "CloudProviderConfig"; aws?: { diff --git a/apps/spruce/src/gql/mocks/getSpruceConfig.ts b/apps/spruce/src/gql/mocks/getSpruceConfig.ts index a30e9e324..ccc03235e 100644 --- a/apps/spruce/src/gql/mocks/getSpruceConfig.ts +++ b/apps/spruce/src/gql/mocks/getSpruceConfig.ts @@ -34,12 +34,6 @@ export const getSpruceConfigMock: ApolloMock< }, ], }, - keys: [ - { - name: "fake_key", - location: "/path/to/key", - }, - ], jira: { host: "jira.mongodb.org", __typename: "JiraConfig", diff --git a/apps/spruce/src/gql/queries/distro.graphql b/apps/spruce/src/gql/queries/distro.graphql index d3e3eed29..c21708bd7 100644 --- a/apps/spruce/src/gql/queries/distro.graphql +++ b/apps/spruce/src/gql/queries/distro.graphql @@ -79,7 +79,6 @@ query Distro($distroId: String!) { providerSettingsList setup setupAsSudo - sshKey sshOptions user userSpawnAllowed diff --git a/apps/spruce/src/gql/queries/spruce-config.graphql b/apps/spruce/src/gql/queries/spruce-config.graphql index a5f57b752..bb92028d7 100644 --- a/apps/spruce/src/gql/queries/spruce-config.graphql +++ b/apps/spruce/src/gql/queries/spruce-config.graphql @@ -14,10 +14,6 @@ query SpruceConfig { email host } - keys { - location - name - } providers { aws { maxVolumeSizePerUser diff --git a/apps/spruce/src/pages/distroSettings/tabs/HostTab/HostTab.tsx b/apps/spruce/src/pages/distroSettings/tabs/HostTab/HostTab.tsx index 6dbef2899..cfb0931d9 100644 --- a/apps/spruce/src/pages/distroSettings/tabs/HostTab/HostTab.tsx +++ b/apps/spruce/src/pages/distroSettings/tabs/HostTab/HostTab.tsx @@ -2,16 +2,12 @@ import { useMemo } from "react"; import { ValidateProps } from "components/SpruceForm"; import { DistroSettingsTabRoutes } from "constants/routes"; import { BootstrapMethod, CommunicationMethod } from "gql/generated/types"; -import { useSpruceConfig } from "hooks"; import { useDistroSettingsContext } from "pages/distroSettings/Context"; import { BaseTab } from "../BaseTab"; import { getFormSchema } from "./getFormSchema"; import { HostFormState, TabProps } from "./types"; export const HostTab: React.FC = ({ distroData, provider }) => { - const spruceConfig = useSpruceConfig(); - const sshKeys = spruceConfig?.keys; - const { getTab } = useDistroSettingsContext(); // @ts-expect-error - see TabState for details. const { formData }: { formData: HostFormState } = getTab( @@ -20,8 +16,8 @@ export const HostTab: React.FC = ({ distroData, provider }) => { const architecture = formData?.setup?.arch; const formSchema = useMemo( - () => getFormSchema({ architecture, provider, sshKeys }), - [architecture, provider, sshKeys], + () => getFormSchema({ architecture, provider }), + [architecture, provider], ); return ( diff --git a/apps/spruce/src/pages/distroSettings/tabs/HostTab/getFormSchema.tsx b/apps/spruce/src/pages/distroSettings/tabs/HostTab/getFormSchema.tsx index c0c1623c0..2d2c44e74 100644 --- a/apps/spruce/src/pages/distroSettings/tabs/HostTab/getFormSchema.tsx +++ b/apps/spruce/src/pages/distroSettings/tabs/HostTab/getFormSchema.tsx @@ -1,5 +1,5 @@ import { GetFormSchema } from "components/SpruceForm"; -import { Arch, BootstrapMethod, Provider, SshKey } from "gql/generated/types"; +import { Arch, BootstrapMethod, Provider } from "gql/generated/types"; import { nonWindowsArchitectures, windowsArchitectures } from "./constants"; import { allocation as allocationProperties, @@ -15,13 +15,11 @@ import { type FormSchemaParams = { architecture: Arch; provider: Provider; - sshKeys: SshKey[]; }; export const getFormSchema = ({ architecture, provider, - sshKeys, }: FormSchemaParams): ReturnType => { const hasStaticProvider = provider === Provider.Static; const hasDockerProvider = provider === Provider.Docker; @@ -102,7 +100,7 @@ export const getFormSchema = ({ bootstrapMethod: { enum: [BootstrapMethod.LegacySsh] }, }, }, - sshConfig: sshConfig(sshKeys), + sshConfig, allocation, }, }, @@ -116,7 +114,7 @@ export const getFormSchema = ({ }, }, bootstrapSettings, - sshConfig: sshConfig(sshKeys), + sshConfig, allocation, }, }, @@ -142,11 +140,11 @@ const bootstrapSettings = { properties: bootstrapProperties.schema, }; -const sshConfig = (sshKeys: SshKey[]) => ({ +const sshConfig = { type: "object" as "object", title: "SSH Configuration", - properties: sshConfigProperties.schema(sshKeys), -}); + properties: sshConfigProperties.schema, +}; const allocation = { type: "object" as "object", diff --git a/apps/spruce/src/pages/distroSettings/tabs/HostTab/schemaFields.tsx b/apps/spruce/src/pages/distroSettings/tabs/HostTab/schemaFields.tsx index 08535c78f..e2b4d71a8 100644 --- a/apps/spruce/src/pages/distroSettings/tabs/HostTab/schemaFields.tsx +++ b/apps/spruce/src/pages/distroSettings/tabs/HostTab/schemaFields.tsx @@ -7,7 +7,7 @@ import { FieldRow, } from "components/SpruceForm/FieldTemplates"; import { size } from "constants/tokens"; -import { Arch, SshKey } from "gql/generated/types"; +import { Arch } from "gql/generated/types"; import { architectureToCopy, bootstrapMethodToCopy, @@ -408,21 +408,6 @@ const user = { }, }; -const sshKey = { - schema: (sshKeys: SshKey[]) => ({ - type: "string" as "string", - title: "SSH Key", - oneOf: sshKeys.map(({ location, name }) => ({ - type: "string" as "string", - title: `${name} – ${location}`, - enum: [name], - })), - }), - uiSchema: { - "ui:allowDeselect": false, - }, -}; - const authorizedKeysFile = { schema: { type: "string" as "string", @@ -665,16 +650,14 @@ export const allocation = { }; export const sshConfig = { - schema: (sshKeys: SshKey[]) => ({ + schema: { user: user.schema, - sshKey: sshKey.schema(sshKeys), authorizedKeysFile: authorizedKeysFile.schema, sshOptions: sshOptions.schema, - }), + }, uiSchema: (hasStaticProvider: boolean) => ({ "ui:ObjectFieldTemplate": CardFieldTemplate, user: user.uiSchema, - sshKey: sshKey.uiSchema, authorizedKeysFile: authorizedKeysFile.uiSchema(hasStaticProvider), sshOptions: sshOptions.uiSchema, }), diff --git a/apps/spruce/src/pages/distroSettings/tabs/HostTab/transformers.test.ts b/apps/spruce/src/pages/distroSettings/tabs/HostTab/transformers.test.ts index d043e2061..5797716f4 100644 --- a/apps/spruce/src/pages/distroSettings/tabs/HostTab/transformers.test.ts +++ b/apps/spruce/src/pages/distroSettings/tabs/HostTab/transformers.test.ts @@ -68,7 +68,6 @@ const form: HostFormState = { }, sshConfig: { user: "admin", - sshKey: "fakeSshKey", authorizedKeysFile: "", sshOptions: ["BatchMode=yes", "ConnectTimeout=10"], }, diff --git a/apps/spruce/src/pages/distroSettings/tabs/HostTab/transformers.ts b/apps/spruce/src/pages/distroSettings/tabs/HostTab/transformers.ts index d7a8352b0..c4da63b1c 100644 --- a/apps/spruce/src/pages/distroSettings/tabs/HostTab/transformers.ts +++ b/apps/spruce/src/pages/distroSettings/tabs/HostTab/transformers.ts @@ -29,7 +29,6 @@ export const gqlToForm = ((data) => { mountpoints, setup, setupAsSudo, - sshKey, sshOptions, user, userSpawnAllowed, @@ -64,7 +63,6 @@ export const gqlToForm = ((data) => { }, sshConfig: { user, - sshKey, authorizedKeysFile, sshOptions, }, @@ -104,7 +102,6 @@ export const formToGql = (( setupAsSudo: setup.setupAsSudo, setup: setup.setupScript, mountpoints: setup.mountpoints, - sshKey: sshConfig.sshKey, sshOptions: sshConfig.sshOptions, user: sshConfig.user, userSpawnAllowed: setup.userSpawnAllowed, diff --git a/apps/spruce/src/pages/distroSettings/tabs/HostTab/types.ts b/apps/spruce/src/pages/distroSettings/tabs/HostTab/types.ts index c50ee8da7..ca3176ba2 100644 --- a/apps/spruce/src/pages/distroSettings/tabs/HostTab/types.ts +++ b/apps/spruce/src/pages/distroSettings/tabs/HostTab/types.ts @@ -49,7 +49,6 @@ export interface HostFormState { }; sshConfig: { user: string; - sshKey: string; authorizedKeysFile: string; sshOptions: string[]; }; diff --git a/apps/spruce/src/pages/distroSettings/tabs/testData.ts b/apps/spruce/src/pages/distroSettings/tabs/testData.ts index 1f83a6abf..e2b342f6d 100644 --- a/apps/spruce/src/pages/distroSettings/tabs/testData.ts +++ b/apps/spruce/src/pages/distroSettings/tabs/testData.ts @@ -111,7 +111,6 @@ const distroData: DistroQuery["distro"] = { ], setup: "ls -alF", setupAsSudo: true, - sshKey: "fakeSshKey", sshOptions: ["BatchMode=yes", "ConnectTimeout=10"], user: "admin", userSpawnAllowed: false,