forked from spinnaker/deck
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(provider/azure): Add Application Name Validator for Azure (spinna…
…ker#6473) fix(provider/azure): Add Application Name Validator for Azure.
- Loading branch information
Neil Ye
authored and
Matt Duftler
committed
Feb 12, 2019
1 parent
97aca15
commit 2bad922
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
app/scripts/modules/azure/validation/applicationName.validator.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
'use strict'; | ||
|
||
const angular = require('angular'); | ||
|
||
import { ApplicationNameValidator } from '@spinnaker/core'; | ||
|
||
module.exports = angular | ||
.module('spinnaker.azure.validation.applicationName', []) | ||
.factory('azureApplicationNameValidator', function() { | ||
function validateSpecialCharacters(name, errors) { | ||
const pattern = /^([a-zA-Z][a-zA-Z0-9]*)?$/; | ||
if (!pattern.test(name)) { | ||
errors.push( | ||
'The application name must begin with a letter and must contain only letters or digits. No ' + | ||
'special characters are allowed.', | ||
); | ||
} | ||
} | ||
|
||
function validate(name) { | ||
const warnings = [], | ||
errors = []; | ||
|
||
if (name && name.length) { | ||
validateSpecialCharacters(name, errors); | ||
} | ||
|
||
return { | ||
warnings: warnings, | ||
errors: errors, | ||
}; | ||
} | ||
|
||
return { | ||
validate: validate, | ||
}; | ||
}) | ||
.run(function(azureApplicationNameValidator) { | ||
ApplicationNameValidator.registerValidator('azure', azureApplicationNameValidator); | ||
}); |