Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEVPROD-4798 remove ssh keys from distro host settings #41

Merged
merged 4 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions apps/spruce/src/gql/generated/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5829,7 +5829,6 @@ export type DistroQuery = {
providerSettingsList: Array<any>;
setup: string;
setupAsSudo: boolean;
sshKey: string;
sshOptions: Array<string>;
user: string;
userSpawnAllowed: boolean;
Expand Down Expand Up @@ -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?: {
Expand Down
6 changes: 0 additions & 6 deletions apps/spruce/src/gql/mocks/getSpruceConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@ export const getSpruceConfigMock: ApolloMock<
},
],
},
keys: [
{
name: "fake_key",
location: "/path/to/key",
},
],
jira: {
host: "jira.mongodb.org",
__typename: "JiraConfig",
Expand Down
1 change: 0 additions & 1 deletion apps/spruce/src/gql/queries/distro.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ query Distro($distroId: String!) {
providerSettingsList
setup
setupAsSudo
sshKey
sshOptions
user
userSpawnAllowed
Expand Down
4 changes: 0 additions & 4 deletions apps/spruce/src/gql/queries/spruce-config.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ query SpruceConfig {
email
host
}
keys {
location
name
}
providers {
aws {
maxVolumeSizePerUser
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TabProps> = ({ distroData, provider }) => {
const spruceConfig = useSpruceConfig();
const sshKeys = spruceConfig?.keys;

const { getTab } = useDistroSettingsContext();
// @ts-expect-error - see TabState for details.
const { formData }: { formData: HostFormState } = getTab(
Expand All @@ -20,8 +16,8 @@ export const HostTab: React.FC<TabProps> = ({ distroData, provider }) => {
const architecture = formData?.setup?.arch;

const formSchema = useMemo(
() => getFormSchema({ architecture, provider, sshKeys }),
[architecture, provider, sshKeys],
() => getFormSchema({ architecture, provider }),
[architecture, provider],
);

return (
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -15,13 +15,11 @@ import {
type FormSchemaParams = {
architecture: Arch;
provider: Provider;
sshKeys: SshKey[];
};

export const getFormSchema = ({
architecture,
provider,
sshKeys,
}: FormSchemaParams): ReturnType<GetFormSchema> => {
const hasStaticProvider = provider === Provider.Static;
const hasDockerProvider = provider === Provider.Docker;
Expand Down Expand Up @@ -102,7 +100,7 @@ export const getFormSchema = ({
bootstrapMethod: { enum: [BootstrapMethod.LegacySsh] },
},
},
sshConfig: sshConfig(sshKeys),
sshConfig,
allocation,
},
},
Expand All @@ -116,7 +114,7 @@ export const getFormSchema = ({
},
},
bootstrapSettings,
sshConfig: sshConfig(sshKeys),
sshConfig,
allocation,
},
},
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ const form: HostFormState = {
},
sshConfig: {
user: "admin",
sshKey: "fakeSshKey",
authorizedKeysFile: "",
sshOptions: ["BatchMode=yes", "ConnectTimeout=10"],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export const gqlToForm = ((data) => {
mountpoints,
setup,
setupAsSudo,
sshKey,
sshOptions,
user,
userSpawnAllowed,
Expand Down Expand Up @@ -64,7 +63,6 @@ export const gqlToForm = ((data) => {
},
sshConfig: {
user,
sshKey,
authorizedKeysFile,
sshOptions,
},
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export interface HostFormState {
};
sshConfig: {
user: string;
sshKey: string;
authorizedKeysFile: string;
sshOptions: string[];
};
Expand Down
1 change: 0 additions & 1 deletion apps/spruce/src/pages/distroSettings/tabs/testData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ const distroData: DistroQuery["distro"] = {
],
setup: "ls -alF",
setupAsSudo: true,
sshKey: "fakeSshKey",
sshOptions: ["BatchMode=yes", "ConnectTimeout=10"],
user: "admin",
userSpawnAllowed: false,
Expand Down
Loading