This repository has been archived by the owner on Jul 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
EVG-19946: Support Docker on provider settings page #2017
Merged
Merged
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
46ae0f3
EVG-19946: Add Docker to provider settings page
minnakt 32cd128
Merge branch 'main' into EVG-19946
minnakt d7d501d
Merge branch 'main' into EVG-19946
minnakt 07b316c
Change form schema and address feedback
minnakt 9383586
Merge branch 'main' into EVG-19946
minnakt 405ce37
Address comments
minnakt 0a7ea2f
Surface types
minnakt 2f14006
Prevent `undefined` error
minnakt 9c5beb2
Merge branch 'main' into EVG-19946
minnakt 8e32f60
Use a different distro for test
minnakt f2ab0cc
Merge branch 'main' into EVG-19946
minnakt e3ee2db
Update SpruceConfig mock to contain container pools
minnakt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
147 changes: 40 additions & 107 deletions
147
src/pages/distroSettings/tabs/ProviderTab/transformerUtils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,119 +1,52 @@ | ||
import { BuildType } from "./types"; | ||
|
||
type FieldGetter = (providerSettings: Record<string, any>) => { | ||
form: Record<string, any>; | ||
gql: Record<string, any>; | ||
}; | ||
|
||
const getUserData = ((providerSettings) => ({ | ||
form: { | ||
import { BuildType, ProviderFormState } from "./types"; | ||
|
||
interface ProviderSettingsList { | ||
user_data: string; | ||
merge_user_data_parts: boolean; | ||
security_group_ids: string[]; | ||
image_url: string; | ||
build_type: string; | ||
docker_registry_user: string; | ||
docker_registry_pw: string; | ||
} | ||
|
||
export const formProviderSettings = ( | ||
providerSettings: Partial<ProviderSettingsList> | ||
) => ({ | ||
staticProviderSettings: { | ||
userData: providerSettings.user_data ?? "", | ||
}, | ||
gql: { | ||
user_data: providerSettings.userData, | ||
}, | ||
})) satisfies FieldGetter; | ||
|
||
const getMergeUserData = ((providerSettings) => ({ | ||
form: { | ||
mergeUserData: providerSettings.merge_user_data_parts ?? false, | ||
}, | ||
gql: { | ||
merge_user_data_parts: providerSettings.mergeUserData, | ||
}, | ||
})) satisfies FieldGetter; | ||
|
||
const getSecurityGroups = ((providerSettings) => ({ | ||
form: { | ||
securityGroups: providerSettings.security_group_ids ?? [], | ||
}, | ||
gql: { | ||
security_group_ids: providerSettings.securityGroups, | ||
}, | ||
})) satisfies FieldGetter; | ||
|
||
const getImageUrl = ((providerSettings) => ({ | ||
form: { | ||
dockerProviderSettings: { | ||
userData: providerSettings.user_data ?? "", | ||
mergeUserData: providerSettings.merge_user_data_parts ?? false, | ||
securityGroups: providerSettings.security_group_ids ?? [], | ||
imageUrl: providerSettings.image_url ?? "", | ||
}, | ||
gql: { | ||
image_url: providerSettings.imageUrl, | ||
}, | ||
})) satisfies FieldGetter; | ||
|
||
const getBuildType = ((providerSettings) => ({ | ||
form: { | ||
buildType: (providerSettings.build_type ?? "") as BuildType, | ||
}, | ||
gql: { | ||
build_type: providerSettings.buildType, | ||
}, | ||
})) satisfies FieldGetter; | ||
|
||
const getRegistryUsername = ((providerSettings) => ({ | ||
form: { | ||
registryUsername: providerSettings.docker_registry_user ?? "", | ||
registryPassword: providerSettings.docker_registry_pw ?? "", | ||
}, | ||
gql: { | ||
docker_registry_user: providerSettings.registryUsername, | ||
}, | ||
})) satisfies FieldGetter; | ||
}); | ||
|
||
const getRegistryPassword = ((providerSettings) => ({ | ||
form: { | ||
registryPassword: providerSettings.docker_registry_pw ?? "", | ||
type ProviderSettings = ProviderFormState["staticProviderSettings"] & | ||
ProviderFormState["dockerProviderSettings"]; | ||
|
||
export const gqlProviderSettings = ( | ||
providerSettings: Partial<ProviderSettings> | ||
) => ({ | ||
staticProviderSettings: { | ||
user_data: providerSettings.userData, | ||
merge_user_data_parts: providerSettings.mergeUserData, | ||
security_group_ids: providerSettings.securityGroups, | ||
}, | ||
gql: { | ||
dockerProviderSettings: { | ||
user_data: providerSettings.userData, | ||
merge_user_data_parts: providerSettings.mergeUserData, | ||
security_group_ids: providerSettings.securityGroups, | ||
image_url: providerSettings.imageUrl, | ||
build_type: providerSettings.buildType, | ||
docker_registry_user: providerSettings.registryUsername, | ||
docker_registry_pw: providerSettings.registryPassword, | ||
}, | ||
})) satisfies FieldGetter; | ||
|
||
export const staticProviderSettings = ((providerSettings = {}) => { | ||
const userData = getUserData(providerSettings); | ||
const mergeUserData = getMergeUserData(providerSettings); | ||
const securityGroups = getSecurityGroups(providerSettings); | ||
|
||
return { | ||
form: { | ||
...userData.form, | ||
...mergeUserData.form, | ||
...securityGroups.form, | ||
}, | ||
gql: { | ||
...userData.gql, | ||
...mergeUserData.gql, | ||
...securityGroups.gql, | ||
}, | ||
}; | ||
}) satisfies FieldGetter; | ||
|
||
export const dockerProviderSettings = ((providerSettings = {}) => { | ||
const imageUrl = getImageUrl(providerSettings); | ||
const buildType = getBuildType(providerSettings); | ||
const registryUser = getRegistryUsername(providerSettings); | ||
const registryPassword = getRegistryPassword(providerSettings); | ||
const userData = getUserData(providerSettings); | ||
const mergeUserData = getMergeUserData(providerSettings); | ||
const securityGroups = getSecurityGroups(providerSettings); | ||
|
||
return { | ||
form: { | ||
...imageUrl.form, | ||
...buildType.form, | ||
...registryUser.form, | ||
...registryPassword.form, | ||
...userData.form, | ||
...mergeUserData.form, | ||
...securityGroups.form, | ||
}, | ||
gql: { | ||
...imageUrl.gql, | ||
...buildType.gql, | ||
...registryUser.gql, | ||
...registryPassword.gql, | ||
...userData.gql, | ||
...mergeUserData.gql, | ||
...securityGroups.gql, | ||
}, | ||
}; | ||
}) satisfies FieldGetter; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This structure makes a lot more sense 😅 gorgeous!