screwdriver-api 4.1.271 → 4.1.274
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 +4 -4
- package/plugins/events/create.js +2 -0
- package/plugins/pipelines/remove.js +2 -2
- package/plugins/pipelines/startAll.js +2 -1
- package/plugins/pipelines/sync.js +16 -9
- package/plugins/pipelines/syncPRs.js +7 -5
- package/plugins/pipelines/syncWebhooks.js +7 -5
- package/plugins/webhooks/helper.js +12 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "screwdriver-api",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.274",
|
|
4
4
|
"description": "API server for the Screwdriver.cd service",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -105,7 +105,7 @@
|
|
|
105
105
|
"screwdriver-config-parser": "^7.6.0",
|
|
106
106
|
"screwdriver-coverage-bookend": "^1.0.3",
|
|
107
107
|
"screwdriver-coverage-sonar": "^3.4.0",
|
|
108
|
-
"screwdriver-data-schema": "^21.
|
|
108
|
+
"screwdriver-data-schema": "^21.27.0",
|
|
109
109
|
"screwdriver-datastore-sequelize": "^7.2.7",
|
|
110
110
|
"screwdriver-executor-base": "^8.4.0",
|
|
111
111
|
"screwdriver-executor-docker": "^5.0.1",
|
|
@@ -114,7 +114,7 @@
|
|
|
114
114
|
"screwdriver-executor-queue": "^3.1.2",
|
|
115
115
|
"screwdriver-executor-router": "^2.3.0",
|
|
116
116
|
"screwdriver-logger": "^1.1.0",
|
|
117
|
-
"screwdriver-models": "^28.
|
|
117
|
+
"screwdriver-models": "^28.18.1",
|
|
118
118
|
"screwdriver-notifications-email": "^2.2.0",
|
|
119
119
|
"screwdriver-notifications-slack": "^3.2.1",
|
|
120
120
|
"screwdriver-request": "^1.0.3",
|
|
@@ -125,7 +125,7 @@
|
|
|
125
125
|
"screwdriver-scm-router": "^6.3.0",
|
|
126
126
|
"screwdriver-template-validator": "^5.2.0",
|
|
127
127
|
"screwdriver-workflow-parser": "^3.2.1",
|
|
128
|
-
"sqlite3": "^5.0.
|
|
128
|
+
"sqlite3": "^5.0.11",
|
|
129
129
|
"stream": "0.0.2",
|
|
130
130
|
"tinytim": "^0.1.1",
|
|
131
131
|
"uuid": "^8.3.2",
|
package/plugins/events/create.js
CHANGED
|
@@ -117,6 +117,8 @@ module.exports = () => ({
|
|
|
117
117
|
|
|
118
118
|
if (!pipeline) {
|
|
119
119
|
throw boom.notFound();
|
|
120
|
+
} else if (pipeline.state === 'INACTIVE') {
|
|
121
|
+
throw boom.badRequest('Cannot create an event for an inactive pipeline');
|
|
120
122
|
}
|
|
121
123
|
|
|
122
124
|
payload.scmContext = pipeline.scmContext;
|
|
@@ -29,10 +29,10 @@ module.exports = () => ({
|
|
|
29
29
|
if (!pipeline) {
|
|
30
30
|
throw boom.notFound('Pipeline does not exist');
|
|
31
31
|
}
|
|
32
|
-
if (pipeline.configPipelineId) {
|
|
32
|
+
if (pipeline.configPipelineId && pipeline.state !== 'INACTIVE') {
|
|
33
33
|
throw boom.forbidden(
|
|
34
34
|
'Child pipeline can only be removed' +
|
|
35
|
-
`
|
|
35
|
+
` after removing it from scmUrls in config pipeline ${pipeline.configPipelineId}`
|
|
36
36
|
);
|
|
37
37
|
}
|
|
38
38
|
if (!user) {
|
|
@@ -22,7 +22,7 @@ module.exports = () => ({
|
|
|
22
22
|
handler: async (request, h) => {
|
|
23
23
|
const { id } = request.params;
|
|
24
24
|
const { pipelineFactory, userFactory } = request.server.app;
|
|
25
|
-
const { username, scmContext } = request.auth.credentials;
|
|
25
|
+
const { username, scmContext, scope } = request.auth.credentials;
|
|
26
26
|
const { isValidToken } = request.server.plugins.pipelines;
|
|
27
27
|
|
|
28
28
|
if (!isValidToken(id, request.auth.credentials)) {
|
|
@@ -44,30 +44,38 @@ module.exports = () => ({
|
|
|
44
44
|
|
|
45
45
|
// Use parent's scmUri if pipeline is child pipeline and using read-only SCM
|
|
46
46
|
const scmUri = await getScmUri({ pipeline, pipelineFactory });
|
|
47
|
+
let hasPushPermissions = false;
|
|
48
|
+
let permissions;
|
|
47
49
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
+
try {
|
|
51
|
+
// Get user permissions
|
|
52
|
+
permissions = await user.getPermissions(scmUri);
|
|
53
|
+
} catch (error) {
|
|
50
54
|
throw boom.boomify(error, { statusCode: error.statusCode });
|
|
51
|
-
}
|
|
55
|
+
}
|
|
52
56
|
|
|
53
57
|
// check if user has push access
|
|
54
58
|
if (!permissions.push) {
|
|
55
|
-
//
|
|
59
|
+
// user is not permitted, delete from admins table
|
|
56
60
|
const newAdmins = pipeline.admins;
|
|
57
61
|
|
|
58
62
|
delete newAdmins[username];
|
|
59
63
|
// This is needed to make admins dirty and update db
|
|
60
64
|
pipeline.admins = newAdmins;
|
|
61
65
|
|
|
62
|
-
|
|
66
|
+
await pipeline.update();
|
|
67
|
+
|
|
68
|
+
if (!scope.includes('admin')) {
|
|
63
69
|
throw boom.forbidden(
|
|
64
70
|
`User ${user.getFullDisplayName()} does not have push permission for this repo`
|
|
65
71
|
);
|
|
66
|
-
}
|
|
72
|
+
}
|
|
73
|
+
} else {
|
|
74
|
+
hasPushPermissions = true;
|
|
67
75
|
}
|
|
68
76
|
|
|
69
77
|
// user has good permissions, add the user as an admin
|
|
70
|
-
if (!pipeline.admins[username]) {
|
|
78
|
+
if (!pipeline.admins[username] && hasPushPermissions) {
|
|
71
79
|
const newAdmins = pipeline.admins;
|
|
72
80
|
|
|
73
81
|
newAdmins[username] = true;
|
|
@@ -78,7 +86,6 @@ module.exports = () => ({
|
|
|
78
86
|
}
|
|
79
87
|
|
|
80
88
|
try {
|
|
81
|
-
// user has good permissions, sync the pipeline
|
|
82
89
|
await pipeline.sync();
|
|
83
90
|
|
|
84
91
|
return h.response().code(204);
|
|
@@ -21,7 +21,7 @@ module.exports = () => ({
|
|
|
21
21
|
handler: async (request, h) => {
|
|
22
22
|
const { id } = request.params;
|
|
23
23
|
const { pipelineFactory, userFactory } = request.server.app;
|
|
24
|
-
const { username, scmContext } = request.auth.credentials;
|
|
24
|
+
const { username, scmContext, scope } = request.auth.credentials;
|
|
25
25
|
|
|
26
26
|
// Fetch the pipeline and user models
|
|
27
27
|
const [pipeline, user] = await Promise.all([
|
|
@@ -36,11 +36,13 @@ module.exports = () => ({
|
|
|
36
36
|
throw boom.notFound(`User ${username} does not exist`);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
if (!scope.includes('admin')) {
|
|
40
|
+
// Use parent's scmUri if pipeline is child pipeline and using read-only SCM
|
|
41
|
+
const scmUri = await getScmUri({ pipeline, pipelineFactory });
|
|
41
42
|
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
// Check the user's permission
|
|
44
|
+
await getUserPermissions({ user, scmUri, level: 'push' });
|
|
45
|
+
}
|
|
44
46
|
|
|
45
47
|
await pipeline.syncPRs();
|
|
46
48
|
|
|
@@ -21,7 +21,7 @@ module.exports = () => ({
|
|
|
21
21
|
handler: async (request, h) => {
|
|
22
22
|
const { id } = request.params;
|
|
23
23
|
const { pipelineFactory, userFactory } = request.server.app;
|
|
24
|
-
const { username, scmContext } = request.auth.credentials;
|
|
24
|
+
const { username, scmContext, scope } = request.auth.credentials;
|
|
25
25
|
|
|
26
26
|
// Fetch the pipeline and user models
|
|
27
27
|
const [pipeline, user] = await Promise.all([
|
|
@@ -36,11 +36,13 @@ module.exports = () => ({
|
|
|
36
36
|
throw boom.notFound(`User ${username} does not exist`);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
if (!scope.includes('admin')) {
|
|
40
|
+
// Use parent's scmUri if pipeline is child pipeline and using read-only SCM
|
|
41
|
+
const scmUri = await getScmUri({ pipeline, pipelineFactory });
|
|
41
42
|
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
// Check the user's permission
|
|
44
|
+
await getUserPermissions({ user, scmUri, level: 'push' });
|
|
45
|
+
}
|
|
44
46
|
|
|
45
47
|
// user has good permissions, add or update webhooks
|
|
46
48
|
await pipeline.addWebhooks(`${request.server.info.uri}/v4/webhooks`);
|
|
@@ -302,8 +302,18 @@ async function triggeredPipelines(
|
|
|
302
302
|
const splitUri = scmUri.split(':');
|
|
303
303
|
const scmBranch = `${splitUri[0]}:${splitUri[1]}:${splitUri[2]}`;
|
|
304
304
|
const scmRepoId = `${splitUri[0]}:${splitUri[1]}`;
|
|
305
|
-
const listConfig = {
|
|
306
|
-
|
|
305
|
+
const listConfig = {
|
|
306
|
+
search: { field: 'scmUri', keyword: `${scmRepoId}:%` },
|
|
307
|
+
params: {
|
|
308
|
+
state: 'ACTIVE'
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
const externalRepoSearchConfig = {
|
|
312
|
+
search: { field: 'subscribedScmUrlsWithActions', keyword: `%${scmRepoId}:%` },
|
|
313
|
+
params: {
|
|
314
|
+
state: 'ACTIVE'
|
|
315
|
+
}
|
|
316
|
+
};
|
|
307
317
|
|
|
308
318
|
const pipelines = await pipelineFactory.list(listConfig);
|
|
309
319
|
|