From 301d5dffd84d80d1071d0e98f6ea3c73f703ac9e Mon Sep 17 00:00:00 2001 From: Mate Vago Date: Wed, 25 Sep 2024 10:31:47 +0200 Subject: [PATCH] feat: add private unchecked registry (#1001) Co-authored-by: Levente Orban --- .../registries/edit-registry-card.tsx | 4 +- .../unchecked-registry-field.tsx | 79 ++++++++++++++++--- web/crux-ui/src/models/registry.ts | 9 ++- web/crux-ui/src/validations/registry.ts | 3 +- web/crux/src/app/registry/registry.dto.ts | 10 +++ web/crux/src/app/registry/registry.mapper.ts | 9 ++- 6 files changed, 96 insertions(+), 18 deletions(-) diff --git a/web/crux-ui/src/components/registries/edit-registry-card.tsx b/web/crux-ui/src/components/registries/edit-registry-card.tsx index 23c14dcf24..13bd488564 100644 --- a/web/crux-ui/src/components/registries/edit-registry-card.tsx +++ b/web/crux-ui/src/components/registries/edit-registry-card.tsx @@ -19,12 +19,12 @@ import { EditableGoogleRegistryDetails, EditableHubRegistryDetails, EditableRegistry, + EditableUncheckedRegistryDetails, EditableV2RegistryDetails, PUBLIC_REGISTRY_TYPES, REGISTRY_TYPE_VALUES, RegistryDetails, RegistryType, - UncheckedRegistryDetails, UpdateRegistryDto, editableRegistryToDto, } from '@app/models' @@ -216,7 +216,7 @@ const EditRegistryCard = (props: EditRegistryCardProps) => { ) : registryType === 'google' ? ( } /> ) : registryType === 'unchecked' ? ( - } /> + } /> ) : (
{t('unknownRegistryType', { registryType })}
)} diff --git a/web/crux-ui/src/components/registries/registry-fields/unchecked-registry-field.tsx b/web/crux-ui/src/components/registries/registry-fields/unchecked-registry-field.tsx index fc81b4b6a0..8b3c4f173b 100644 --- a/web/crux-ui/src/components/registries/registry-fields/unchecked-registry-field.tsx +++ b/web/crux-ui/src/components/registries/registry-fields/unchecked-registry-field.tsx @@ -1,15 +1,19 @@ import { DyoInput } from '@app/elements/dyo-input' import { DyoLabel } from '@app/elements/dyo-label' +import DyoPassword from '@app/elements/dyo-password' import DyoToggle from '@app/elements/dyo-toggle' -import { UncheckedRegistryDetails } from '@app/models' -import { EditRegistryTypeProps } from '@app/utils' +import { EditableUncheckedRegistryDetails } from '@app/models' +import { EditRegistryTypeProps, formikSetFieldValueOrIgnore } from '@app/utils' import useTranslation from 'next-translate/useTranslation' -const UncheckedRegistryFields = (props: EditRegistryTypeProps) => { +const UncheckedRegistryFields = (props: EditRegistryTypeProps) => { const { formik } = props + const { values, errors, handleChange, setFieldValue } = formik const { t } = useTranslation('registries') + const editing = !!values.id + return ( <> {t('tips.unchecked')} @@ -18,28 +22,83 @@ const UncheckedRegistryFields = (props: EditRegistryTypeProps => { if (!value) { - await formik.setFieldValue('url', '', false) + await setFieldValue('url', '', false) } - await formik.setFieldValue(field, value, shouldValidate) + await setFieldValue(field, value, shouldValidate) }} /> - {!formik.values.local && ( + {!values.local && ( )} + + { + if (!value) { + await setFieldValue('user', '', false) + await setFieldValue('token', '', false) + } + + await setFieldValue(field, value, shouldValidate) + }} + /> + + {!values.public && ( + <> + {editing && ( + + )} + + {values.changeCredentials && ( + <> + + + + + )} + + )} ) } diff --git a/web/crux-ui/src/models/registry.ts b/web/crux-ui/src/models/registry.ts index 79c24af60c..545c77bc65 100644 --- a/web/crux-ui/src/models/registry.ts +++ b/web/crux-ui/src/models/registry.ts @@ -3,7 +3,7 @@ import { REGISTRY_GITHUB_URL, REGISTRY_GITLAB_URLS, REGISTRY_HUB_URL } from '@ap export const REGISTRY_TYPE_VALUES = ['v2', 'hub', 'gitlab', 'github', 'google', 'unchecked'] as const export type RegistryType = (typeof REGISTRY_TYPE_VALUES)[number] -export const PUBLIC_REGISTRY_TYPES: RegistryType[] = ['hub', 'v2', 'google'] +export const PUBLIC_REGISTRY_TYPES: RegistryType[] = ['hub', 'v2', 'unchecked', 'google'] export const GITHUB_NAMESPACE_VALUES = ['organization', 'user'] as const export const GITLAB_NAMESPACE_VALUES = ['group', 'project'] as const @@ -104,9 +104,11 @@ type UncheckedRegistryDetailsBase = { type: 'unchecked' local?: boolean url: string + public: boolean } export type UncheckedRegistryDetails = RegistryDetailsBase & UncheckedRegistryDetailsBase +export type EditableUncheckedRegistryDetails = EditableRegistryCredentials & UncheckedRegistryDetails type UpsertDetailsDto = Omit, 'type' | 'changeCredentials'> @@ -358,9 +360,12 @@ export const editableRegistryToDto = (ui: EditableRegistry): CreateRegistryDto = } } case 'unchecked': { - const details: Omit = { + const details: UpsertDetailsDto = { url: ui.url, local: ui.local, + public: ui.public, + user: !ui.public && ui.changeCredentials ? ui.user : null, + token: !ui.public && ui.changeCredentials ? ui.token : null, } return { diff --git a/web/crux-ui/src/validations/registry.ts b/web/crux-ui/src/validations/registry.ts index db965c991b..dda85dcf68 100644 --- a/web/crux-ui/src/validations/registry.ts +++ b/web/crux-ui/src/validations/registry.ts @@ -27,7 +27,7 @@ const createRegistryCredentialRole = (label: string) => .meta(shouldResetMetaData) .requiredWhenTypeIs({ public: ['gitlab', 'github'], - private: ['v2', 'google', 'hub'], + private: ['v2', 'unchecked', 'google', 'hub'], }) .label(label) @@ -90,6 +90,7 @@ export const registrySchema = yup.object().shape({ gitlab: 'token', github: 'pat', v2: 'token', + unchecked: 'token', google: 'privateKey', hub: 'token', }), diff --git a/web/crux/src/app/registry/registry.dto.ts b/web/crux/src/app/registry/registry.dto.ts index 8769920592..947ca54bbb 100644 --- a/web/crux/src/app/registry/registry.dto.ts +++ b/web/crux/src/app/registry/registry.dto.ts @@ -236,6 +236,16 @@ export class CreateUncheckedRegistryDetailsDto { @IsBoolean() local: boolean + + @IsString() + @IsOptional() + @ValidateIf(privateAndPropertyIsPresent('token')) + user?: string + + @IsString() + @IsOptional() + @ValidateIf(privateAndPropertyIsPresent('user')) + token?: string } export class UpdateHubRegistryDetailsDto extends CreateHubRegistryDetailsDto {} diff --git a/web/crux/src/app/registry/registry.mapper.ts b/web/crux/src/app/registry/registry.mapper.ts index 57d3c83334..03ed8d54a9 100644 --- a/web/crux/src/app/registry/registry.mapper.ts +++ b/web/crux/src/app/registry/registry.mapper.ts @@ -85,6 +85,7 @@ export default class RegistryMapper { : registry.type === RegistryTypeEnum.unchecked ? { url: registry.url, + public: !registry.user, } : null @@ -171,12 +172,14 @@ export default class RegistryMapper { } } case 'unchecked': { - const details = req.details as CreateUncheckedRegistryDetailsDto | UpdateUncheckedRegistryDetailsDto + const details = this.dtoDetailsToDb( + req.details as CreateUncheckedRegistryDetailsDto | UpdateUncheckedRegistryDetailsDto, + ) return { type: RegistryTypeEnum.unchecked, url: details.local ? '' : details.url, - user: null, - token: null, + user: details.user, + token: details.token, apiUrl: null, imageNamePrefix: null, namespace: null,