screwdriver-api 4.1.199 → 4.1.203

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.199",
3
+ "version": "4.1.203",
4
4
  "description": "API server for the Screwdriver.cd service",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -530,7 +530,7 @@ async function handleNewBuild({ done, hasFailure, newBuild, jobName, pipelineId
530
530
  }
531
531
 
532
532
  // If all join builds finished successfully and it's clear that a new build has not been started before, start new build
533
- if ([ 'CREATED', null, undefined ].includes(newBuild.status)) {
533
+ if (['CREATED', null, undefined].includes(newBuild.status)) {
534
534
  newBuild.status = 'QUEUED';
535
535
  const queuedBuild = await newBuild.update();
536
536
 
@@ -1114,7 +1114,7 @@ const buildsPlugin = {
1114
1114
  tokenRoute(),
1115
1115
  metricsRoute(),
1116
1116
  artifactGetRoute(options),
1117
- artifactUnzipRoute(),
1117
+ artifactUnzipRoute()
1118
1118
  ]);
1119
1119
  }
1120
1120
  };
@@ -115,6 +115,10 @@ module.exports = () => ({
115
115
  userFactory.get({ username, scmContext })
116
116
  ]);
117
117
 
118
+ if (!pipeline) {
119
+ throw boom.notFound();
120
+ }
121
+
118
122
  payload.scmContext = pipeline.scmContext;
119
123
 
120
124
  // In pipeline scope, check if the token is allowed to the pipeline
@@ -126,7 +130,16 @@ module.exports = () => ({
126
130
  const scmUri = await getScmUri({ pipeline, pipelineFactory });
127
131
 
128
132
  // Check the user's permission
129
- const permissions = await user.getPermissions(scmUri);
133
+ let permissions;
134
+
135
+ try {
136
+ permissions = await user.getPermissions(scmUri);
137
+ } catch (err) {
138
+ if (err.statusCode === 403 && (pipeline.scmRepo && pipeline.scmRepo.private)) {
139
+ throw boom.notFound();
140
+ }
141
+ throw boom.boomify(err, { statusCode: err.statusCode });
142
+ }
130
143
 
131
144
  // Update admins
132
145
  if (!prNum) {
@@ -187,8 +200,8 @@ module.exports = () => ({
187
200
  // User has good permissions, create an event
188
201
  sha = await scm.getCommitSha(scmConfig);
189
202
  } catch (err) {
190
- if (err.status) {
191
- throw boom.boomify(err, { statusCode: err.status });
203
+ if (err.statusCode) {
204
+ throw boom.boomify(err, { statusCode: err.statusCode });
192
205
  }
193
206
  }
194
207
 
@@ -90,9 +90,12 @@ module.exports = () => ({
90
90
 
91
91
  await defaultCollection.update();
92
92
  }
93
+
94
+ const results = await pipeline.sync();
95
+
93
96
  // check if pipeline has deploy key annotation then create secrets
94
- const deployKeyAnnotation = pipeline.annotations && pipeline.annotations[ANNOTATION_USE_DEPLOY_KEY]
95
-
97
+ const deployKeyAnnotation = pipeline.annotations && pipeline.annotations[ANNOTATION_USE_DEPLOY_KEY];
98
+
96
99
  if (autoKeysGeneration || deployKeyAnnotation) {
97
100
  const privateDeployKey = await pipelineFactory.scm.addDeployKey({
98
101
  scmContext,
@@ -109,8 +112,6 @@ module.exports = () => ({
109
112
  });
110
113
  }
111
114
 
112
- const results = await pipeline.sync();
113
-
114
115
  await pipeline.addWebhooks(`${request.server.info.uri}/v4/webhooks`);
115
116
 
116
117
  const location = urlLib.format({
@@ -141,25 +141,32 @@ module.exports = () => ({
141
141
  // update pipeline
142
142
  const updatedPipeline = await oldPipeline.update();
143
143
 
144
+ await updatedPipeline.addWebhooks(`${request.server.info.uri}/v4/webhooks`);
145
+
146
+ const result = await updatedPipeline.sync();
147
+
144
148
  // check if pipeline has deploy key annotation then create secrets
145
- const deployKeyAnnotation = oldPipeline.annotations && oldPipeline.annotations[ANNOTATION_USE_DEPLOY_KEY]
149
+ // sync needs to happen before checking annotations
150
+ const deployKeyAnnotation =
151
+ updatedPipeline.annotations && updatedPipeline.annotations[ANNOTATION_USE_DEPLOY_KEY];
146
152
 
147
153
  if (deployKeyAnnotation) {
148
154
  const deploySecret = await secretFactory.get({
149
- pipelineId: oldPipeline.id,
150
- name: deployKeySecret,
151
- })
155
+ pipelineId: updatedPipeline.id,
156
+ name: deployKeySecret
157
+ });
158
+ // create only secret doesn't exist already
152
159
 
153
160
  if (!deploySecret) {
154
161
  const privateDeployKey = await pipelineFactory.scm.addDeployKey({
155
- scmContext: oldPipeline.scmContext,
162
+ scmContext: updatedPipeline.scmContext,
156
163
  checkoutUrl: formattedCheckoutUrl,
157
164
  token
158
165
  });
159
166
  const privateDeployKeyB64 = Buffer.from(privateDeployKey).toString('base64');
160
167
 
161
168
  await secretFactory.create({
162
- pipelineId: oldPipeline.id,
169
+ pipelineId: updatedPipeline.id,
163
170
  name: deployKeySecret,
164
171
  value: privateDeployKeyB64,
165
172
  allowInPR: true
@@ -167,10 +174,6 @@ module.exports = () => ({
167
174
  }
168
175
  }
169
176
 
170
- await updatedPipeline.addWebhooks(`${request.server.info.uri}/v4/webhooks`);
171
-
172
- const result = await updatedPipeline.sync();
173
-
174
177
  return h.response(result.toJson()).code(200);
175
178
  },
176
179
  validate: {
@@ -13,7 +13,7 @@ const { startHookEvent } = require('../webhooks/helper');
13
13
  */
14
14
  const processHooksPlugin = {
15
15
  name: 'processHooks',
16
- async register(server, options) {
16
+ async register(server) {
17
17
  server.route({
18
18
  method: 'POST',
19
19
  path: '/processHooks',
@@ -376,7 +376,7 @@ async function startEvents(eventConfigs, eventFactory) {
376
376
  if (result.value) events.push(result.value);
377
377
  } else {
378
378
  errorCount += 1;
379
- logger.error(`pipeline:${eventConfigs[i].pipelineId} error in starting event`, result.value);
379
+ logger.error(`pipeline:${eventConfigs[i].pipelineId} error in starting event`, result.reason);
380
380
  }
381
381
  });
382
382
 
@@ -1171,7 +1171,13 @@ async function startHookEvent(request, h, webhookConfig) {
1171
1171
  }
1172
1172
  }
1173
1173
 
1174
- const token = await obtainScmToken({ pluginOptions: webhookConfig.pluginOptions, userFactory, username, scmContext, scm });
1174
+ const token = await obtainScmToken({
1175
+ pluginOptions: webhookConfig.pluginOptions,
1176
+ userFactory,
1177
+ username,
1178
+ scmContext,
1179
+ scm
1180
+ });
1175
1181
 
1176
1182
  if (action !== 'release' && action !== 'tag') {
1177
1183
  let scmUri;
@@ -65,7 +65,7 @@ const webhooksPlugin = {
65
65
  const { pipelineFactory, queueWebhook } = request.server.app;
66
66
  const { scm } = pipelineFactory;
67
67
  const { executor, queueWebhookEnabled } = queueWebhook;
68
- let message = 'Unable to process this kind of event';
68
+ const message = 'Unable to process this kind of event';
69
69
  let hookId;
70
70
 
71
71
  try {
@@ -79,6 +79,7 @@ const webhooksPlugin = {
79
79
  parsed.pluginOptions = pluginOptions;
80
80
 
81
81
  const { type } = parsed;
82
+
82
83
  hookId = parsed.hookId;
83
84
 
84
85
  request.log(['webhook', hookId], `Received event type ${type}`);
@@ -92,14 +93,13 @@ const webhooksPlugin = {
92
93
  return await executor.enqueueWebhook(parsed);
93
94
  } catch (err) {
94
95
  // if enqueueWebhook is not implemented, an event starts without enqueuing
95
- if (err.message != 'Not implemented') {
96
+ if (err.message !== 'Not implemented') {
96
97
  throw err;
97
98
  }
98
99
  }
99
100
  }
100
101
 
101
102
  return await startHookEvent(request, h, parsed);
102
-
103
103
  } catch (err) {
104
104
  logger.error(`[${hookId}]: ${err}`);
105
105