screwdriver-api 8.0.199 → 8.0.200
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 +1 -1
- package/plugins/builds/create.js +6 -0
- package/plugins/builds/triggers/helpers.js +12 -0
- package/plugins/events/create.js +4 -0
- package/plugins/pipelines/create.js +5 -1
- package/plugins/pipelines/openPr.js +26 -6
- package/plugins/pipelines/startAll.js +9 -2
- package/plugins/pipelines/sync.js +4 -0
- package/plugins/pipelines/syncPRs.js +5 -1
- package/plugins/pipelines/syncWebhooks.js +5 -1
- package/plugins/pipelines/tokens/create.js +5 -1
- package/plugins/webhooks/helper.js +33 -0
package/package.json
CHANGED
package/plugins/builds/create.js
CHANGED
|
@@ -66,6 +66,12 @@ module.exports = () => ({
|
|
|
66
66
|
// check if user has push access
|
|
67
67
|
// eslint-disable-next-line consistent-return
|
|
68
68
|
.then(permissions => {
|
|
69
|
+
if (permissions.archived === true) {
|
|
70
|
+
throw boom.forbidden(
|
|
71
|
+
'Archived repositories cannot be used for this operation'
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
69
75
|
if (!permissions.push) {
|
|
70
76
|
// the user who are not permitted is deleted from admins table
|
|
71
77
|
const newAdmins = pipeline.admins;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const logger = require('screwdriver-logger');
|
|
4
|
+
const boom = require('@hapi/boom');
|
|
4
5
|
const workflowParser = require('screwdriver-workflow-parser');
|
|
5
6
|
const merge = require('lodash.mergewith');
|
|
6
7
|
const schema = require('screwdriver-data-schema');
|
|
@@ -236,6 +237,17 @@ async function createEvent(config) {
|
|
|
236
237
|
|
|
237
238
|
// get pipeline admin's token
|
|
238
239
|
const token = await realAdmin.unsealToken();
|
|
240
|
+
const permissions = await eventFactory.scm.getPermissions({
|
|
241
|
+
scmContext,
|
|
242
|
+
scmUri,
|
|
243
|
+
scmRepo: pipeline.scmRepo,
|
|
244
|
+
token
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
if (permissions.archived === true) {
|
|
248
|
+
throw boom.forbidden('Archived repositories cannot be used for this operation');
|
|
249
|
+
}
|
|
250
|
+
|
|
239
251
|
const scmConfig = {
|
|
240
252
|
scmContext,
|
|
241
253
|
scmUri,
|
package/plugins/events/create.js
CHANGED
|
@@ -170,6 +170,10 @@ module.exports = () => ({
|
|
|
170
170
|
throw boom.boomify(err, { statusCode: err.statusCode });
|
|
171
171
|
}
|
|
172
172
|
|
|
173
|
+
if (permissions.archived === true) {
|
|
174
|
+
throw boom.forbidden('Archived repositories cannot be used for this operation');
|
|
175
|
+
}
|
|
176
|
+
|
|
173
177
|
// Update admins
|
|
174
178
|
if (!prNum) {
|
|
175
179
|
try {
|
|
@@ -52,7 +52,11 @@ module.exports = () => ({
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
// get the user permissions for the repo
|
|
55
|
-
await getUserPermissions({ user, scmUri });
|
|
55
|
+
const permissions = await getUserPermissions({ user, scmUri });
|
|
56
|
+
|
|
57
|
+
if (permissions.archived === true) {
|
|
58
|
+
throw boom.forbidden('Archived repositories cannot be used for this operation');
|
|
59
|
+
}
|
|
56
60
|
|
|
57
61
|
// see if there is already a pipeline
|
|
58
62
|
let pipeline = await pipelineFactory.get({ scmUri });
|
|
@@ -26,11 +26,16 @@ module.exports = () => ({
|
|
|
26
26
|
},
|
|
27
27
|
|
|
28
28
|
handler: async (request, h) => {
|
|
29
|
-
const { userFactory } = request.server.app;
|
|
29
|
+
const { pipelineFactory, userFactory } = request.server.app;
|
|
30
30
|
const { username, scmContext } = request.auth.credentials;
|
|
31
31
|
const { files, title, message } = request.payload;
|
|
32
32
|
const checkoutUrl = helper.formatCheckoutUrl(request.payload.checkoutUrl);
|
|
33
33
|
const rootDir = helper.sanitizeRootDir(request.payload.rootDir);
|
|
34
|
+
const pipeline = await pipelineFactory.get(request.params.id);
|
|
35
|
+
|
|
36
|
+
if (!pipeline) {
|
|
37
|
+
throw boom.notFound('Pipeline does not exist');
|
|
38
|
+
}
|
|
34
39
|
|
|
35
40
|
return userFactory
|
|
36
41
|
.get({ username, scmContext })
|
|
@@ -49,10 +54,25 @@ module.exports = () => ({
|
|
|
49
54
|
checkoutUrl,
|
|
50
55
|
token
|
|
51
56
|
})
|
|
52
|
-
.then(scmUri =>
|
|
53
|
-
|
|
57
|
+
.then(scmUri => {
|
|
58
|
+
if (
|
|
59
|
+
scmUri.split(':').slice(0, 2).join(':') !==
|
|
60
|
+
pipeline.scmUri.split(':').slice(0, 2).join(':')
|
|
61
|
+
) {
|
|
62
|
+
throw boom.forbidden(
|
|
63
|
+
'Creating pull requests to repositories other than the pipeline is not permitted'
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return user
|
|
54
68
|
.getPermissions(scmUri)
|
|
55
|
-
.then(permissions => {
|
|
69
|
+
.then(async permissions => {
|
|
70
|
+
if (permissions.archived === true) {
|
|
71
|
+
throw boom.forbidden(
|
|
72
|
+
'Archived repositories cannot be used for this operation'
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
56
76
|
if (!permissions.push) {
|
|
57
77
|
throw boom.forbidden(
|
|
58
78
|
`User ${user.getFullDisplayName()} does not have push permission for this repo`
|
|
@@ -79,8 +99,8 @@ module.exports = () => ({
|
|
|
79
99
|
.catch(error => {
|
|
80
100
|
// 404 error throws, if branch name is incorrect
|
|
81
101
|
throw boom.boomify(error, { statusCode: error.statusCode });
|
|
82
|
-
})
|
|
83
|
-
);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
84
104
|
})
|
|
85
105
|
.then(async pullRequest => {
|
|
86
106
|
if (!pullRequest) {
|
|
@@ -38,7 +38,11 @@ module.exports = () => ({
|
|
|
38
38
|
|
|
39
39
|
const user = await userFactory.get({ username, scmContext });
|
|
40
40
|
|
|
41
|
-
await getUserPermissions({ user, scmUri: pipeline.scmUri, level: 'push' });
|
|
41
|
+
const permissions = await getUserPermissions({ user, scmUri: pipeline.scmUri, level: 'push' });
|
|
42
|
+
|
|
43
|
+
if (permissions.archived === true) {
|
|
44
|
+
throw boom.forbidden('Archived repositories cannot be used for this operation');
|
|
45
|
+
}
|
|
42
46
|
|
|
43
47
|
const pipelines = await pipelineFactory.list({
|
|
44
48
|
params: {
|
|
@@ -56,8 +60,11 @@ module.exports = () => ({
|
|
|
56
60
|
scmUri: p.scmUri,
|
|
57
61
|
token: pipelineToken
|
|
58
62
|
});
|
|
63
|
+
const childPermissions = await getUserPermissions({ user, scmUri: p.scmUri, level: 'push' });
|
|
59
64
|
|
|
60
|
-
|
|
65
|
+
if (childPermissions.archived === true) {
|
|
66
|
+
throw boom.forbidden('Archived repositories cannot be used for this operation');
|
|
67
|
+
}
|
|
61
68
|
|
|
62
69
|
await createEvent(
|
|
63
70
|
{
|
|
@@ -66,6 +66,10 @@ module.exports = () => ({
|
|
|
66
66
|
throw boom.boomify(error, { statusCode: error.statusCode });
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
if (permissions.archived === true) {
|
|
70
|
+
throw boom.forbidden('Archived repositories cannot be used for this operation');
|
|
71
|
+
}
|
|
72
|
+
|
|
69
73
|
// check if user has push access
|
|
70
74
|
if (!permissions.push) {
|
|
71
75
|
// user is not permitted, delete from admins table
|
|
@@ -49,7 +49,11 @@ module.exports = () => ({
|
|
|
49
49
|
const scmUri = await getScmUri({ pipeline, pipelineFactory });
|
|
50
50
|
|
|
51
51
|
// Check the user's permission
|
|
52
|
-
await getUserPermissions({ user, scmUri, level: 'push' });
|
|
52
|
+
const permissions = await getUserPermissions({ user, scmUri, level: 'push' });
|
|
53
|
+
|
|
54
|
+
if (permissions.archived === true) {
|
|
55
|
+
throw boom.forbidden('Archived repositories cannot be used for this operation');
|
|
56
|
+
}
|
|
53
57
|
}
|
|
54
58
|
|
|
55
59
|
await pipeline.syncPRs();
|
|
@@ -49,7 +49,11 @@ module.exports = () => ({
|
|
|
49
49
|
const scmUri = await getScmUri({ pipeline, pipelineFactory });
|
|
50
50
|
|
|
51
51
|
// Check the user's permission
|
|
52
|
-
await getUserPermissions({ user, scmUri, level: 'push' });
|
|
52
|
+
const permissions = await getUserPermissions({ user, scmUri, level: 'push' });
|
|
53
|
+
|
|
54
|
+
if (permissions.archived === true) {
|
|
55
|
+
throw boom.forbidden('Archived repositories cannot be used for this operation');
|
|
56
|
+
}
|
|
53
57
|
}
|
|
54
58
|
|
|
55
59
|
// user has good permissions, add or update webhooks
|
|
@@ -52,7 +52,11 @@ module.exports = () => ({
|
|
|
52
52
|
const scmUri = await getScmUri({ pipeline, pipelineFactory });
|
|
53
53
|
|
|
54
54
|
// Check the user's permission
|
|
55
|
-
await getUserPermissions({ user, scmUri });
|
|
55
|
+
const permissions = await getUserPermissions({ user, scmUri });
|
|
56
|
+
|
|
57
|
+
if (permissions.archived === true) {
|
|
58
|
+
throw boom.forbidden('Archived repositories cannot be used for this operation');
|
|
59
|
+
}
|
|
56
60
|
|
|
57
61
|
// Make sure the token name is unique
|
|
58
62
|
const tokens = await pipeline.tokens;
|
|
@@ -313,6 +313,29 @@ const uriTrimmer = uri => {
|
|
|
313
313
|
return uriToArray.join(':');
|
|
314
314
|
};
|
|
315
315
|
|
|
316
|
+
/**
|
|
317
|
+
* Check whether a pipeline's repository is archived.
|
|
318
|
+
* @method isArchivedPipeline
|
|
319
|
+
* @param {Pipeline} pipeline
|
|
320
|
+
* @param {PipelineFactory} pipelineFactory
|
|
321
|
+
*/
|
|
322
|
+
async function isArchivedPipeline(pipeline, pipelineFactory) {
|
|
323
|
+
const permissions = await pipelineFactory.scm.getPermissions({
|
|
324
|
+
scmUri: pipeline.scmUri,
|
|
325
|
+
scmContext: pipeline.scmContext,
|
|
326
|
+
scmRepo: pipeline.scmRepo,
|
|
327
|
+
token: await pipeline.token
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
if (permissions.archived === true) {
|
|
331
|
+
logger.info(`Skipping pipeline:${pipeline.id} for archived repository`);
|
|
332
|
+
|
|
333
|
+
return true;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
return false;
|
|
337
|
+
}
|
|
338
|
+
|
|
316
339
|
/**
|
|
317
340
|
* Create metadata by the parsed event
|
|
318
341
|
* @param {Object} parsed It has information to create metadata
|
|
@@ -1248,6 +1271,12 @@ async function createEvents(server, userFactory, pipelineFactory, pipelines, par
|
|
|
1248
1271
|
eventConfig.startFrom = '~subscribe';
|
|
1249
1272
|
eventConfig.subscribedConfigSha = eventConfig.sha;
|
|
1250
1273
|
|
|
1274
|
+
if (await isArchivedPipeline(pTuple.pipeline, pipelineFactory)) {
|
|
1275
|
+
logger.info(`skip create event for this subscribed trigger due to archiving repository`);
|
|
1276
|
+
|
|
1277
|
+
return null;
|
|
1278
|
+
}
|
|
1279
|
+
|
|
1251
1280
|
try {
|
|
1252
1281
|
eventConfig.sha = await pipelineFactory.scm.getCommitSha(scmConfig);
|
|
1253
1282
|
} catch (err) {
|
|
@@ -1255,6 +1284,8 @@ async function createEvents(server, userFactory, pipelineFactory, pipelines, par
|
|
|
1255
1284
|
throw err;
|
|
1256
1285
|
} else {
|
|
1257
1286
|
logger.info(`skip create event for this subscribed trigger`);
|
|
1287
|
+
|
|
1288
|
+
return null;
|
|
1258
1289
|
}
|
|
1259
1290
|
}
|
|
1260
1291
|
|
|
@@ -1272,6 +1303,8 @@ async function createEvents(server, userFactory, pipelineFactory, pipelines, par
|
|
|
1272
1303
|
throw err;
|
|
1273
1304
|
} else {
|
|
1274
1305
|
logger.info(`skip create event for this subscribed trigger`);
|
|
1306
|
+
|
|
1307
|
+
return null;
|
|
1275
1308
|
}
|
|
1276
1309
|
}
|
|
1277
1310
|
}
|