screwdriver-api 8.0.14 → 8.0.16
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/lib/server.js +36 -24
- package/package.json +1 -1
- package/plugins/builds/create.js +15 -1
- package/plugins/events/create.js +2 -2
- package/plugins/events/index.js +16 -2
- package/plugins/events/stopBuilds.js +1 -1
- package/plugins/pipelines/sync.js +9 -0
- package/plugins/webhooks/helper.js +12 -0
package/lib/server.js
CHANGED
|
@@ -9,12 +9,11 @@ process.on('unhandledRejection', (reason, p) => {
|
|
|
9
9
|
});
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
13
|
-
* @method prettyPrintErrors
|
|
12
|
+
* @method handlePreResponseLogs
|
|
14
13
|
* @param {Hapi.Request} request Hapi Request object
|
|
15
14
|
* @param {Hapi.h} h Hapi Response Toolkit
|
|
16
15
|
*/
|
|
17
|
-
function
|
|
16
|
+
function handlePreResponseLogs(request, h) {
|
|
18
17
|
const { response } = request;
|
|
19
18
|
const { release } = request.server.app;
|
|
20
19
|
|
|
@@ -22,31 +21,45 @@ function prettyPrintErrors(request, h) {
|
|
|
22
21
|
h.state(release.cookieName, release.cookieValue);
|
|
23
22
|
}
|
|
24
23
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
// Pretty print errors
|
|
25
|
+
if (response.isBoom) {
|
|
26
|
+
const err = response;
|
|
27
|
+
const errName = err.output.payload.error;
|
|
28
|
+
const errMessage = err.message;
|
|
29
|
+
const { statusCode } = err.output.payload;
|
|
30
|
+
const stack = err.stack || errMessage;
|
|
31
|
+
|
|
32
|
+
// If we're throwing errors, let's have them say a little more than just 500
|
|
33
|
+
if (statusCode === 500) {
|
|
34
|
+
request.log(['server', 'error'], stack);
|
|
35
|
+
}
|
|
28
36
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
37
|
+
const res = {
|
|
38
|
+
statusCode,
|
|
39
|
+
error: errName,
|
|
40
|
+
message: errMessage
|
|
41
|
+
};
|
|
34
42
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
43
|
+
if (err.data) {
|
|
44
|
+
res.data = err.data;
|
|
45
|
+
}
|
|
38
46
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
error: errName,
|
|
42
|
-
message: errMessage
|
|
43
|
-
};
|
|
47
|
+
return h.response(res).code(statusCode);
|
|
48
|
+
}
|
|
44
49
|
|
|
45
|
-
|
|
46
|
-
|
|
50
|
+
// Log request payload when it takes longer than 5 seconds to respond
|
|
51
|
+
// This is to prevent logging payloads for every request
|
|
52
|
+
if (request.info && request.info.received && Date.now() - request.info.received > 5000 && request.payload) {
|
|
53
|
+
request.log(['payload'], {
|
|
54
|
+
method: request.method,
|
|
55
|
+
path: request.path,
|
|
56
|
+
payload: request.payload,
|
|
57
|
+
statusCode: request.response && request.response.statusCode,
|
|
58
|
+
responseTime: Date.now() - request.info.received
|
|
59
|
+
});
|
|
47
60
|
}
|
|
48
61
|
|
|
49
|
-
return h.
|
|
62
|
+
return h.continue;
|
|
50
63
|
}
|
|
51
64
|
|
|
52
65
|
/**
|
|
@@ -164,8 +177,7 @@ module.exports = async config => {
|
|
|
164
177
|
});
|
|
165
178
|
}
|
|
166
179
|
|
|
167
|
-
|
|
168
|
-
server.ext('onPreResponse', prettyPrintErrors);
|
|
180
|
+
server.ext('onPreResponse', handlePreResponseLogs);
|
|
169
181
|
|
|
170
182
|
// Audit log
|
|
171
183
|
if (config.log && config.log.audit.enabled) {
|
package/package.json
CHANGED
package/plugins/builds/create.js
CHANGED
|
@@ -64,8 +64,13 @@ module.exports = () => ({
|
|
|
64
64
|
const newAdmins = pipeline.admins;
|
|
65
65
|
|
|
66
66
|
delete newAdmins[username];
|
|
67
|
+
const newAdminUserIds = pipeline.adminUserIds.filter(
|
|
68
|
+
adminUserId => adminUserId !== user.id
|
|
69
|
+
);
|
|
70
|
+
|
|
67
71
|
// This is needed to make admins dirty and update db
|
|
68
72
|
pipeline.admins = newAdmins;
|
|
73
|
+
pipeline.adminUserIds = newAdminUserIds;
|
|
69
74
|
|
|
70
75
|
return pipeline.update().then(() => {
|
|
71
76
|
throw boom.forbidden(
|
|
@@ -83,9 +88,18 @@ module.exports = () => ({
|
|
|
83
88
|
newAdmins[username] = true;
|
|
84
89
|
// This is needed to make admins dirty and update db
|
|
85
90
|
pipeline.admins = newAdmins;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const newAdminUserIds = pipeline.adminUserIds;
|
|
86
94
|
|
|
87
|
-
|
|
95
|
+
if (!newAdminUserIds.includes(user.id)) {
|
|
96
|
+
newAdminUserIds.push(user.id);
|
|
97
|
+
|
|
98
|
+
// This is needed to make admins dirty and update db
|
|
99
|
+
pipeline.adminUserIds = newAdminUserIds;
|
|
88
100
|
}
|
|
101
|
+
|
|
102
|
+
return pipeline.update();
|
|
89
103
|
})
|
|
90
104
|
// user has good permissions, sync and create a build
|
|
91
105
|
.then(() => (job.isPR() ? pipeline.syncPR(job.prNum) : pipeline.sync()))
|
package/plugins/events/create.js
CHANGED
|
@@ -152,7 +152,7 @@ module.exports = () => ({
|
|
|
152
152
|
|
|
153
153
|
// Update admins
|
|
154
154
|
if (!prNum) {
|
|
155
|
-
await updateAdmins({ permissions, pipeline,
|
|
155
|
+
await updateAdmins({ permissions, pipeline, user });
|
|
156
156
|
}
|
|
157
157
|
|
|
158
158
|
// Get scmConfig
|
|
@@ -201,7 +201,7 @@ module.exports = () => ({
|
|
|
201
201
|
await updateAdmins({
|
|
202
202
|
permissions,
|
|
203
203
|
pipeline,
|
|
204
|
-
|
|
204
|
+
user
|
|
205
205
|
});
|
|
206
206
|
}
|
|
207
207
|
}
|
package/plugins/events/index.js
CHANGED
|
@@ -23,17 +23,22 @@ const eventsPlugin = {
|
|
|
23
23
|
* @method updateAdmins
|
|
24
24
|
* @param {Object} permissions User permissions
|
|
25
25
|
* @param {Pipeline} pipeline Pipeline object to update
|
|
26
|
-
* @param {String}
|
|
26
|
+
* @param {String} user User object
|
|
27
27
|
* @return {Promise} Updates the pipeline admins and throws an error if not an admin
|
|
28
28
|
*/
|
|
29
|
-
server.expose('updateAdmins', ({ permissions, pipeline,
|
|
29
|
+
server.expose('updateAdmins', ({ permissions, pipeline, user }) => {
|
|
30
|
+
const { username, id: userId } = user;
|
|
31
|
+
|
|
30
32
|
// Delete user from admin list if bad permissions
|
|
31
33
|
if (!permissions.push) {
|
|
32
34
|
const newAdmins = pipeline.admins;
|
|
33
35
|
|
|
34
36
|
delete newAdmins[username];
|
|
37
|
+
const newAdminUserIds = pipeline.adminUserIds.filter(adminUserId => adminUserId !== userId);
|
|
38
|
+
|
|
35
39
|
// This is needed to make admins dirty and update db
|
|
36
40
|
pipeline.admins = newAdmins;
|
|
41
|
+
pipeline.adminUserIds = newAdminUserIds;
|
|
37
42
|
|
|
38
43
|
return pipeline.update().then(() => {
|
|
39
44
|
throw boom.forbidden(`User ${username} does not have push permission for this repo`);
|
|
@@ -49,7 +54,16 @@ const eventsPlugin = {
|
|
|
49
54
|
newAdmins[name] = true;
|
|
50
55
|
});
|
|
51
56
|
|
|
57
|
+
const newAdminUserIds = [userId];
|
|
58
|
+
|
|
59
|
+
pipeline.adminUserIds.forEach(adminUserId => {
|
|
60
|
+
if (adminUserId !== userId) {
|
|
61
|
+
newAdminUserIds.push(adminUserId);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
52
65
|
pipeline.admins = newAdmins;
|
|
66
|
+
pipeline.adminUserIds = newAdminUserIds;
|
|
53
67
|
|
|
54
68
|
return pipeline.update();
|
|
55
69
|
});
|
|
@@ -60,8 +60,11 @@ module.exports = () => ({
|
|
|
60
60
|
const newAdmins = pipeline.admins;
|
|
61
61
|
|
|
62
62
|
delete newAdmins[username];
|
|
63
|
+
const newAdminUserIds = pipeline.adminUserIds.filter(adminUserId => adminUserId !== user.id);
|
|
64
|
+
|
|
63
65
|
// This is needed to make admins dirty and update db
|
|
64
66
|
pipeline.admins = newAdmins;
|
|
67
|
+
pipeline.adminUserIds = newAdminUserIds;
|
|
65
68
|
|
|
66
69
|
await pipeline.update();
|
|
67
70
|
|
|
@@ -77,10 +80,16 @@ module.exports = () => ({
|
|
|
77
80
|
// user has good permissions, add the user as an admin
|
|
78
81
|
if (!pipeline.admins[username] && hasPushPermissions) {
|
|
79
82
|
const newAdmins = pipeline.admins;
|
|
83
|
+
const newAdminUserIds = pipeline.adminUserIds;
|
|
80
84
|
|
|
81
85
|
newAdmins[username] = true;
|
|
86
|
+
if (!newAdminUserIds.includes(user.id)) {
|
|
87
|
+
newAdminUserIds.push(user.id);
|
|
88
|
+
}
|
|
89
|
+
|
|
82
90
|
// This is needed to make admins dirty and update db
|
|
83
91
|
pipeline.admins = newAdmins;
|
|
92
|
+
pipeline.adminUserIds = newAdminUserIds;
|
|
84
93
|
|
|
85
94
|
await pipeline.update();
|
|
86
95
|
}
|
|
@@ -95,8 +95,11 @@ async function updateAdmins(userFactory, username, scmContext, pipeline, pipelin
|
|
|
95
95
|
const newAdmins = pipeline.admins;
|
|
96
96
|
|
|
97
97
|
delete newAdmins[username];
|
|
98
|
+
const newAdminUserIds = pipeline.adminUserIds.filter(adminUserId => adminUserId !== user.id);
|
|
99
|
+
|
|
98
100
|
// This is needed to make admins dirty and update db
|
|
99
101
|
pipeline.admins = newAdmins;
|
|
102
|
+
pipeline.adminUserIds = newAdminUserIds;
|
|
100
103
|
|
|
101
104
|
return pipeline.update();
|
|
102
105
|
}
|
|
@@ -110,7 +113,16 @@ async function updateAdmins(userFactory, username, scmContext, pipeline, pipelin
|
|
|
110
113
|
newAdmins[name] = true;
|
|
111
114
|
});
|
|
112
115
|
|
|
116
|
+
const newAdminUserIds = [user.id];
|
|
117
|
+
|
|
118
|
+
pipeline.adminUserIds.forEach(adminUserId => {
|
|
119
|
+
if (adminUserId !== user.id) {
|
|
120
|
+
newAdminUserIds.push(adminUserId);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
|
|
113
124
|
pipeline.admins = newAdmins;
|
|
125
|
+
pipeline.adminUserIds = newAdminUserIds;
|
|
114
126
|
|
|
115
127
|
return pipeline.update();
|
|
116
128
|
} catch (err) {
|