screwdriver-api 7.0.32 → 7.0.34

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 CHANGED
@@ -254,14 +254,14 @@ datastore.setup(datastoreConfig.ddlSyncEnabled).then(() =>
254
254
  commandFactory,
255
255
  commandTagFactory,
256
256
  templateFactory,
257
+ pipelineTemplateFactory,
258
+ pipelineTemplateVersionFactory,
257
259
  templateTagFactory,
258
260
  pipelineFactory,
259
261
  jobFactory,
260
262
  userFactory,
261
263
  buildFactory,
262
264
  buildClusterFactory,
263
- pipelineTemplateFactory,
264
- pipelineTemplateVersionFactory,
265
265
  stepFactory,
266
266
  bannerFactory,
267
267
  secretFactory,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "screwdriver-api",
3
- "version": "7.0.32",
3
+ "version": "7.0.34",
4
4
  "description": "API server for the Screwdriver.cd service",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -208,3 +208,84 @@ handler: async (request, h) => {
208
208
  // ...
209
209
  }
210
210
  ```
211
+
212
+ #### Pipeline Templates
213
+ ##### Get all pipeline templates
214
+
215
+ `GET /pipeline/templates`
216
+
217
+ Can use additional options for sorting, pagination and count:
218
+ `GET /pipeline/templates?sort=ascending&sortBy=name&page=1&count=50`
219
+
220
+ ##### Get all versions for a pipeline template
221
+
222
+ `GET /pipeline/templates/{namespace}/{name}/versions`
223
+
224
+ Can use additional options for sorting, pagination and count:
225
+ `GET /pipeline/templates/{namespace}/{name}/versions?sort=ascending&page=1&count=50`
226
+
227
+ ##### Create a pipeline template
228
+ Creating a template will store the template meta (`name`, `namespace`, `maintainer`, `latestVersion`, `trustedSinceVersion`, `pipelineId`) and template version (`description`, `version`, `config`, `createTime`, `templateId`) into the datastore.
229
+
230
+ `version` will be auto-bumped. For example, if `mypipelinetemplate@1.0.0` already exists and the version passed in is `1.0.0`, the newly created template will be version `1.0.1`.
231
+
232
+
233
+ `POST /pipeline/template`
234
+ ###### Arguments
235
+
236
+ 'name', 'namespace', 'version', 'description', 'maintainer', 'config'
237
+
238
+ * `name` - Name of the template
239
+ * `namespace` - Namespace of the template
240
+ * `version` - Version of the template
241
+ * `description` - Description of the template
242
+ * `maintainer` - Maintainer of the template
243
+ * `config` - Config of the template. This field is an object that includes `steps`, `image`, and optional `secrets`, `environments`. Similar to what's inside the `pipeline`
244
+
245
+ Example payload:
246
+ ```json
247
+ {
248
+ "name": "example-template",
249
+ "namespace": "my-namespace",
250
+ "version": "1.3.1",
251
+ "description": "An example template",
252
+ "maintainer": "example@gmail.com",
253
+ "config": {
254
+ "steps": [{
255
+ "echo": "echo hello"
256
+ }]
257
+ }
258
+ }
259
+ ```
260
+
261
+ ##### Validate a pipeline template
262
+ Validate a pipeline template and return a JSON containing the boolean property ‘valid’ indicating if the template is valid or not
263
+
264
+ `POST /pipeline/template/validate`
265
+
266
+ ###### Arguments
267
+
268
+ 'name', 'namespace', 'version', 'description', 'maintainer', 'config'
269
+
270
+ * `name` - Name of the template
271
+ * `namespace` - Namespace of the template
272
+ * `version` - Version of the template
273
+ * `description` - Description of the template
274
+ * `maintainer` - Maintainer of the template
275
+ * `config` - Config of the template. This field is an object that includes `steps`, `image`, and optional `secrets`, `environments`. Similar to what's inside the `pipeline`
276
+
277
+ Example payload:
278
+ ```json
279
+ {
280
+ "name": "example-template",
281
+ "namespace": "my-namespace",
282
+ "version": "1.3.1",
283
+ "description": "An example template",
284
+ "maintainer": "example@gmail.com",
285
+ "config": {
286
+ "steps": [{
287
+ "echo": "echo hello"
288
+ }]
289
+ }
290
+ }
291
+ ```
@@ -31,6 +31,8 @@ const deleteCache = require('./caches/delete');
31
31
  const openPrRoute = require('./openPr');
32
32
  const createTemplate = require('./templates/create');
33
33
  const validateTemplate = require('./templates/validate');
34
+ const listTemplates = require('./templates/list');
35
+ const listTemplateVersions = require('./templates/listVersions');
34
36
 
35
37
  /**
36
38
  * Pipeline API Plugin
@@ -199,7 +201,9 @@ const pipelinesPlugin = {
199
201
  deleteCache(),
200
202
  openPrRoute(),
201
203
  createTemplate(),
202
- validateTemplate()
204
+ validateTemplate(),
205
+ listTemplates(),
206
+ listTemplateVersions()
203
207
  ]);
204
208
  }
205
209
  };
@@ -0,0 +1,55 @@
1
+ 'use strict';
2
+
3
+ const boom = require('@hapi/boom');
4
+ const schema = require('screwdriver-data-schema');
5
+ const joi = require('joi');
6
+ const listSchema = joi.array().items(schema.models.templateMeta.get).label('List of pipeline templates');
7
+ const listCountSchema = joi
8
+ .object()
9
+ .keys({
10
+ count: joi.number(),
11
+ rows: listSchema
12
+ })
13
+ .label('Pipeline Template Count and List of templates');
14
+
15
+ module.exports = () => ({
16
+ method: 'GET',
17
+ path: '/pipeline/templates',
18
+ options: {
19
+ description: 'List all the pipeline templates',
20
+ notes: 'Returns an array template meta for all the pipeline templates',
21
+ tags: ['api', 'pipeline', 'template'],
22
+ auth: {
23
+ strategies: ['token'],
24
+ scope: ['user', 'build']
25
+ },
26
+ handler: async (request, h) => {
27
+ const { pipelineTemplateFactory } = request.server.app;
28
+
29
+ const { page, sort, sortBy, count } = request.query;
30
+ const config = { sort };
31
+
32
+ if (sortBy) {
33
+ config.sortBy = sortBy;
34
+ }
35
+
36
+ if (page || count) {
37
+ config.paginate = { page, count };
38
+ }
39
+
40
+ const pipelineTemplates = await pipelineTemplateFactory.list(config);
41
+
42
+ if (!pipelineTemplates || pipelineTemplates.length === 0) {
43
+ throw boom.notFound('Pipeline templates do not exist');
44
+ }
45
+
46
+ return h.response(pipelineTemplates).code(200);
47
+ },
48
+ response: {
49
+ schema: joi.alternatives().try(listSchema, listCountSchema)
50
+ },
51
+ validate: {
52
+ query: schema.api.pagination
53
+ }
54
+ }
55
+ });
@@ -0,0 +1,61 @@
1
+ 'use strict';
2
+
3
+ const boom = require('@hapi/boom');
4
+ const joi = require('joi');
5
+ const schema = require('screwdriver-data-schema');
6
+ const listSchema = joi
7
+ .array()
8
+ .items(schema.models.pipelineTemplateVersions.get)
9
+ .label('List of versions of a template');
10
+ const nameSchema = schema.models.templateMeta.base.extract('name');
11
+ const namespaceSchema = schema.models.templateMeta.base.extract('namespace');
12
+
13
+ module.exports = () => ({
14
+ method: 'GET',
15
+ path: '/pipeline/templates/{namespace}/{name}/versions',
16
+ options: {
17
+ description: 'Get all template versions for a given template name with pagination',
18
+ notes: 'Returns all template records for a given template name',
19
+ tags: ['api', 'templates', 'versions'],
20
+ auth: {
21
+ strategies: ['token'],
22
+ scope: ['user', 'build']
23
+ },
24
+ handler: async (request, h) => {
25
+ const { pipelineTemplateVersionFactory } = request.server.app;
26
+ const config = {
27
+ params: request.params,
28
+ sort: request.query.sort
29
+ };
30
+
31
+ if (request.query.page || request.query.count) {
32
+ config.paginate = {
33
+ page: request.query.page,
34
+ count: request.query.count
35
+ };
36
+ }
37
+
38
+ const templates = await pipelineTemplateVersionFactory.list(config);
39
+
40
+ if (!templates || templates.length === 0) {
41
+ throw boom.notFound('Template does not exist');
42
+ }
43
+
44
+ return h.response(templates).code(200);
45
+ },
46
+ response: {
47
+ schema: listSchema
48
+ },
49
+ validate: {
50
+ params: joi.object({
51
+ namespace: namespaceSchema,
52
+ name: nameSchema
53
+ }),
54
+ query: schema.api.pagination.concat(
55
+ joi.object({
56
+ search: joi.forbidden()
57
+ })
58
+ )
59
+ }
60
+ }
61
+ });