screwdriver-api 5.0.0 → 5.0.2
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/bin/server +4 -0
- package/config/custom-environment-variables.yaml +10 -0
- package/config/default.yaml +7 -0
- package/lib/server.js +28 -0
- package/package.json +13 -13
- package/plugins/logging.js +6 -1
- package/plugins/pipelines/README.md +4 -0
- package/plugins/pipelines/list.js +36 -19
package/bin/server
CHANGED
|
@@ -44,6 +44,9 @@ ecosystem.api = httpdConfig.uri;
|
|
|
44
44
|
|
|
45
45
|
const release = config.get('release');
|
|
46
46
|
|
|
47
|
+
// Logging config
|
|
48
|
+
const log = config.get('log');
|
|
49
|
+
|
|
47
50
|
// Notification config
|
|
48
51
|
const notificationConfig = config.get('notifications');
|
|
49
52
|
|
|
@@ -261,6 +264,7 @@ datastore.setup(datastoreConfig.ddlSyncEnabled).then(() =>
|
|
|
261
264
|
scm
|
|
262
265
|
},
|
|
263
266
|
release,
|
|
267
|
+
log,
|
|
264
268
|
validator: {
|
|
265
269
|
externalJoin: true,
|
|
266
270
|
notificationsValidationErr
|
|
@@ -468,6 +468,16 @@ release:
|
|
|
468
468
|
__name: RELEASE_ENVIRONMENT_VARIABLES
|
|
469
469
|
__format: json
|
|
470
470
|
|
|
471
|
+
# Logging preferences
|
|
472
|
+
log:
|
|
473
|
+
audit:
|
|
474
|
+
# set true to enable audit logs for all API calls
|
|
475
|
+
enabled: LOG_AUDIT_ENABLED
|
|
476
|
+
# add target scope tokens(pipeline, build, temporal, admin, guest, user)
|
|
477
|
+
scope:
|
|
478
|
+
__name: LOG_AUDIT_SCOPE
|
|
479
|
+
__format: json
|
|
480
|
+
|
|
471
481
|
build:
|
|
472
482
|
environment:
|
|
473
483
|
__name: CLUSTER_ENVIRONMENT_VARIABLES
|
package/config/default.yaml
CHANGED
|
@@ -339,6 +339,13 @@ release:
|
|
|
339
339
|
headerName: release
|
|
340
340
|
headerValue: stable
|
|
341
341
|
|
|
342
|
+
# Logging preferences
|
|
343
|
+
log:
|
|
344
|
+
audit:
|
|
345
|
+
# set true to enable audit logs for all API calls
|
|
346
|
+
enabled: false
|
|
347
|
+
# add target scope tokens(pipeline, build, temporal, admin, guest, user)
|
|
348
|
+
scope: []
|
|
342
349
|
|
|
343
350
|
# default cluster environment variables to inject into builds
|
|
344
351
|
build:
|
package/lib/server.js
CHANGED
|
@@ -160,6 +160,34 @@ module.exports = async config => {
|
|
|
160
160
|
// Write prettier errors
|
|
161
161
|
server.ext('onPreResponse', prettyPrintErrors);
|
|
162
162
|
|
|
163
|
+
// Audit log
|
|
164
|
+
if (config.log && config.log.audit.enabled) {
|
|
165
|
+
server.ext('onCredentials', (request, h) => {
|
|
166
|
+
const { username, scope, pipelineId } = request.auth.credentials;
|
|
167
|
+
const validScope = config.log.audit.scope.filter(s => scope.includes(s));
|
|
168
|
+
|
|
169
|
+
if (Array.isArray(validScope) && validScope.length > 0) {
|
|
170
|
+
let context;
|
|
171
|
+
|
|
172
|
+
if (validScope.includes('admin')) {
|
|
173
|
+
context = `Admin ${username}`;
|
|
174
|
+
} else if (validScope.includes('user')) {
|
|
175
|
+
context = `User ${username}`;
|
|
176
|
+
} else if (validScope.includes('build') || validScope.includes('temporal')) {
|
|
177
|
+
context = `Build ${username}`;
|
|
178
|
+
} else if (validScope.includes('pipeline')) {
|
|
179
|
+
context = `Pipeline ${pipelineId}`;
|
|
180
|
+
} else {
|
|
181
|
+
context = `Guest ${username}`;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
logger.info(`[Login] ${context} ${request.method} ${request.path}`);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return h.continue;
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
|
|
163
191
|
// Register events for notifications plugin
|
|
164
192
|
server.event(['build_status', 'job_status']);
|
|
165
193
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "screwdriver-api",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.2",
|
|
4
4
|
"description": "API server for the Screwdriver.cd service",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -83,13 +83,13 @@
|
|
|
83
83
|
"badge-maker": "^3.3.1",
|
|
84
84
|
"config": "^1.31.0",
|
|
85
85
|
"date-fns": "^1.30.1",
|
|
86
|
-
"dayjs": "^1.11.
|
|
86
|
+
"dayjs": "^1.11.6",
|
|
87
87
|
"hapi-auth-bearer-token": "^8.0.0",
|
|
88
88
|
"hapi-auth-jwt2": "^10.2.0",
|
|
89
89
|
"hapi-rate-limit": "^5.0.1",
|
|
90
90
|
"hapi-swagger": "^14.5.5",
|
|
91
91
|
"ioredis": "^5.2.3",
|
|
92
|
-
"joi": "^17.
|
|
92
|
+
"joi": "^17.7.0",
|
|
93
93
|
"js-yaml": "^3.14.1",
|
|
94
94
|
"jsonwebtoken": "^8.5.1",
|
|
95
95
|
"license-checker": "^17.0.0",
|
|
@@ -98,14 +98,14 @@
|
|
|
98
98
|
"node-env-file": "^0.1.8",
|
|
99
99
|
"prom-client": "^12.0.0",
|
|
100
100
|
"redlock": "^4.1.0",
|
|
101
|
-
"screwdriver-artifact-bookend": "^1.
|
|
101
|
+
"screwdriver-artifact-bookend": "^1.4.0",
|
|
102
102
|
"screwdriver-build-bookend": "^3.0.0",
|
|
103
|
-
"screwdriver-cache-bookend": "^2.0
|
|
103
|
+
"screwdriver-cache-bookend": "^2.1.0",
|
|
104
104
|
"screwdriver-command-validator": "^2.1.0",
|
|
105
|
-
"screwdriver-config-parser": "^7.6.
|
|
106
|
-
"screwdriver-coverage-bookend": "^1.0
|
|
107
|
-
"screwdriver-coverage-sonar": "^3.4.
|
|
108
|
-
"screwdriver-data-schema": "^21.28.
|
|
105
|
+
"screwdriver-config-parser": "^7.6.1",
|
|
106
|
+
"screwdriver-coverage-bookend": "^1.1.0",
|
|
107
|
+
"screwdriver-coverage-sonar": "^3.4.1",
|
|
108
|
+
"screwdriver-data-schema": "^21.28.4",
|
|
109
109
|
"screwdriver-datastore-sequelize": "^7.2.7",
|
|
110
110
|
"screwdriver-executor-base": "^8.4.0",
|
|
111
111
|
"screwdriver-executor-docker": "^5.0.1",
|
|
@@ -113,19 +113,19 @@
|
|
|
113
113
|
"screwdriver-executor-k8s-vm": "^4.3.2",
|
|
114
114
|
"screwdriver-executor-queue": "^3.1.2",
|
|
115
115
|
"screwdriver-executor-router": "^2.3.0",
|
|
116
|
-
"screwdriver-logger": "^1.
|
|
117
|
-
"screwdriver-models": "^28.
|
|
116
|
+
"screwdriver-logger": "^1.2.0",
|
|
117
|
+
"screwdriver-models": "^28.20.0",
|
|
118
118
|
"screwdriver-notifications-email": "^2.3.1",
|
|
119
119
|
"screwdriver-notifications-slack": "^3.3.0",
|
|
120
120
|
"screwdriver-request": "^1.0.3",
|
|
121
121
|
"screwdriver-scm-base": "^7.3.0",
|
|
122
122
|
"screwdriver-scm-bitbucket": "^4.5.1",
|
|
123
|
-
"screwdriver-scm-github": "^11.10.
|
|
123
|
+
"screwdriver-scm-github": "^11.10.3",
|
|
124
124
|
"screwdriver-scm-gitlab": "^2.10.0",
|
|
125
125
|
"screwdriver-scm-router": "^6.3.0",
|
|
126
126
|
"screwdriver-template-validator": "^5.2.0",
|
|
127
127
|
"screwdriver-workflow-parser": "^3.2.1",
|
|
128
|
-
"sqlite3": "^5.
|
|
128
|
+
"sqlite3": "^5.1.2",
|
|
129
129
|
"stream": "0.0.2",
|
|
130
130
|
"tinytim": "^0.1.1",
|
|
131
131
|
"uuid": "^8.3.2",
|
package/plugins/logging.js
CHANGED
|
@@ -33,6 +33,10 @@ server.register({
|
|
|
33
33
|
|
|
34
34
|
`GET /pipelines?page={pageNumber}&count={countNumber}&configPipelineId={configPipelineId}&search={search}`
|
|
35
35
|
|
|
36
|
+
Need to have array format for `ids` to only return pipelines with matching ids
|
|
37
|
+
`GET /pipelines?search={search}&ids[]=12345&ids[]=55555`
|
|
38
|
+
|
|
39
|
+
|
|
36
40
|
#### Get single pipeline
|
|
37
41
|
|
|
38
42
|
`GET /pipelines/{id}`
|
|
@@ -7,6 +7,11 @@ const listSchema = joi
|
|
|
7
7
|
.array()
|
|
8
8
|
.items(schema.models.pipeline.get)
|
|
9
9
|
.label('List of Pipelines');
|
|
10
|
+
const pipelineIdsSchema = joi
|
|
11
|
+
.alternatives()
|
|
12
|
+
.try(joi.array().items(idSchema), idSchema)
|
|
13
|
+
.required();
|
|
14
|
+
const IDS_KEY = 'ids[]';
|
|
10
15
|
|
|
11
16
|
module.exports = () => ({
|
|
12
17
|
method: 'GET',
|
|
@@ -21,30 +26,40 @@ module.exports = () => ({
|
|
|
21
26
|
},
|
|
22
27
|
|
|
23
28
|
handler: async (request, h) => {
|
|
24
|
-
const
|
|
25
|
-
const
|
|
29
|
+
const { pipelineFactory } = request.server.app;
|
|
30
|
+
const { sort, configPipelineId, sortBy, search, page, count } = request.query;
|
|
31
|
+
const scmContexts = pipelineFactory.scm.getScmContexts();
|
|
26
32
|
let pipelineArray = [];
|
|
27
33
|
|
|
28
34
|
scmContexts.forEach(scmContext => {
|
|
29
35
|
const config = {
|
|
30
36
|
params: { scmContext },
|
|
31
|
-
sort
|
|
37
|
+
sort
|
|
32
38
|
};
|
|
33
39
|
|
|
34
|
-
|
|
35
|
-
|
|
40
|
+
// Only return specific pipelines
|
|
41
|
+
if (request.query[IDS_KEY]) {
|
|
42
|
+
const ids = request.query[IDS_KEY];
|
|
43
|
+
|
|
44
|
+
config.params.id = Array.isArray(ids)
|
|
45
|
+
? ids.map(pipelineId => parseInt(pipelineId, 10))
|
|
46
|
+
: [parseInt(ids, 10)];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (configPipelineId) {
|
|
50
|
+
config.params.configPipelineId = configPipelineId;
|
|
36
51
|
}
|
|
37
52
|
|
|
38
|
-
if (
|
|
39
|
-
config.sortBy =
|
|
53
|
+
if (sortBy) {
|
|
54
|
+
config.sortBy = sortBy;
|
|
40
55
|
}
|
|
41
56
|
|
|
42
|
-
if (
|
|
57
|
+
if (search) {
|
|
43
58
|
config.search = {
|
|
44
59
|
field: 'name',
|
|
45
60
|
// Do a fuzzy search for name: screwdriver-cd/ui
|
|
46
61
|
// See https://www.w3schools.com/sql/sql_like.asp for syntax
|
|
47
|
-
keyword: `%${
|
|
62
|
+
keyword: `%${search}%`
|
|
48
63
|
};
|
|
49
64
|
} else {
|
|
50
65
|
// default list all to 50 max count, according to schema.api.pagination
|
|
@@ -54,17 +69,17 @@ module.exports = () => ({
|
|
|
54
69
|
};
|
|
55
70
|
}
|
|
56
71
|
|
|
57
|
-
if (
|
|
72
|
+
if (page) {
|
|
58
73
|
config.paginate = config.paginate || {};
|
|
59
|
-
config.paginate.page =
|
|
74
|
+
config.paginate.page = page;
|
|
60
75
|
}
|
|
61
76
|
|
|
62
|
-
if (
|
|
77
|
+
if (count) {
|
|
63
78
|
config.paginate = config.paginate || {};
|
|
64
|
-
config.paginate.count =
|
|
79
|
+
config.paginate.count = count;
|
|
65
80
|
}
|
|
66
81
|
|
|
67
|
-
const pipelines =
|
|
82
|
+
const pipelines = pipelineFactory.list(config);
|
|
68
83
|
|
|
69
84
|
pipelineArray = pipelineArray.concat(pipelines);
|
|
70
85
|
});
|
|
@@ -76,7 +91,7 @@ module.exports = () => ({
|
|
|
76
91
|
let adminDetails;
|
|
77
92
|
|
|
78
93
|
if (scmContext) {
|
|
79
|
-
const scmDisplayName =
|
|
94
|
+
const scmDisplayName = pipelineFactory.scm.getDisplayName({ scmContext });
|
|
80
95
|
|
|
81
96
|
adminDetails = request.server.plugins.banners.screwdriverAdminDetails(username, scmDisplayName);
|
|
82
97
|
}
|
|
@@ -86,10 +101,11 @@ module.exports = () => ({
|
|
|
86
101
|
}
|
|
87
102
|
|
|
88
103
|
return allPipelines.filter(pipeline => {
|
|
89
|
-
const
|
|
90
|
-
const
|
|
104
|
+
const { settings, scmRepo, admins } = pipeline;
|
|
105
|
+
const setToPublic = settings && settings.public;
|
|
106
|
+
const privatePipeline = scmRepo && scmRepo.private;
|
|
91
107
|
|
|
92
|
-
return !privatePipeline || setToPublic ||
|
|
108
|
+
return !privatePipeline || setToPublic || admins[username];
|
|
93
109
|
});
|
|
94
110
|
})
|
|
95
111
|
.then(allPipelines => h.response(allPipelines.map(p => p.toJson())))
|
|
@@ -103,7 +119,8 @@ module.exports = () => ({
|
|
|
103
119
|
validate: {
|
|
104
120
|
query: schema.api.pagination.concat(
|
|
105
121
|
joi.object({
|
|
106
|
-
configPipelineId: idSchema
|
|
122
|
+
configPipelineId: idSchema,
|
|
123
|
+
'ids[]': pipelineIdsSchema.optional()
|
|
107
124
|
})
|
|
108
125
|
)
|
|
109
126
|
}
|