Skip to content

Commit

Permalink
fix(provider/azure): Add Application Name Validator for Azure (#6473)
Browse files Browse the repository at this point in the history
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
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/scripts/modules/azure/azure.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ module.exports = angular
require('./securityGroup/securityGroup.reader').name,
require('./image/image.reader').name,
require('./cache/cacheConfigurer.service').name,
require('./validation/applicationName.validator').name,
])
.config(function() {
CloudProviderRegistry.registerProvider('azure', {
Expand Down
40 changes: 40 additions & 0 deletions app/scripts/modules/azure/validation/applicationName.validator.js
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);
});

0 comments on commit 2bad922

Please sign in to comment.