screwdriver-api 7.0.253 → 7.0.254
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 +3 -1
- package/plugins/banners/README.md +18 -1
- package/plugins/banners/get.js +10 -0
- package/plugins/banners/list.js +13 -0
package/package.json
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "screwdriver-api",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.254",
|
|
4
4
|
"description": "API server for the Screwdriver.cd service",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"pretest": "eslint . --quiet",
|
|
8
8
|
"test": "nyc --report-dir ./artifacts/coverage --reporter=lcov mocha --reporter mocha-multi-reporters --reporter-options configFile=./mocha.config.json --recursive --timeout 10000 --retries 1 --exit --allow-uncaught true --color true",
|
|
9
9
|
"test-debug": "mocha --inspect-brk ./test/**/*.js",
|
|
10
|
+
"test-banner": "mocha ./test/**/banner.test.js",
|
|
10
11
|
"start": "./bin/server",
|
|
11
12
|
"debug": "node --nolazy ./bin/server",
|
|
12
13
|
"profile": "node --prof ./bin/server",
|
|
13
14
|
"functional": "cucumber-js --format=progress --tags '(not @ignore) and @prod' --retry 2 --fail-fast --exit",
|
|
15
|
+
"functional-banner": "cucumber-js --format=progress --tags '(not @ignore) and (not @prod) and @banner' --fail-fast --exit",
|
|
14
16
|
"functional-beta": "cucumber-js --format=progress --tags '(not @ignore) and (not @prod) and (not @x1) and (not @parallel)' --retry 2 --fail-fast --exit",
|
|
15
17
|
"functional-beta-parallel": "cucumber-js --format=progress --tags '(not @ignore) and (not @prod) and (not @x1) and @parallel' --retry 2 --fail-fast --exit --parallel 4",
|
|
16
18
|
"functional-beta-x1-parallel": "cucumber-js --format=progress --tags '(not @ignore) and (not @prod) and @x1 and @parallel' --retry 2 --fail-fast --exit --parallel 4",
|
|
@@ -36,20 +36,37 @@ server.register({
|
|
|
36
36
|
* `message` - Text of the banner to create.
|
|
37
37
|
* `type` - An optional banner type. Options are `info` and `warn`. Defaults to `info`
|
|
38
38
|
* `isActive` - An optional status flag to indicate whether banner should display. Defaults to `false`
|
|
39
|
+
* `scope` - An optional scope type that specifies whether the banner should be displayed globally or limited to the affected pipelines or builds. Accepted values are `GLOBAL`, `PIPELINE`, and `BUILD`, with `GLOBAL` as the default.
|
|
40
|
+
* `scopeId` - A required field when the scope is set to `PIPELINE` or `BUILD`, serving as a reference to the corresponding pipeline or build ID.
|
|
39
41
|
|
|
40
42
|
Example payload:
|
|
41
43
|
```json
|
|
42
44
|
{
|
|
43
45
|
"message": "The Screwdriver Team is currently investigating random failures.",
|
|
44
46
|
"type": "info",
|
|
45
|
-
"isActive": "true"
|
|
47
|
+
"isActive": "true",
|
|
48
|
+
"scope": "PIPELINE",
|
|
49
|
+
"scopeId": "12345"
|
|
46
50
|
}
|
|
47
51
|
```
|
|
48
52
|
|
|
49
53
|
#### Get a listing of all banners
|
|
50
54
|
|
|
55
|
+
Query Params:
|
|
56
|
+
|
|
57
|
+
* `scope` - *Optional* Returns banners for a specific scope
|
|
58
|
+
* `scopeId` - *Optional* Filters by a specific scope ID
|
|
59
|
+
* `createdBy` - *Optional* Filters banners created by a specific user
|
|
60
|
+
* `type` - *Optional* Filters by banner type
|
|
61
|
+
* `isActive` - *Optional* Accepts true or false to filter active or inactive banners
|
|
62
|
+
|
|
51
63
|
`GET /banners`
|
|
52
64
|
|
|
65
|
+
`GET /banners?scope=GLOBAL&isActive=true&type=info`
|
|
66
|
+
|
|
67
|
+
`GET /banners?scope=PIPELINE&scopeId=12345&isActive=true&type=info`
|
|
68
|
+
|
|
69
|
+
|
|
53
70
|
#### Get a specific banner
|
|
54
71
|
|
|
55
72
|
`GET /banners/{id}`
|
package/plugins/banners/get.js
CHANGED
|
@@ -18,6 +18,11 @@ module.exports = () => ({
|
|
|
18
18
|
enabled: false
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
|
+
auth: {
|
|
22
|
+
strategies: ['token'],
|
|
23
|
+
scope: ['user'],
|
|
24
|
+
mode: 'try' // This allows unauthenticated requests but still runs the auth check
|
|
25
|
+
},
|
|
21
26
|
handler: async (request, h) => {
|
|
22
27
|
const { bannerFactory } = request.server.app;
|
|
23
28
|
const { id } = request.params;
|
|
@@ -28,6 +33,11 @@ module.exports = () => ({
|
|
|
28
33
|
if (!banner) {
|
|
29
34
|
throw boom.notFound(`Banner ${id} does not exist`);
|
|
30
35
|
}
|
|
36
|
+
if (banner.scope !== 'GLOBAL') {
|
|
37
|
+
if (!request.auth.isAuthenticated) {
|
|
38
|
+
throw boom.unauthorized('Authentication required');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
31
41
|
|
|
32
42
|
return h.response(banner.toJson());
|
|
33
43
|
})
|
package/plugins/banners/list.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const schema = require('screwdriver-data-schema');
|
|
4
4
|
const listSchema = schema.models.banner.list;
|
|
5
|
+
const boom = require('@hapi/boom');
|
|
5
6
|
|
|
6
7
|
module.exports = () => ({
|
|
7
8
|
method: 'GET',
|
|
@@ -10,6 +11,11 @@ module.exports = () => ({
|
|
|
10
11
|
description: 'Get banners',
|
|
11
12
|
notes: 'Returns all banner records',
|
|
12
13
|
tags: ['api', 'banners'],
|
|
14
|
+
auth: {
|
|
15
|
+
strategies: ['token'],
|
|
16
|
+
scope: ['user'],
|
|
17
|
+
mode: 'try' // This allows unauthenticated requests but still runs the auth check
|
|
18
|
+
},
|
|
13
19
|
plugins: {
|
|
14
20
|
'hapi-rate-limit': {
|
|
15
21
|
enabled: false
|
|
@@ -17,6 +23,13 @@ module.exports = () => ({
|
|
|
17
23
|
},
|
|
18
24
|
handler: async (request, h) => {
|
|
19
25
|
const { bannerFactory } = request.server.app;
|
|
26
|
+
const { scope } = request.query;
|
|
27
|
+
|
|
28
|
+
if (scope !== 'GLOBAL') {
|
|
29
|
+
if (!request.auth.isAuthenticated) {
|
|
30
|
+
throw boom.unauthorized('Authentication required');
|
|
31
|
+
}
|
|
32
|
+
}
|
|
20
33
|
|
|
21
34
|
// list params defaults to empty object in models if undefined
|
|
22
35
|
return bannerFactory
|