screwdriver-api 8.0.7 → 8.0.8
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
|
@@ -15,12 +15,12 @@ module.exports = () => ({
|
|
|
15
15
|
tags: ['api', 'jobs'],
|
|
16
16
|
auth: {
|
|
17
17
|
strategies: ['token'],
|
|
18
|
-
scope: ['
|
|
18
|
+
scope: ['user', '!guest']
|
|
19
19
|
},
|
|
20
20
|
|
|
21
21
|
handler: async (request, h) => {
|
|
22
|
-
const { jobFactory, pipelineFactory } = request.server.app;
|
|
23
|
-
const { username } = request.auth.credentials;
|
|
22
|
+
const { jobFactory, bannerFactory, userFactory, pipelineFactory } = request.server.app;
|
|
23
|
+
const { username, scmContext, scmUserId } = request.auth.credentials;
|
|
24
24
|
const { id } = request.params;
|
|
25
25
|
const adminAnnotation = 'screwdriver.cd/sdAdminBuildClusterOverride';
|
|
26
26
|
const job = await jobFactory.get(id);
|
|
@@ -29,12 +29,32 @@ module.exports = () => ({
|
|
|
29
29
|
throw boom.notFound(`Job ${id} does not exist`);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
const pipeline = await
|
|
32
|
+
const [pipeline, user] = await Promise.all([
|
|
33
|
+
pipelineFactory.get(job.pipelineId),
|
|
34
|
+
userFactory.get({ username, scmContext })
|
|
35
|
+
]);
|
|
33
36
|
|
|
34
37
|
if (!pipeline) {
|
|
35
38
|
throw boom.notFound('Pipeline does not exist');
|
|
36
39
|
}
|
|
37
40
|
|
|
41
|
+
if (!user) {
|
|
42
|
+
throw boom.notFound(`User ${username} does not exist`);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const scmDisplayName = bannerFactory.scm.getDisplayName({ scmContext });
|
|
46
|
+
const adminDetails = request.server.plugins.banners.screwdriverAdminDetails(
|
|
47
|
+
username,
|
|
48
|
+
scmDisplayName,
|
|
49
|
+
scmUserId
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
if (!adminDetails.isAdmin) {
|
|
53
|
+
throw boom.forbidden(
|
|
54
|
+
`User ${username} does not have Screwdriver administrative privileges to update the buildCluster`
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
38
58
|
// remove buildClusterOverride annotation from job
|
|
39
59
|
const [permutation] = job.permutations;
|
|
40
60
|
const buildClusterOverride =
|
|
@@ -50,6 +70,8 @@ module.exports = () => ({
|
|
|
50
70
|
|
|
51
71
|
delete permutation.annotations[adminAnnotation];
|
|
52
72
|
|
|
73
|
+
job.permutations = [permutation];
|
|
74
|
+
|
|
53
75
|
try {
|
|
54
76
|
const result = await job.updateBuildCluster();
|
|
55
77
|
|
|
@@ -15,7 +15,7 @@ module.exports = () => ({
|
|
|
15
15
|
tags: ['api', 'jobs'],
|
|
16
16
|
auth: {
|
|
17
17
|
strategies: ['token'],
|
|
18
|
-
scope: ['
|
|
18
|
+
scope: ['user', '!guest']
|
|
19
19
|
},
|
|
20
20
|
handler: async (request, h) => {
|
|
21
21
|
const adminAnnotation = 'screwdriver.cd/sdAdminBuildClusterOverride';
|
|
@@ -26,8 +26,8 @@ module.exports = () => ({
|
|
|
26
26
|
throw boom.badRequest(`Payload must contain ${adminAnnotation}`);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
const { jobFactory, buildClusterFactory, pipelineFactory } = request.server.app;
|
|
30
|
-
const { scmContext, username } = request.auth.credentials;
|
|
29
|
+
const { jobFactory, bannerFactory, buildClusterFactory, pipelineFactory, userFactory } = request.server.app;
|
|
30
|
+
const { scmContext, username, scmUserId } = request.auth.credentials;
|
|
31
31
|
|
|
32
32
|
const job = await jobFactory.get(id);
|
|
33
33
|
|
|
@@ -35,12 +35,32 @@ module.exports = () => ({
|
|
|
35
35
|
throw boom.notFound(`Job ${id} does not exist`);
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
const pipeline = await
|
|
38
|
+
const [pipeline, user] = await Promise.all([
|
|
39
|
+
pipelineFactory.get(job.pipelineId),
|
|
40
|
+
userFactory.get({ username, scmContext })
|
|
41
|
+
]);
|
|
39
42
|
|
|
40
43
|
if (!pipeline) {
|
|
41
44
|
throw boom.notFound('Pipeline does not exist');
|
|
42
45
|
}
|
|
43
46
|
|
|
47
|
+
if (!user) {
|
|
48
|
+
throw boom.notFound(`User ${username} does not exist`);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const scmDisplayName = bannerFactory.scm.getDisplayName({ scmContext });
|
|
52
|
+
const adminDetails = request.server.plugins.banners.screwdriverAdminDetails(
|
|
53
|
+
username,
|
|
54
|
+
scmDisplayName,
|
|
55
|
+
scmUserId
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
if (!adminDetails.isAdmin) {
|
|
59
|
+
throw boom.forbidden(
|
|
60
|
+
`User ${username} does not have Screwdriver administrative privileges to update the buildCluster`
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
44
64
|
// ensure that the buildCluster is a valid cluster
|
|
45
65
|
const buildClusterName = payload[adminAnnotation];
|
|
46
66
|
const buildCluster = await buildClusterFactory.get({ name: buildClusterName, scmContext });
|
|
@@ -62,6 +82,7 @@ module.exports = () => ({
|
|
|
62
82
|
);
|
|
63
83
|
}
|
|
64
84
|
permutation.annotations[adminAnnotation] = buildClusterName;
|
|
85
|
+
job.permutations = [permutation];
|
|
65
86
|
|
|
66
87
|
try {
|
|
67
88
|
const result = await job.updateBuildCluster();
|