Skip to content

Commit

Permalink
Merge pull request #54 from eva-vashkevich/iss52
Browse files Browse the repository at this point in the history
fixed name validation, fixed vsphere case
  • Loading branch information
eva-vashkevich authored Apr 25, 2024
2 parents 20b3b73 + 1d8c622 commit 634a7a6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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'] },
Expand All @@ -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'])
};
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/capi/l10n/en-us.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
2 changes: 1 addition & 1 deletion pkg/capi/types/capi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions pkg/capi/util/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

0 comments on commit 634a7a6

Please sign in to comment.