screwdriver-api 8.0.189 → 8.0.190

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.189",
3
+ "version": "8.0.190",
4
4
  "description": "API server for the Screwdriver.cd service",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -62,6 +62,10 @@ module.exports = () => ({
62
62
  throw boom.forbidden('Pipeline does not own token');
63
63
  }
64
64
 
65
+ if (request.payload && request.payload.expiresAt !== undefined) {
66
+ token.expiresAt = request.payload.expiresAt;
67
+ }
68
+
65
69
  logger.info(
66
70
  `[Audit] user ${username}:${scmContext} refreshes the token name:${token.name} for pipelineId:${pipelineId}.`
67
71
  );
@@ -73,7 +77,14 @@ module.exports = () => ({
73
77
  params: joi.object({
74
78
  pipelineId: pipelineIdSchema,
75
79
  tokenId: tokenIdSchema
76
- })
80
+ }),
81
+ payload: joi
82
+ .object({
83
+ expiresAt: schema.models.token.update.extract('expiresAt')
84
+ })
85
+ .unknown(true)
86
+ .allow(null)
87
+ .default({})
77
88
  }
78
89
  }
79
90
  });
@@ -65,8 +65,25 @@ module.exports = () => ({
65
65
  throw boom.conflict(`Token ${match.name} already exists`);
66
66
  }
67
67
 
68
+ let payloadOptions;
69
+
70
+ if (request.payload && request.payload.options) {
71
+ payloadOptions = request.payload.options;
72
+ }
73
+
68
74
  Object.keys(request.payload).forEach(key => {
69
- token[key] = request.payload[key];
75
+ if (key === 'options') {
76
+ const hasResourceUpdates =
77
+ payloadOptions.resources && Object.keys(payloadOptions.resources).length > 0;
78
+
79
+ token.options = {
80
+ ...token.options,
81
+ ...payloadOptions,
82
+ resources: hasResourceUpdates ? payloadOptions.resources : token.options.resources
83
+ };
84
+ } else {
85
+ token[key] = request.payload[key];
86
+ }
70
87
  });
71
88
 
72
89
  return token.update().then(() => h.response(token.toJson()).code(200));
@@ -69,6 +69,10 @@ Example payload:
69
69
 
70
70
  `PUT /tokens/{id}/refresh`
71
71
 
72
+ **Arguments**
73
+
74
+ * `expiresAt` - An optional expiration date for the refreshed token.
75
+
72
76
  #### Remove a token
73
77
 
74
78
  `DELETE /tokens/{id}`
@@ -35,7 +35,13 @@ module.exports = () => ({
35
35
  }
36
36
 
37
37
  return canAccess(credentials, token, request.server.app)
38
- .then(() => token.refresh())
38
+ .then(() => {
39
+ if (request.payload && request.payload.expiresAt !== undefined) {
40
+ token.expiresAt = request.payload.expiresAt;
41
+ }
42
+
43
+ return token.refresh();
44
+ })
39
45
  .then(() => h.response(token.toJson()).code(200));
40
46
  })
41
47
  .catch(err => {
@@ -45,7 +51,14 @@ module.exports = () => ({
45
51
  validate: {
46
52
  params: joi.object({
47
53
  id: idSchema
48
- })
54
+ }),
55
+ payload: joi
56
+ .object({
57
+ expiresAt: schema.models.token.update.extract('expiresAt')
58
+ })
59
+ .unknown(true)
60
+ .allow(null)
61
+ .default({})
49
62
  }
50
63
  }
51
64
  });
@@ -50,8 +50,25 @@ module.exports = () => ({
50
50
  throw boom.conflict(`Token with name ${match.name} already exists`);
51
51
  }
52
52
 
53
+ let payloadOptions;
54
+
55
+ if (request.payload && request.payload.options) {
56
+ payloadOptions = request.payload.options;
57
+ }
58
+
53
59
  Object.keys(request.payload).forEach(key => {
54
- token[key] = request.payload[key];
60
+ if (key === 'options') {
61
+ const hasResourceUpdates =
62
+ payloadOptions.resources && Object.keys(payloadOptions.resources).length > 0;
63
+
64
+ token.options = {
65
+ ...token.options,
66
+ ...payloadOptions,
67
+ resources: hasResourceUpdates ? payloadOptions.resources : token.options.resources
68
+ };
69
+ } else {
70
+ token[key] = request.payload[key];
71
+ }
55
72
  });
56
73
 
57
74
  return token.update().then(() => h.response(token.toJson()).code(200));