From 1d8c622c5c325b1b1b87006e8cb0268a581ceef8 Mon Sep 17 00:00:00 2001 From: Evgeniya Vashkevich Date: Thu, 25 Apr 2024 14:31:45 -0700 Subject: [PATCH] fixed name validation, fixed vsphere case --- .../ProviderConfig.vue | 7 ++++--- pkg/capi/l10n/en-us.yaml | 4 ++-- pkg/capi/types/capi.ts | 2 +- pkg/capi/util/validators.ts | 8 ++++++-- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/pkg/capi/edit/turtles-capi.cattle.io.capiprovider/ProviderConfig.vue b/pkg/capi/edit/turtles-capi.cattle.io.capiprovider/ProviderConfig.vue index 64c908d..5996d2e 100644 --- a/pkg/capi/edit/turtles-capi.cattle.io.capiprovider/ProviderConfig.vue +++ b/pkg/capi/edit/turtles-capi.cattle.io.capiprovider/ProviderConfig.vue @@ -19,7 +19,7 @@ import Banner from '@components/Banner/Banner.vue'; import { _EDIT, _CREATE } from '@shell/config/query-params'; import { allHash } from '@shell/utils/promise'; import { PROVIDER_TYPES, RANCHER_TURTLES_SYSTEM_NAMESPACE, RANCHER_TURTLES_SYSTEM_NAME, Provider } from '../../types/capi'; -import { providerVersionValidator, urlValidator } from '../../util/validators'; +import { providerNameValidator, providerVersionValidator, urlValidator } from '../../util/validators'; const defaultFeatures = { clusterResourceSet: true, @@ -102,7 +102,7 @@ export default (Vue as VueConstructor< return { loading: true, fvFormRuleSets: [ - { path: 'metadata.name', rules: ['required'] }, + { path: 'metadata.name', rules: ['name'] }, { path: 'spec.name', rules: ['required'] }, { path: 'spec.version', rules: ['version'] }, { path: 'spec.fetchConfig.url', rules: ['url'] }, @@ -116,7 +116,8 @@ export default (Vue as VueConstructor< ...mapGetters(['namespaces']), fvExtraRules() { return { - version: providerVersionValidator(this.$store.getters['i18n/t'], this.isCustom), + name: providerNameValidator(this.$store.getters['i18n/t']), + version: providerVersionValidator(this.$store.getters['i18n/t']), url: urlValidator(this.$store.getters['i18n/t']) }; }, diff --git a/pkg/capi/l10n/en-us.yaml b/pkg/capi/l10n/en-us.yaml index e61aa2a..1bc88ae 100644 --- a/pkg/capi/l10n/en-us.yaml +++ b/pkg/capi/l10n/en-us.yaml @@ -170,8 +170,8 @@ validation: stringFormat: '"{key}" must be a valid {format}.' uniqueItems: '"{key}" may not contain duplicate elements.' version: Version format must match format for this provisioner. - name: Name is required. + name: Name is required and must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character. port: Port value must be a number. - url: '"Value" must be a valid URL.' + url: '"Value" must be a valid URL.' error: clusterClassNotFound: Could not find corresponding cluster class. Please check that cluster class exists and is valid. diff --git a/pkg/capi/types/capi.ts b/pkg/capi/types/capi.ts index bf20327..cb82030 100644 --- a/pkg/capi/types/capi.ts +++ b/pkg/capi/types/capi.ts @@ -85,7 +85,7 @@ export const PROVIDER_TYPES: Provider[] = [ id: 'gcp', disabled: false, needCredentials: true }, { - id: 'vsphere', disabled: false, needCredentials: true + id: 'vmwarevsphere', disabled: false, needCredentials: true }, { id: 'custom', disabled: false, needCredentials: false diff --git a/pkg/capi/util/validators.ts b/pkg/capi/util/validators.ts index 665fc85..642927a 100644 --- a/pkg/capi/util/validators.ts +++ b/pkg/capi/util/validators.ts @@ -159,6 +159,10 @@ export const urlValidator = function(t: Translation): Validator { return (val: string) => val && !val.match(/^https?:\/\/(.*)$/) ? t('validation.url') : undefined; }; -export const providerVersionValidator = function(t: Translation, required: boolean): Validator { - return (val: string) => required && !val.match(/^(\.*\w*)*$/) ? t('validation.version') : undefined; +export const providerVersionValidator = function(t: Translation): Validator { + return (val: string) => val && !val.match(/^(\.*\w*)*$/) ? t('validation.version') : undefined; +}; + +export const providerNameValidator = function(t: Translation): Validator { + return (val: string) => !val || !val.match(/^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$/) ? t('validation.name') : undefined; };