screwdriver-api 6.0.26 → 6.0.28

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": "6.0.26",
3
+ "version": "6.0.28",
4
4
  "description": "API server for the Screwdriver.cd service",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -26,39 +26,17 @@ module.exports = () => ({
26
26
 
27
27
  // Check permissions
28
28
  // Must be Screwdriver admin to add Screwdriver build cluster
29
- if (managedByScrewdriver) {
30
- const scmDisplayName = bannerFactory.scm.getDisplayName({ scmContext: payload.scmContext });
31
- const adminDetails = request.server.plugins.banners.screwdriverAdminDetails(username, scmDisplayName);
29
+ const scmDisplayName = bannerFactory.scm.getDisplayName({ scmContext: payload.scmContext });
30
+ const adminDetails = request.server.plugins.banners.screwdriverAdminDetails(username, scmDisplayName);
32
31
 
33
- if (!adminDetails.isAdmin) {
34
- return boom.forbidden(
35
- `User ${adminDetails.userDisplayName}
32
+ if (!adminDetails.isAdmin) {
33
+ return boom.forbidden(
34
+ `User ${adminDetails.userDisplayName}
36
35
  does not have Screwdriver administrative privileges.`
37
- );
38
- }
39
-
40
- return (
41
- buildClusterFactory
42
- .create(payload)
43
- .then(buildCluster => {
44
- // everything succeeded, inform the user
45
- const location = urlLib.format({
46
- host: request.headers.host,
47
- port: request.headers.port,
48
- protocol: request.server.info.protocol,
49
- pathname: `${request.path}/${buildCluster.id}`
50
- });
51
-
52
- return h.response(buildCluster.toJson()).header('Location', location).code(201);
53
- })
54
- // something was botched
55
- .catch(err => {
56
- throw err;
57
- })
58
36
  );
59
37
  }
60
- // Must provide scmOrganizations if not a Screwdriver cluster
61
- if (scmOrganizations && scmOrganizations.length === 0) {
38
+ // Must provide scmOrganizations if not a Screwdriver managed cluster
39
+ if (!managedByScrewdriver && scmOrganizations && scmOrganizations.length === 0) {
62
40
  return boom.badData(`No scmOrganizations provided for build cluster ${name}.`);
63
41
  }
64
42
 
@@ -28,46 +28,18 @@ module.exports = () => ({
28
28
 
29
29
  // Check permissions
30
30
  // Must be Screwdriver admin to update Screwdriver build cluster
31
- if (managedByScrewdriver) {
32
- const scmDisplayName = bannerFactory.scm.getDisplayName({ scmContext: userContext });
33
- const adminDetails = request.server.plugins.banners.screwdriverAdminDetails(username, scmDisplayName);
31
+ const scmDisplayName = bannerFactory.scm.getDisplayName({ scmContext: userContext });
32
+ const adminDetails = request.server.plugins.banners.screwdriverAdminDetails(username, scmDisplayName);
34
33
 
35
- if (!adminDetails.isAdmin) {
36
- return boom.forbidden(
37
- `User ${adminDetails.userDisplayName}
34
+ if (!adminDetails.isAdmin) {
35
+ return boom.forbidden(
36
+ `User ${adminDetails.userDisplayName}
38
37
  does not have Screwdriver administrative privileges.`
39
- );
40
- }
41
-
42
- return buildClusterFactory
43
- .list({
44
- params: {
45
- name,
46
- scmContext: userContext
47
- }
48
- })
49
- .then(buildClusters => {
50
- if (!Array.isArray(buildClusters)) {
51
- throw boom.badData('Build cluster list returned non-array.');
52
- }
53
- if (buildClusters.length === 0) {
54
- throw boom.notFound(
55
- `Build cluster ${name}, scmContext ${payload.scmContext} does not exist`
56
- );
57
- }
58
-
59
- Object.assign(buildClusters[0], request.payload);
60
-
61
- return buildClusters[0]
62
- .update()
63
- .then(updatedBuildCluster => h.response(updatedBuildCluster.toJson()).code(200));
64
- })
65
- .catch(err => {
66
- throw err;
67
- });
38
+ );
68
39
  }
69
- // Must provide scmOrganizations if not a Screwdriver cluster
70
- if (scmOrganizations && scmOrganizations.length === 0) {
40
+
41
+ // Must provide scmOrganizations if not a Screwdriver managed cluster
42
+ if (!managedByScrewdriver && scmOrganizations && scmOrganizations.length === 0) {
71
43
  return boom.badData(`No scmOrganizations provided for build cluster ${name}.`);
72
44
  }
73
45
 
@@ -75,7 +47,7 @@ module.exports = () => ({
75
47
  .list({
76
48
  params: {
77
49
  name,
78
- scmContext: payload.scmContext
50
+ scmContext: userContext
79
51
  }
80
52
  })
81
53
  .then(buildClusters => {
@@ -83,13 +55,12 @@ module.exports = () => ({
83
55
  throw boom.badData('Build cluster list returned non-array.');
84
56
  }
85
57
  if (buildClusters.length === 0) {
86
- throw boom.notFound(`Build cluster ${name} scmContext ${payload.scmContext} does not exist`);
58
+ throw boom.notFound(`Build cluster ${name}, scmContext ${userContext} does not exist`);
87
59
  }
88
- const buildCluster = buildClusters[0];
89
60
 
90
- Object.assign(buildCluster, payload);
61
+ Object.assign(buildClusters[0], request.payload);
91
62
 
92
- return buildCluster
63
+ return buildClusters[0]
93
64
  .update()
94
65
  .then(updatedBuildCluster => h.response(updatedBuildCluster.toJson()).code(200));
95
66
  })
@@ -92,7 +92,7 @@ module.exports = config => ({
92
92
  }),
93
93
  query: joi.object({
94
94
  type: typeSchema
95
- })
95
+ }).options({ allowUnknown: true })
96
96
  }
97
97
  }
98
98
  });