From d1f0fbe4ccf408e43a64cf64b44132261e94a00a Mon Sep 17 00:00:00 2001 From: Francesco Torchia Date: Tue, 4 Feb 2025 15:27:42 +0100 Subject: [PATCH] Fleet: validate GitRepo Url Signed-off-by: Francesco Torchia --- shell/assets/translations/en-us.yaml | 2 ++ shell/edit/fleet.cattle.io.gitrepo.vue | 8 +++++++- shell/utils/validators/formRules/index.ts | 3 +++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/shell/assets/translations/en-us.yaml b/shell/assets/translations/en-us.yaml index e97c89f0d7b..ba4b781271f 100644 --- a/shell/assets/translations/en-us.yaml +++ b/shell/assets/translations/en-us.yaml @@ -6040,6 +6040,8 @@ validation: flowOutput: both: Requires "Output" or "Cluster Output" to be selected. global: Requires "Cluster Output" to be selected. + git: + repository: Repository URL must be a HTTP(s) or SSH url with no trailing spaces output: logdna: apiKey: Required an "Api Key" to be set. diff --git a/shell/edit/fleet.cattle.io.gitrepo.vue b/shell/edit/fleet.cattle.io.gitrepo.vue index 092d519dd58..0239947cb71 100644 --- a/shell/edit/fleet.cattle.io.gitrepo.vue +++ b/shell/edit/fleet.cattle.io.gitrepo.vue @@ -153,7 +153,13 @@ export default { stepRepoInfo, stepTargetInfo, displayHelmRepoURLRegex: false, - fvFormRuleSets: [{ path: 'spec.repo', rules: ['required'] }] + fvFormRuleSets: [{ + path: 'spec.repo', + rules: [ + 'required', + 'gitRepository' + ], + }] }; }, diff --git a/shell/utils/validators/formRules/index.ts b/shell/utils/validators/formRules/index.ts index ab7de7c1175..a6249f3ee34 100644 --- a/shell/utils/validators/formRules/index.ts +++ b/shell/utils/validators/formRules/index.ts @@ -157,6 +157,8 @@ export default function(t: Translation, { key = 'Value' }: ValidationOptions): { const url: Validator = (val: string) => val && !isUrl(val) ? t('validation.setting.serverUrl.url') : undefined; + const gitRepository: Validator = (val: string) => val && !/^(([A-Za-z0-9]+@|http(|s)\:\/\/)|(http(|s)\:\/\/[A-Za-z0-9]+@))([A-Za-z0-9.]+(:\d+)?)(?::|\/)([\d\/\w.-]+?)(\.git){0,1}$/i.test(val) ? t('validation.git.repository') : undefined; + const alphanumeric: Validator = (val: string) => val && !/^[a-zA-Z0-9]+$/.test(val) ? t('validation.alphanumeric', { key }) : undefined; const interval: Validator = (val: string) => !/^\d+[hms]$/.test(val) ? t('validation.monitoring.route.interval', { key }) : undefined; @@ -486,6 +488,7 @@ export default function(t: Translation, { key = 'Value' }: ValidationOptions): { dnsLabelRestricted, externalName, fileRequired, + gitRepository, groupsAreValid, hostname, imageUrl,