Skip to content

Commit

Permalink
Merge pull request #164 from screwdriver-cd/templateTagRegex
Browse files Browse the repository at this point in the history
fix(616): Add regex for template tag names
  • Loading branch information
petey authored Jul 19, 2017
2 parents a6daa8d + 6fef451 commit 99037da
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
2 changes: 2 additions & 0 deletions config/regex.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
module.exports = {
// Templates can only be named with A-Z,a-z,0-9,-,_,/
TEMPLATE_NAME: /^[\w/-]+$/,
// Template tags must start with an alpha character (A-Z,a-z) and can only contain A-Z,a-z,0-9,-,_
TEMPLATE_TAG_NAME: /^[a-zA-Z][\w-]+$/,
// Version can only have up to 2 decimals, like 1.2.3
VERSION: /^(\d+)?(\.\d+)?(\.\d+)?$/,
// Full name of template and version. Example: chef/publish@1.2.3 or chef/publish@1-stable
Expand Down
8 changes: 8 additions & 0 deletions config/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ const TEMPLATE_NAME = Joi
.description('Name of the Template')
.example('node/npm-install');

const TEMPLATE_TAG_NAME = Joi
.string()
.regex(Regex.TEMPLATE_TAG_NAME)
.max(30)
.description('Name of the Template Tag')
.example('latest');

const TEMPLATE_VERSION = Joi
.string()
.regex(Regex.VERSION)
Expand Down Expand Up @@ -49,6 +56,7 @@ const SCHEMA_TEMPLATE = Joi.object()
module.exports = {
template: SCHEMA_TEMPLATE,
name: TEMPLATE_NAME,
templateTag: TEMPLATE_TAG_NAME,
version: TEMPLATE_VERSION,
description: TEMPLATE_DESCRIPTION,
maintainer: TEMPLATE_MAINTAINER,
Expand Down
6 changes: 1 addition & 5 deletions models/templateTag.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ const MODEL = {
.description('Identifier of this template tag')
.example(123345),
name: Template.name,
tag: Joi
.string()
.alphanum()
.max(30)
.required(),
tag: Template.templateTag,
version: Template.version
};

Expand Down
2 changes: 1 addition & 1 deletion test/data/templatetag.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Base Template Tag Example
id: 123234135
name: test/template
tag: 'stable'
tag: stable
version: '1.2.0'

0 comments on commit 99037da

Please sign in to comment.