Skip to content

Commit

Permalink
remove ssh keys from distro host settings
Browse files Browse the repository at this point in the history
  • Loading branch information
ybrill committed Apr 8, 2024
1 parent f13f96d commit ac3f0a7
Show file tree
Hide file tree
Showing 11 changed files with 11 additions and 62 deletions.
11 changes: 0 additions & 11 deletions apps/spruce/src/gql/generated/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,6 @@ export type Distro = {
providerSettingsList: Array<Scalars["Map"]["output"]>;
setup: Scalars["String"]["output"];
setupAsSudo: Scalars["Boolean"]["output"];
sshKey: Scalars["String"]["output"];
sshOptions: Array<Scalars["String"]["output"]>;
user: Scalars["String"]["output"];
userSpawnAllowed: Scalars["Boolean"]["output"];
Expand Down Expand Up @@ -453,7 +452,6 @@ export type DistroInput = {
providerSettingsList: Array<Scalars["Map"]["input"]>;
setup: Scalars["String"]["input"];
setupAsSudo: Scalars["Boolean"]["input"];
sshKey: Scalars["String"]["input"];
sshOptions: Array<Scalars["String"]["input"]>;
user: Scalars["String"]["input"];
userSpawnAllowed: Scalars["Boolean"]["input"];
Expand Down Expand Up @@ -2310,12 +2308,6 @@ export enum RoundingRule {
Up = "UP",
}

export type SshKey = {
__typename?: "SSHKey";
location: Scalars["String"]["output"];
name: Scalars["String"]["output"];
};

/** SaveDistroInput is the input to the saveDistro mutation. */
export type SaveDistroInput = {
distro: DistroInput;
Expand Down Expand Up @@ -2467,7 +2459,6 @@ export type SpruceConfig = {
containerPools?: Maybe<ContainerPoolsConfig>;
githubOrgs: Array<Scalars["String"]["output"]>;
jira?: Maybe<JiraConfig>;
keys: Array<SshKey>;
providers?: Maybe<CloudProviderConfig>;
secretFields: Array<Scalars["String"]["output"]>;
slack?: Maybe<SlackConfig>;
Expand Down Expand Up @@ -5832,7 +5823,6 @@ export type DistroQuery = {
providerSettingsList: Array<any>;
setup: string;
setupAsSudo: boolean;
sshKey: string;
sshOptions: Array<string>;
user: string;
userSpawnAllowed: boolean;
Expand Down Expand Up @@ -8266,7 +8256,6 @@ export type SpruceConfigQuery = {
email?: string | null;
host?: string | null;
} | null;
keys: Array<{ __typename?: "SSHKey"; location: string; name: string }>;
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
8 changes: 2 additions & 6 deletions apps/spruce/src/pages/distroSettings/tabs/HostTab/HostTab.tsx
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
23 changes: 3 additions & 20 deletions apps/spruce/src/pages/distroSettings/tabs/HostTab/schemaFields.tsx
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
1 change: 0 additions & 1 deletion apps/spruce/src/pages/distroSettings/tabs/HostTab/types.ts
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

0 comments on commit ac3f0a7

Please sign in to comment.