screwdriver-api 8.0.57 → 8.0.59

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "screwdriver-api",
3
- "version": "8.0.57",
3
+ "version": "8.0.59",
4
4
  "description": "API server for the Screwdriver.cd service",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -121,7 +121,7 @@
121
121
  "screwdriver-executor-queue": "^6.0.0",
122
122
  "screwdriver-executor-router": "^5.0.0",
123
123
  "screwdriver-logger": "^3.0.0",
124
- "screwdriver-models": "^32.4.0",
124
+ "screwdriver-models": "^32.8.0",
125
125
  "screwdriver-notifications-email": "^5.0.0",
126
126
  "screwdriver-notifications-slack": "^7.0.0",
127
127
  "screwdriver-request": "^3.0.0",
@@ -5,6 +5,7 @@ const joi = require('joi');
5
5
  const schema = require('screwdriver-data-schema');
6
6
  const getSchema = schema.models.pipeline.base.extract('admins').get;
7
7
  const idSchema = schema.models.pipeline.base.extract('id');
8
+ const scmContextSchema = schema.models.pipeline.base.extract('scmContext');
8
9
 
9
10
  module.exports = () => ({
10
11
  method: 'GET',
@@ -15,19 +16,39 @@ module.exports = () => ({
15
16
  tags: ['api', 'pipelines'],
16
17
  auth: {
17
18
  strategies: ['token'],
18
- scope: ['user', 'pipeline', '!guest']
19
+ scope: ['user', 'admin', 'pipeline', '!guest']
19
20
  },
20
21
 
21
22
  handler: async (request, h) => {
22
- const factory = request.server.app.pipelineFactory;
23
- const pipeline = await factory.get(request.params.id);
23
+ const pipelineFactory = request.server.app.pipelineFactory;
24
+ const { scope } = request.auth.credentials;
25
+ const { scmContext, includeUserToken } = request.query;
26
+
27
+ if (includeUserToken && !scope.includes('admin')) {
28
+ throw boom.forbidden('Only Screwdriver admin is allowed to request user token');
29
+ }
30
+
31
+ const pipeline = await pipelineFactory.get(request.params.id);
24
32
 
25
33
  if (!pipeline) {
26
34
  throw boom.notFound('Pipeline does not exist');
27
35
  }
28
36
 
29
37
  try {
30
- const admin = await pipeline.getFirstAdmin();
38
+ const admin =
39
+ scmContext && scmContext !== pipeline.scmContext
40
+ ? await pipeline.getFirstAdmin({ scmContext })
41
+ : await pipeline.getFirstAdmin();
42
+
43
+ if (includeUserToken) {
44
+ const profile = request.server.plugins.auth.generateProfile({
45
+ username: admin.username,
46
+ scmContext: admin.scmContext,
47
+ scope: ['user']
48
+ });
49
+
50
+ admin.userToken = request.server.plugins.auth.generateToken(profile);
51
+ }
31
52
 
32
53
  return h.response(admin);
33
54
  } catch (e) {
@@ -40,6 +61,10 @@ module.exports = () => ({
40
61
  validate: {
41
62
  params: joi.object({
42
63
  id: idSchema
64
+ }),
65
+ query: joi.object({
66
+ scmContext: scmContextSchema.optional(),
67
+ includeUserToken: joi.boolean().optional()
43
68
  })
44
69
  }
45
70
  }