screwdriver-api 6.0.24 → 6.0.26

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.24",
3
+ "version": "6.0.26",
4
4
  "description": "API server for the Screwdriver.cd service",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -114,14 +114,14 @@
114
114
  "screwdriver-executor-queue": "^4.0.0",
115
115
  "screwdriver-executor-router": "^3.0.0",
116
116
  "screwdriver-logger": "^2.0.0",
117
- "screwdriver-models": "^29.3.0",
117
+ "screwdriver-models": "^29.6.0",
118
118
  "screwdriver-notifications-email": "^3.0.0",
119
119
  "screwdriver-notifications-slack": "^4.0.0",
120
120
  "screwdriver-request": "^2.0.1",
121
- "screwdriver-scm-base": "^8.0.0",
121
+ "screwdriver-scm-base": "^8.1.0",
122
122
  "screwdriver-scm-bitbucket": "^5.0.1",
123
- "screwdriver-scm-github": "^12.0.0",
124
- "screwdriver-scm-gitlab": "^3.0.0",
123
+ "screwdriver-scm-github": "^12.1.1",
124
+ "screwdriver-scm-gitlab": "^3.1.0",
125
125
  "screwdriver-scm-router": "^7.0.0",
126
126
  "screwdriver-template-validator": "^6.0.0",
127
127
  "screwdriver-workflow-parser": "^4.0.0",
@@ -17,8 +17,7 @@ module.exports = () => ({
17
17
  },
18
18
 
19
19
  handler: async (request, h) => {
20
- const { buildClusterFactory, bannerFactory, userFactory } = request.server.app;
21
- const { scm } = buildClusterFactory;
20
+ const { buildClusterFactory, bannerFactory } = request.server.app;
22
21
  const { username, scmContext: userContext } = request.auth.credentials;
23
22
  const { payload } = request;
24
23
  const { managedByScrewdriver, name, scmOrganizations } = payload;
@@ -63,34 +62,9 @@ module.exports = () => ({
63
62
  return boom.badData(`No scmOrganizations provided for build cluster ${name}.`);
64
63
  }
65
64
 
66
- // Must have admin permission on org(s) if adding org-specific build cluster
67
65
  return (
68
- userFactory
69
- .get({ username, scmContext: userContext })
70
- .then(user => user.unsealToken())
71
- .then(token =>
72
- Promise.all(
73
- scmOrganizations.map(organization =>
74
- scm
75
- .getOrgPermissions({
76
- organization,
77
- username,
78
- token,
79
- scmContext: payload.scmContext
80
- })
81
- .then(permissions => {
82
- if (!permissions.admin) {
83
- throw boom.forbidden(
84
- `User ${username} does not have
85
- administrative privileges on scm
86
- organization ${organization}.`
87
- );
88
- }
89
- })
90
- )
91
- )
92
- )
93
- .then(() => buildClusterFactory.create(payload))
66
+ buildClusterFactory
67
+ .create(payload)
94
68
  .then(buildCluster => {
95
69
  // everything succeeded, inform the user
96
70
  const location = urlLib.format({
@@ -18,8 +18,7 @@ module.exports = () => ({
18
18
  },
19
19
 
20
20
  handler: async (request, h) => {
21
- const { buildClusterFactory, bannerFactory, userFactory } = request.server.app;
22
- const { scm } = buildClusterFactory;
21
+ const { buildClusterFactory, bannerFactory } = request.server.app;
23
22
  const { name } = request.params; // name of build cluster to update
24
23
  const { username, scmContext: userContext } = request.auth.credentials;
25
24
  const { payload } = request;
@@ -72,62 +71,28 @@ module.exports = () => ({
72
71
  return boom.badData(`No scmOrganizations provided for build cluster ${name}.`);
73
72
  }
74
73
 
75
- // Must have admin permission on org(s) if updating org-specific build cluster
76
- return userFactory
77
- .get({ username, scmContext: userContext })
78
- .then(user =>
79
- Promise.all([
80
- user.unsealToken(),
81
- buildClusterFactory.list({
82
- params: {
83
- name,
84
- scmContext: payload.scmContext
85
- }
86
- })
87
- ]).then(([token, buildClusters]) => {
88
- if (!Array.isArray(buildClusters)) {
89
- throw boom.badData('Build cluster list returned non-array.');
90
- }
91
- if (buildClusters.length === 0) {
92
- throw boom.notFound(
93
- `Build cluster ${name} scmContext ${payload.scmContext} does not exist`
94
- );
95
- }
74
+ return buildClusterFactory
75
+ .list({
76
+ params: {
77
+ name,
78
+ scmContext: payload.scmContext
79
+ }
80
+ })
81
+ .then(buildClusters => {
82
+ if (!Array.isArray(buildClusters)) {
83
+ throw boom.badData('Build cluster list returned non-array.');
84
+ }
85
+ if (buildClusters.length === 0) {
86
+ throw boom.notFound(`Build cluster ${name} scmContext ${payload.scmContext} does not exist`);
87
+ }
88
+ const buildCluster = buildClusters[0];
96
89
 
97
- // To update scmOrganizations, user need to have admin permissions on both old and new organizations
98
- const buildCluster = buildClusters[0];
99
- const orgs = buildCluster.scmOrganizations;
100
- const newOrgs = scmOrganizations || [];
101
- const combined = [...new Set([...orgs, ...newOrgs])];
90
+ Object.assign(buildCluster, payload);
102
91
 
103
- return Promise.all(
104
- combined.map(organization =>
105
- scm
106
- .getOrgPermissions({
107
- organization,
108
- username,
109
- token,
110
- scmContext: payload.scmContext
111
- })
112
- .then(permissions => {
113
- if (!permissions.admin) {
114
- throw boom.forbidden(
115
- `User ${username} does not have
116
- administrative privileges on scm
117
- organization ${organization}.`
118
- );
119
- }
120
- })
121
- )
122
- ).then(() => {
123
- Object.assign(buildCluster, payload);
124
-
125
- return buildCluster
126
- .update()
127
- .then(updatedBuildCluster => h.response(updatedBuildCluster.toJson()).code(200));
128
- });
129
- })
130
- )
92
+ return buildCluster
93
+ .update()
94
+ .then(updatedBuildCluster => h.response(updatedBuildCluster.toJson()).code(200));
95
+ })
131
96
  .catch(err => {
132
97
  throw err;
133
98
  });