diff --git a/libs/ui-components/src/components/Repository/CreateRepository/utils.ts b/libs/ui-components/src/components/Repository/CreateRepository/utils.ts index 7b03b5770..8f17cedbe 100644 --- a/libs/ui-components/src/components/Repository/CreateRepository/utils.ts +++ b/libs/ui-components/src/components/Repository/CreateRepository/utils.ts @@ -1,7 +1,6 @@ import * as Yup from 'yup'; import { TFunction } from 'i18next'; import { - DockerAuth, HttpConfig, HttpRepoSpec, OciAuthType, @@ -132,9 +131,7 @@ export const getInitValues = ({ formValues.useAdvancedConfig = !!( repository.spec.ociAuth || repository.spec['ca.crt'] || - repository.spec.skipServerVerification || - repository.spec.scheme || - repository.spec.accessMode + repository.spec.skipServerVerification ); formValues.ociConfig = { registry: repository.spec.registry, @@ -217,12 +214,6 @@ export const getRepositoryPatches = (values: RepositoryFormValues, repository: R if (ociRepoSpec.skipServerVerification !== undefined) { patches.push({ op: 'remove', path: '/spec/skipServerVerification' }); } - if (ociRepoSpec.scheme) { - patches.push({ op: 'remove', path: '/spec/scheme' }); - } - if (ociRepoSpec.accessMode) { - patches.push({ op: 'remove', path: '/spec/accessMode' }); - } return patches; } @@ -261,17 +252,34 @@ export const getRepositoryPatches = (values: RepositoryFormValues, repository: R const ociAuth = values.ociConfig.ociAuth; if (ociAuth?.use && ociAuth.username && ociAuth.password) { - const ociAuthValue: DockerAuth = { - authType: OciAuthType.DOCKER, - username: ociAuth.username, - password: ociAuth.password, - }; - appendJSONPatch({ - patches, - newValue: ociAuthValue, - originalValue: ociRepoSpec.ociAuth, - path: '/spec/ociAuth', - }); + if (!ociRepoSpec.ociAuth) { + patches.push({ + op: 'add', + path: '/spec/ociAuth', + value: { + authType: OciAuthType.DOCKER, + username: ociAuth.username, + password: ociAuth.password, + }, + }); + } else { + if (ociAuth.username !== ociRepoSpec.ociAuth.username) { + appendJSONPatch({ + patches, + newValue: ociAuth.username, + originalValue: ociRepoSpec.ociAuth.username, + path: '/spec/ociAuth/username', + }); + } + if (ociAuth.password !== ociRepoSpec.ociAuth.password) { + appendJSONPatch({ + patches, + newValue: ociAuth.password, + originalValue: ociRepoSpec.ociAuth.password, + path: '/spec/ociAuth/password', + }); + } + } } else if (ociRepoSpec.ociAuth) { patches.push({ op: 'remove', path: '/spec/ociAuth' }); } @@ -396,18 +404,22 @@ export const getRepositoryPatches = (values: RepositoryFormValues, repository: R }); } } else { - appendJSONPatch({ - patches, - newValue: values.httpConfig?.basicAuth.password, - originalValue: repository.spec.httpConfig.password, - path: '/spec/httpConfig/password', - }); - appendJSONPatch({ - patches, - newValue: values.httpConfig?.basicAuth.username, - originalValue: repository.spec.httpConfig.username, - path: '/spec/httpConfig/username', - }); + if (values.httpConfig.basicAuth.password !== repository.spec.httpConfig.password) { + appendJSONPatch({ + patches, + newValue: values.httpConfig.basicAuth.password, + originalValue: repository.spec.httpConfig.password, + path: '/spec/httpConfig/password', + }); + } + if (values.httpConfig.basicAuth.username !== repository.spec.httpConfig.username) { + appendJSONPatch({ + patches, + newValue: values.httpConfig.basicAuth.username, + originalValue: repository.spec.httpConfig.username, + path: '/spec/httpConfig/username', + }); + } } if (!values.httpConfig?.mTlsAuth?.use) { @@ -424,20 +436,24 @@ export const getRepositoryPatches = (values: RepositoryFormValues, repository: R }); } } else { - appendJSONPatch({ - patches, - newValue: values.httpConfig?.mTlsAuth.tlsCrt, - originalValue: repository.spec.httpConfig['tls.crt'], - path: '/spec/httpConfig/tls.crt', - encodeB64: true, - }); - appendJSONPatch({ - patches, - newValue: values.httpConfig?.mTlsAuth.tlsKey, - originalValue: repository.spec.httpConfig['tls.key'], - path: '/spec/httpConfig/tls.key', - encodeB64: true, - }); + if (values.httpConfig.mTlsAuth.tlsCrt !== repository.spec.httpConfig['tls.crt']) { + appendJSONPatch({ + patches, + newValue: values.httpConfig.mTlsAuth.tlsCrt, + originalValue: repository.spec.httpConfig['tls.crt'], + path: '/spec/httpConfig/tls.crt', + encodeB64: true, + }); + } + if (values.httpConfig.mTlsAuth.tlsKey !== repository.spec.httpConfig['tls.key']) { + appendJSONPatch({ + patches, + newValue: values.httpConfig.mTlsAuth.tlsKey, + originalValue: repository.spec.httpConfig['tls.key'], + path: '/spec/httpConfig/tls.key', + encodeB64: true, + }); + } } if (!values.httpConfig?.token) { @@ -448,12 +464,14 @@ export const getRepositoryPatches = (values: RepositoryFormValues, repository: R }); } } else { - appendJSONPatch({ - patches, - newValue: values.httpConfig?.token, - originalValue: repository.spec.httpConfig.token, - path: '/spec/httpConfig/token', - }); + if (values.httpConfig.token !== repository.spec.httpConfig.token) { + appendJSONPatch({ + patches, + newValue: values.httpConfig.token, + originalValue: repository.spec.httpConfig.token, + path: '/spec/httpConfig/token', + }); + } } } } else if (values.configType === 'ssh') { @@ -484,12 +502,24 @@ export const getRepositoryPatches = (values: RepositoryFormValues, repository: R value, }); } else { - appendJSONPatch({ - patches, - newValue: values.sshConfig?.privateKeyPassphrase, - originalValue: repository.spec.sshConfig.privateKeyPassphrase, - path: '/spec/sshConfig/privateKeyPassphrase', - }); + if (values.sshConfig?.privateKeyPassphrase !== repository.spec.sshConfig.privateKeyPassphrase) { + appendJSONPatch({ + patches, + newValue: values.sshConfig?.privateKeyPassphrase, + originalValue: repository.spec.sshConfig.privateKeyPassphrase, + path: '/spec/sshConfig/privateKeyPassphrase', + }); + } + + if (values.sshConfig?.sshPrivateKey !== repository.spec.sshConfig.sshPrivateKey) { + appendJSONPatch({ + patches, + newValue: values.sshConfig?.sshPrivateKey, + originalValue: repository.spec.sshConfig.sshPrivateKey, + path: '/spec/sshConfig/sshPrivateKey', + encodeB64: true, + }); + } appendJSONPatch({ patches, @@ -497,14 +527,6 @@ export const getRepositoryPatches = (values: RepositoryFormValues, repository: R originalValue: repository.spec.sshConfig.skipServerVerification, path: '/spec/sshConfig/skipServerVerification', }); - - appendJSONPatch({ - patches, - newValue: values.sshConfig?.sshPrivateKey, - originalValue: repository.spec.sshConfig.sshPrivateKey, - path: '/spec/sshConfig/sshPrivateKey', - encodeB64: true, - }); } }