screwdriver-api 8.0.192 → 8.0.194
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
package/plugins/events/create.js
CHANGED
|
@@ -295,10 +295,6 @@ module.exports = () => ({
|
|
|
295
295
|
|
|
296
296
|
const event = await createEvent(payload, request.server);
|
|
297
297
|
|
|
298
|
-
if (event.builds === null) {
|
|
299
|
-
return boom.notFound('No jobs to start.');
|
|
300
|
-
}
|
|
301
|
-
|
|
302
298
|
// everything succeeded, inform the user
|
|
303
299
|
const location = urlLib.format({
|
|
304
300
|
host: request.headers.host,
|
|
@@ -307,6 +303,15 @@ module.exports = () => ({
|
|
|
307
303
|
pathname: `${request.path}/${event.id}`
|
|
308
304
|
});
|
|
309
305
|
|
|
306
|
+
if (event.builds === null) {
|
|
307
|
+
return h
|
|
308
|
+
.response(event.toJson())
|
|
309
|
+
.header('X-Status-Message', 'No jobs to start.')
|
|
310
|
+
.header('Access-Control-Expose-Headers', 'X-Status-Message')
|
|
311
|
+
.header('Location', location)
|
|
312
|
+
.code(201);
|
|
313
|
+
}
|
|
314
|
+
|
|
310
315
|
return h.response(event.toJson()).header('Location', location).code(201);
|
|
311
316
|
},
|
|
312
317
|
validate: {
|
|
@@ -28,9 +28,10 @@ module.exports = () => ({
|
|
|
28
28
|
},
|
|
29
29
|
|
|
30
30
|
handler: async (request, h) => {
|
|
31
|
-
const { pipelineFactory, userFactory } = request.server.app;
|
|
31
|
+
const { pipelineFactory, userFactory, jobFactory, eventFactory } = request.server.app;
|
|
32
32
|
const { username, scmContext } = request.auth.credentials;
|
|
33
33
|
const pipelineId = request.params.id;
|
|
34
|
+
const { scope, cacheId } = request.query;
|
|
34
35
|
const { isValidToken } = request.server.plugins.pipelines;
|
|
35
36
|
|
|
36
37
|
if (!isValidToken(pipelineId, request.auth.credentials)) {
|
|
@@ -55,6 +56,25 @@ module.exports = () => ({
|
|
|
55
56
|
// Check the user's permission
|
|
56
57
|
await getUserPermissions({ user, scmUri, level: 'push' });
|
|
57
58
|
|
|
59
|
+
// Ensure the cache resource (scope/cacheId) actually belongs to this pipeline.
|
|
60
|
+
// The push permission above only authorizes {id}; without this check a caller could
|
|
61
|
+
// delete another pipeline's cache by passing an unrelated cacheId.
|
|
62
|
+
let resourcePipelineId = cacheId;
|
|
63
|
+
|
|
64
|
+
if (scope === 'jobs') {
|
|
65
|
+
const job = await jobFactory.get(cacheId);
|
|
66
|
+
|
|
67
|
+
resourcePipelineId = job && job.pipelineId;
|
|
68
|
+
} else if (scope === 'events') {
|
|
69
|
+
const event = await eventFactory.get(cacheId);
|
|
70
|
+
|
|
71
|
+
resourcePipelineId = event && event.pipelineId;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (resourcePipelineId !== pipelineId) {
|
|
75
|
+
throw boom.forbidden(`Cache ${scope}:${cacheId} does not belong to pipeline ${pipelineId}`);
|
|
76
|
+
}
|
|
77
|
+
|
|
58
78
|
const res = await api.invoke(request);
|
|
59
79
|
const statusCode = res.statusCode === 200 ? 204 : res.statusCode;
|
|
60
80
|
|