Skip to content

Commit

Permalink
Fleet: validate GitRepo Url
Browse files Browse the repository at this point in the history
Signed-off-by: Francesco Torchia <[email protected]>
  • Loading branch information
torchiaf committed Feb 4, 2025
1 parent 20d87dc commit d1f0fbe
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions shell/assets/translations/en-us.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 7 additions & 1 deletion shell/edit/fleet.cattle.io.gitrepo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,13 @@ export default {
stepRepoInfo,
stepTargetInfo,
displayHelmRepoURLRegex: false,
fvFormRuleSets: [{ path: 'spec.repo', rules: ['required'] }]
fvFormRuleSets: [{
path: 'spec.repo',

Check warning on line 157 in shell/edit/fleet.cattle.io.gitrepo.vue

View workflow job for this annotation

GitHub Actions / lint

Missing space before value for key 'path'
rules: [
'required',
'gitRepository'
],
}]
};
},
Expand Down
3 changes: 3 additions & 0 deletions shell/utils/validators/formRules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -486,6 +488,7 @@ export default function(t: Translation, { key = 'Value' }: ValidationOptions): {
dnsLabelRestricted,
externalName,
fileRequired,
gitRepository,
groupsAreValid,
hostname,
imageUrl,
Expand Down

0 comments on commit d1f0fbe

Please sign in to comment.