screwdriver-api 7.0.25 → 7.0.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/server +12 -0
- package/lib/server.js +5 -0
- package/package.json +2 -2
- package/plugins/pipelines/index.js +5 -1
- package/plugins/pipelines/templates/create.js +61 -0
- package/plugins/pipelines/templates/validate.js +38 -0
- package/plugins/template-validator.js +1 -1
- package/plugins/templates/create.js +1 -1
package/bin/server
CHANGED
|
@@ -229,6 +229,16 @@ const buildClusterFactory = Models.BuildClusterFactory.getInstance({
|
|
|
229
229
|
datastoreRO,
|
|
230
230
|
scm
|
|
231
231
|
});
|
|
232
|
+
const pipelineTemplateFactory = Models.PipelineTemplateFactory.getInstance({
|
|
233
|
+
datastore,
|
|
234
|
+
datastoreRO,
|
|
235
|
+
scm
|
|
236
|
+
});
|
|
237
|
+
const pipelineTemplateVersionFactory = Models.PipelineTemplateVersionFactory.getInstance({
|
|
238
|
+
datastore,
|
|
239
|
+
datastoreRO,
|
|
240
|
+
scm
|
|
241
|
+
});
|
|
232
242
|
|
|
233
243
|
// @TODO run setup for SCM and Executor
|
|
234
244
|
// datastoreConfig.ddlSync => sync datastore schema (ddl) via api (default: true)
|
|
@@ -250,6 +260,8 @@ datastore.setup(datastoreConfig.ddlSyncEnabled).then(() =>
|
|
|
250
260
|
userFactory,
|
|
251
261
|
buildFactory,
|
|
252
262
|
buildClusterFactory,
|
|
263
|
+
pipelineTemplateFactory,
|
|
264
|
+
pipelineTemplateVersionFactory,
|
|
253
265
|
stepFactory,
|
|
254
266
|
bannerFactory,
|
|
255
267
|
secretFactory,
|
package/lib/server.js
CHANGED
|
@@ -126,6 +126,11 @@ module.exports = async config => {
|
|
|
126
126
|
commandTagFactory: config.commandTagFactory,
|
|
127
127
|
templateFactory: config.templateFactory,
|
|
128
128
|
templateTagFactory: config.templateTagFactory,
|
|
129
|
+
pipelineTemplateFactory: config.pipelineTemplateFactory,
|
|
130
|
+
pipelineTemplateVersionFactory: config.pipelineTemplateVersionFactory,
|
|
131
|
+
templateMetaFactory: config.templateMetaFactory,
|
|
132
|
+
jobTemplateTagFactory: config.jobTemplateTagFactory,
|
|
133
|
+
pipelineTemplateTagFactory: config.pipelineTemplateTagFactory,
|
|
129
134
|
stageFactory: config.stageFactory,
|
|
130
135
|
stageBuildFactory: config.stageBuildFactory,
|
|
131
136
|
triggerFactory: config.triggerFactory,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "screwdriver-api",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.26",
|
|
4
4
|
"description": "API server for the Screwdriver.cd service",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -123,7 +123,7 @@
|
|
|
123
123
|
"screwdriver-scm-github": "^12.1.1",
|
|
124
124
|
"screwdriver-scm-gitlab": "^3.1.0",
|
|
125
125
|
"screwdriver-scm-router": "^7.0.0",
|
|
126
|
-
"screwdriver-template-validator": "^
|
|
126
|
+
"screwdriver-template-validator": "^7.0.0",
|
|
127
127
|
"screwdriver-workflow-parser": "^4.1.1",
|
|
128
128
|
"sqlite3": "^5.1.4",
|
|
129
129
|
"stream": "0.0.2",
|
|
@@ -29,6 +29,8 @@ const latestCommitEvent = require('./latestCommitEvent');
|
|
|
29
29
|
const getAdmin = require('./admins/get');
|
|
30
30
|
const deleteCache = require('./caches/delete');
|
|
31
31
|
const openPrRoute = require('./openPr');
|
|
32
|
+
const createTemplate = require('./templates/create');
|
|
33
|
+
const validateTemplate = require('./templates/validate');
|
|
32
34
|
|
|
33
35
|
/**
|
|
34
36
|
* Pipeline API Plugin
|
|
@@ -195,7 +197,9 @@ const pipelinesPlugin = {
|
|
|
195
197
|
latestCommitEvent(),
|
|
196
198
|
getAdmin(),
|
|
197
199
|
deleteCache(),
|
|
198
|
-
openPrRoute()
|
|
200
|
+
openPrRoute(),
|
|
201
|
+
createTemplate(),
|
|
202
|
+
validateTemplate()
|
|
199
203
|
]);
|
|
200
204
|
}
|
|
201
205
|
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const boom = require('@hapi/boom');
|
|
4
|
+
const schema = require('screwdriver-data-schema');
|
|
5
|
+
const validator = require('screwdriver-template-validator').parsePipelineTemplate;
|
|
6
|
+
const templateSchema = schema.api.templateValidator;
|
|
7
|
+
|
|
8
|
+
module.exports = () => ({
|
|
9
|
+
method: 'POST',
|
|
10
|
+
path: '/pipeline/template',
|
|
11
|
+
options: {
|
|
12
|
+
description: 'Create a new pipeline template',
|
|
13
|
+
notes: 'Create a specific pipeline template',
|
|
14
|
+
tags: ['api', 'pipelineTemplate'],
|
|
15
|
+
auth: {
|
|
16
|
+
strategies: ['token'],
|
|
17
|
+
scope: ['build']
|
|
18
|
+
},
|
|
19
|
+
|
|
20
|
+
handler: async (request, h) => {
|
|
21
|
+
const { pipelineTemplateVersionFactory, pipelineTemplateFactory } = request.server.app;
|
|
22
|
+
|
|
23
|
+
const config = await validator(request.payload.yaml);
|
|
24
|
+
|
|
25
|
+
if (config.errors.length > 0) {
|
|
26
|
+
throw boom.badRequest(`Template has invalid format: ${config.errors.length} error(s).`, config.errors);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const pipelineTemplate = await pipelineTemplateFactory.get({
|
|
30
|
+
name: config.template.name,
|
|
31
|
+
namespace: config.template.namespace
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const { isPR, pipelineId } = request.auth.credentials;
|
|
35
|
+
|
|
36
|
+
// If template name exists, but this build's pipelineId is not the same as template's pipelineId
|
|
37
|
+
// Then this build does not have permission to publish
|
|
38
|
+
if (isPR || (pipelineTemplate && pipelineId !== pipelineTemplate.pipelineId)) {
|
|
39
|
+
throw boom.forbidden('Not allowed to publish this template');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const template = await pipelineTemplateVersionFactory.create(
|
|
43
|
+
{
|
|
44
|
+
...config.template,
|
|
45
|
+
pipelineId
|
|
46
|
+
},
|
|
47
|
+
pipelineTemplateFactory
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
const location = new URL(
|
|
51
|
+
`${request.path}/${template.id}`,
|
|
52
|
+
`${request.server.info.protocol}://${request.headers.host}`
|
|
53
|
+
).toString();
|
|
54
|
+
|
|
55
|
+
return h.response(template.toJson()).header('Location', location).code(201);
|
|
56
|
+
},
|
|
57
|
+
validate: {
|
|
58
|
+
payload: templateSchema.input
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const boom = require('@hapi/boom');
|
|
4
|
+
const schema = require('screwdriver-data-schema');
|
|
5
|
+
const templateSchema = schema.api.templateValidator;
|
|
6
|
+
const pipelineValidator = require('screwdriver-template-validator').parsePipelineTemplate;
|
|
7
|
+
|
|
8
|
+
module.exports = () => ({
|
|
9
|
+
method: 'POST',
|
|
10
|
+
path: '/pipeline/template/validate',
|
|
11
|
+
options: {
|
|
12
|
+
description: 'Validate a given sd-template.yaml',
|
|
13
|
+
notes: 'returns the parsed config, validation errors, or both',
|
|
14
|
+
tags: ['api', 'validation', 'yaml'],
|
|
15
|
+
auth: {
|
|
16
|
+
strategies: ['token'],
|
|
17
|
+
scope: ['user', 'pipeline']
|
|
18
|
+
},
|
|
19
|
+
|
|
20
|
+
handler: async (request, h) => {
|
|
21
|
+
try {
|
|
22
|
+
const { yaml: templateString } = request.payload;
|
|
23
|
+
|
|
24
|
+
const result = await pipelineValidator(templateString);
|
|
25
|
+
|
|
26
|
+
return h.response(result);
|
|
27
|
+
} catch (err) {
|
|
28
|
+
throw boom.badRequest(err.toString());
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
validate: {
|
|
32
|
+
payload: templateSchema.input
|
|
33
|
+
},
|
|
34
|
+
response: {
|
|
35
|
+
schema: templateSchema.output
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
});
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const boom = require('@hapi/boom');
|
|
4
4
|
const schema = require('screwdriver-data-schema');
|
|
5
5
|
const templateSchema = schema.api.templateValidator;
|
|
6
|
-
const validator = require('screwdriver-template-validator');
|
|
6
|
+
const validator = require('screwdriver-template-validator').parseJobTemplate;
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Hapi Template Validator Plugin
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const urlLib = require('url');
|
|
4
4
|
const boom = require('@hapi/boom');
|
|
5
5
|
const schema = require('screwdriver-data-schema');
|
|
6
|
-
const validator = require('screwdriver-template-validator');
|
|
6
|
+
const validator = require('screwdriver-template-validator').parseJobTemplate;
|
|
7
7
|
const templateSchema = schema.api.templateValidator;
|
|
8
8
|
const hoek = require('@hapi/hoek');
|
|
9
9
|
|