-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #109 from screwdriver-cd/template_validation
feat(470): Add template validation
- Loading branch information
Showing
6 changed files
with
99 additions
and
1 deletion.
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
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
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,46 @@ | ||
'use strict'; | ||
|
||
const Joi = require('joi'); | ||
const Job = require('./job'); | ||
const Regex = require('./regex'); | ||
|
||
const TEMPLATE_NAME = Joi | ||
.string() | ||
.regex(Regex.TEMPLATE_NAME) | ||
.description('Name of the Template') | ||
.example('node/npm-install'); | ||
|
||
const TEMPLATE_VERSION = Joi | ||
.string() | ||
.regex(Regex.VERSION) | ||
.description('Version of the Template') | ||
.example('1.2.3'); | ||
|
||
const TEMPLATE_DESCRIPTION = Joi | ||
.string() | ||
.description('Description of the Template') | ||
.example('Installs npm modules'); | ||
|
||
const TEMPLATE_MAINTAINER = Joi | ||
.string() | ||
.email() | ||
.description('Maintainer of the Template') | ||
.example('foo@bar.com'); | ||
|
||
const SCHEMA_TEMPLATE = Joi.object() | ||
.keys({ | ||
name: TEMPLATE_NAME, | ||
version: TEMPLATE_VERSION, | ||
description: TEMPLATE_DESCRIPTION, | ||
maintainer: TEMPLATE_MAINTAINER, | ||
config: Job.job | ||
}) | ||
.requiredKeys('name', 'version', 'description', 'maintainer', 'config.steps'); | ||
|
||
/** | ||
* The definition of the Template pieces | ||
* @type {Object} | ||
*/ | ||
module.exports = { | ||
template: SCHEMA_TEMPLATE | ||
}; |
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
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,13 @@ | ||
'use strict'; | ||
|
||
const assert = require('chai').assert; | ||
const config = require('../../').config; | ||
const validate = require('../helper').validate; | ||
|
||
describe('config template', () => { | ||
describe('template', () => { | ||
it('validates safely', () => { | ||
assert.isNull(validate('config.template.yaml', config.template.template).error); | ||
}); | ||
}); | ||
}); |
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,14 @@ | ||
name: test/template | ||
version: "1.3" | ||
description: Template for testing | ||
maintainer: foo@bar.com | ||
config: | ||
image: node:6 | ||
steps: | ||
- install: npm install | ||
- test: npm test | ||
- echo: echo $FOO | ||
environment: | ||
FOO: bar | ||
secrets: | ||
- NPM_TOKEN |