Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed name validation, fixed vsphere case #54

Merged
merged 1 commit into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
};