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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
48 additions
and
115 deletions.
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