screwdriver-api 4.1.177 → 4.1.181

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "screwdriver-api",
3
- "version": "4.1.177",
3
+ "version": "4.1.181",
4
4
  "description": "API server for the Screwdriver.cd service",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,49 @@
1
+ 'use strict';
2
+
3
+ const boom = require('@hapi/boom');
4
+ const joi = require('joi');
5
+ const schema = require('screwdriver-data-schema');
6
+ const idSchema = schema.models.build.base.extract('id');
7
+
8
+ module.exports = config => ({
9
+ method: 'POST',
10
+ path: '/builds/{id}/artifacts/unzip',
11
+ options: {
12
+ description: 'Extract a ZIP for build artifacts',
13
+ notes: 'Extract a specific ZIP for build artifacts',
14
+ tags: ['api', 'builds', 'artifacts'],
15
+ auth: {
16
+ strategies: ['token'],
17
+ scope: ['build']
18
+ },
19
+
20
+ handler: async (req, h) => {
21
+ const buildId = req.params.id;
22
+ const { username, scope } = req.auth.credentials;
23
+ const isBuild = scope.includes('build');
24
+ const { buildFactory } = req.server.app;
25
+
26
+ if (isBuild && username !== buildId) {
27
+ return boom.forbidden(`Credential only valid for ${username}`);
28
+ }
29
+
30
+ return buildFactory
31
+ .get(buildId)
32
+ .then(async buildModel => {
33
+ if (!buildModel) {
34
+ throw boom.notFound('Build does not exist');
35
+ }
36
+ await buildModel.unzipArtifacts();
37
+ return h.response().code(202);
38
+ })
39
+ .catch(err => {
40
+ throw err;
41
+ });
42
+ },
43
+ validate: {
44
+ params: joi.object({
45
+ id: idSchema
46
+ })
47
+ }
48
+ }
49
+ });
@@ -11,6 +11,7 @@ const createRoute = require('./create');
11
11
  const stepGetRoute = require('./steps/get');
12
12
  const listStepsRoute = require('./steps/list');
13
13
  const artifactGetRoute = require('./artifacts/get');
14
+ const artifactUnzipRoute = require('./artifacts/unzip');
14
15
  const stepUpdateRoute = require('./steps/update');
15
16
  const stepLogsRoute = require('./steps/logs');
16
17
  const listSecretsRoute = require('./listSecrets');
@@ -270,7 +271,6 @@ async function createInternalBuild(config) {
270
271
  } else {
271
272
  job = await jobFactory.get(jobId);
272
273
  }
273
-
274
274
  const internalBuildConfig = {
275
275
  jobId: job.id,
276
276
  sha: event.sha,
@@ -410,6 +410,11 @@ function parseJobInfo({ joinObj = {}, current, nextJobName, nextPipelineId }) {
410
410
  * @return {Promise} All finished builds
411
411
  */
412
412
  async function getFinishedBuilds(event, buildFactory) {
413
+ if (!event.parentEventId) {
414
+ // FIXME: remove this flow to always use buildFactory.getLatestBuilds
415
+ return event.getBuilds();
416
+ }
417
+
413
418
  // FIXME: buildFactory.getLatestBuilds doesn't return build model
414
419
  const builds = await buildFactory.getLatestBuilds({ groupEventId: event.groupEventId });
415
420
 
@@ -1106,7 +1111,8 @@ const buildsPlugin = {
1106
1111
  listSecretsRoute(),
1107
1112
  tokenRoute(),
1108
1113
  metricsRoute(),
1109
- artifactGetRoute(options)
1114
+ artifactGetRoute(options),
1115
+ artifactUnzipRoute(),
1110
1116
  ]);
1111
1117
  }
1112
1118
  };
@@ -32,9 +32,6 @@ server.register({
32
32
  #### Returns a list of builds associated with the event
33
33
  `GET /events/{id}/builds`
34
34
 
35
- `GET /events/{id}/builds?steps=true`
36
-
37
-
38
35
  #### Get build metrics for a single event
39
36
  `GET /events/{id}/metrics`
40
37
 
@@ -24,23 +24,14 @@ module.exports = () => ({
24
24
  handler: async (request, h) => {
25
25
  const { eventFactory } = request.server.app;
26
26
  const event = await eventFactory.get(request.params.id);
27
- const { steps } = request.query;
28
27
 
29
28
  if (!event) {
30
29
  throw boom.notFound('Event does not exist');
31
30
  }
32
31
 
33
- const buildsModel = await event.getBuilds({
34
- readOnly: true
35
- });
32
+ const buildsModel = await event.getBuilds();
36
33
 
37
- let data;
38
-
39
- if (steps) {
40
- data = await Promise.all(buildsModel.map(async buildModel => buildModel.toJsonWithSteps()));
41
- } else {
42
- data = await Promise.all(buildsModel.map(async buildModel => buildModel.toJson()));
43
- }
34
+ const data = await Promise.all(buildsModel.map(async buildModel => buildModel.toJsonWithSteps()));
44
35
 
45
36
  return h.response(data);
46
37
  },
@@ -50,16 +41,7 @@ module.exports = () => ({
50
41
  validate: {
51
42
  params: joi.object({
52
43
  id: eventIdSchema
53
- }),
54
- query: schema.api.pagination.concat(
55
- joi.object({
56
- steps: joi
57
- .boolean()
58
- .truthy('true')
59
- .falsy('false')
60
- .default(false)
61
- })
62
- )
44
+ })
63
45
  }
64
46
  }
65
47
  });
@@ -46,8 +46,6 @@ Example payload:
46
46
  #### Get list of builds for a single job
47
47
  `GET /jobs/{id}/builds`
48
48
 
49
- `GET /jobs/{id}/builds?steps=true`
50
-
51
49
  `GET /jobs/{id}/builds?page=2&count=30&sort=ascending`
52
50
 
53
51
  `GET /jobs/{id}/builds?page=2&count=30&sort=ascending&sortBy=id`
@@ -23,7 +23,7 @@ module.exports = () => ({
23
23
 
24
24
  handler: async (request, h) => {
25
25
  const factory = request.server.app.jobFactory;
26
- const { sort, sortBy, page, count, steps } = request.query;
26
+ const { sort, sortBy, page, count } = request.query;
27
27
 
28
28
  return factory
29
29
  .get(request.params.id)
@@ -32,7 +32,7 @@ module.exports = () => ({
32
32
  throw boom.notFound('Job does not exist');
33
33
  }
34
34
 
35
- const config = { sort, sortBy: 'createTime', readOnly: true };
35
+ const config = { sort, sortBy: 'createTime' };
36
36
 
37
37
  if (sortBy) {
38
38
  config.sortBy = sortBy;
@@ -45,13 +45,7 @@ module.exports = () => ({
45
45
  return job.getBuilds(config);
46
46
  })
47
47
  .then(async builds => {
48
- let data;
49
-
50
- if (steps) {
51
- data = await Promise.all(builds.map(b => b.toJsonWithSteps()));
52
- } else {
53
- data = await Promise.all(builds.map(b => b.toJson()));
54
- }
48
+ const data = await Promise.all(builds.map(b => b.toJsonWithSteps()));
55
49
 
56
50
  return h.response(data);
57
51
  })
@@ -66,15 +60,7 @@ module.exports = () => ({
66
60
  params: joi.object({
67
61
  id: jobIdSchema
68
62
  }),
69
- query: schema.api.pagination.concat(
70
- joi.object({
71
- steps: joi
72
- .boolean()
73
- .truthy('true')
74
- .falsy('false')
75
- .default(false)
76
- })
77
- )
63
+ query: schema.api.pagination
78
64
  }
79
65
  }
80
66
  });