screwdriver-api 8.0.198 → 8.0.199
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/pipelines/get.js +50 -9
package/package.json
CHANGED
package/plugins/pipelines/get.js
CHANGED
|
@@ -6,6 +6,37 @@ const schema = require('screwdriver-data-schema');
|
|
|
6
6
|
const getSchema = schema.models.pipeline.get;
|
|
7
7
|
const idSchema = schema.models.pipeline.base.extract('id');
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Get a pipeline when the current user is an explicitly registered admin from another SCM context.
|
|
11
|
+
*
|
|
12
|
+
* @param {Object} credentials Request credentials
|
|
13
|
+
* @param {String} pipelineId Target pipeline ID
|
|
14
|
+
* @param {Object} app Server app object
|
|
15
|
+
* @return {Promise<Object|null>} Pipeline when access is allowed, otherwise null
|
|
16
|
+
*/
|
|
17
|
+
async function canAccessPipelineForScmMigration(credentials, pipelineId, app) {
|
|
18
|
+
const { username, scmContext, scope } = credentials;
|
|
19
|
+
const { pipelineFactory, userFactory } = app;
|
|
20
|
+
|
|
21
|
+
if (!scope.includes('user')) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const [pipeline, user] = await Promise.all([
|
|
26
|
+
pipelineFactory.get(pipelineId),
|
|
27
|
+
userFactory.get({ username, scmContext })
|
|
28
|
+
]);
|
|
29
|
+
|
|
30
|
+
if (!pipeline || !user) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const isDifferentScm = user.scmContext !== pipeline.scmContext;
|
|
35
|
+
const isExplicitAdmin = (pipeline.adminUserIds || []).includes(user.id);
|
|
36
|
+
|
|
37
|
+
return isDifferentScm && isExplicitAdmin ? pipeline : null;
|
|
38
|
+
}
|
|
39
|
+
|
|
9
40
|
module.exports = () => ({
|
|
10
41
|
method: 'GET',
|
|
11
42
|
path: '/pipelines/{id}',
|
|
@@ -26,18 +57,28 @@ module.exports = () => ({
|
|
|
26
57
|
handler: async (request, h) => {
|
|
27
58
|
const { canAccessPipeline } = request.server.plugins.pipelines;
|
|
28
59
|
const { credentials } = request.auth;
|
|
60
|
+
const pipelineId = request.params.id;
|
|
61
|
+
let pipeline;
|
|
62
|
+
|
|
63
|
+
try {
|
|
64
|
+
pipeline = await canAccessPipeline(credentials, pipelineId, 'pull', request.server.app);
|
|
65
|
+
} catch (err) {
|
|
66
|
+
if (!boom.isBoom(err, 403)) {
|
|
67
|
+
throw err;
|
|
68
|
+
}
|
|
29
69
|
|
|
30
|
-
|
|
31
|
-
.then(pipeline => {
|
|
32
|
-
if (!pipeline) {
|
|
33
|
-
throw boom.notFound('Pipeline does not exist');
|
|
34
|
-
}
|
|
70
|
+
pipeline = await canAccessPipelineForScmMigration(credentials, pipelineId, request.server.app);
|
|
35
71
|
|
|
36
|
-
|
|
37
|
-
})
|
|
38
|
-
.catch(err => {
|
|
72
|
+
if (!pipeline) {
|
|
39
73
|
throw err;
|
|
40
|
-
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (!pipeline) {
|
|
78
|
+
throw boom.notFound('Pipeline does not exist');
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return h.response(pipeline.toJson());
|
|
41
82
|
},
|
|
42
83
|
response: {
|
|
43
84
|
schema: getSchema
|