screwdriver-api 7.0.165 → 7.0.167
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,4 +1,5 @@
|
|
|
1
1
|
# Commands Plugin
|
|
2
|
+
|
|
2
3
|
> Hapi commands plugin for the Screwdriver API
|
|
3
4
|
|
|
4
5
|
## Usage
|
|
@@ -12,17 +13,20 @@ const commandsPlugin = require('./');
|
|
|
12
13
|
|
|
13
14
|
server.connection({ port: 3000 });
|
|
14
15
|
|
|
15
|
-
server.register(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
16
|
+
server.register(
|
|
17
|
+
{
|
|
18
|
+
register: commandsPlugin,
|
|
19
|
+
options: {}
|
|
20
|
+
},
|
|
21
|
+
() => {
|
|
22
|
+
server.start(err => {
|
|
23
|
+
if (err) {
|
|
24
|
+
throw err;
|
|
25
|
+
}
|
|
26
|
+
console.log('Server running at:', server.info.uri);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
);
|
|
26
30
|
```
|
|
27
31
|
|
|
28
32
|
### Routes
|
|
@@ -61,10 +65,10 @@ You can get a single command by providing the command namespace, name and the sp
|
|
|
61
65
|
|
|
62
66
|
'namespace', 'name', 'tag' or 'version'
|
|
63
67
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
+
- `namespace` - Namespace of the command
|
|
69
|
+
- `name` - Name of the command
|
|
70
|
+
- `tag` - Tag of the command (e.g. `stable`, `latest`, etc)
|
|
71
|
+
- `version` - Version of the command
|
|
68
72
|
|
|
69
73
|
##### Create a command
|
|
70
74
|
|
|
@@ -72,7 +76,7 @@ Creating a command will store the command data (`namespace`, `name`, `version`,
|
|
|
72
76
|
|
|
73
77
|
`version` will be auto-bumped. For example, if `foo/bar@1.0.0` already exists and the version passed in is `1.0`, the newly created command will be version `1.0.1`.
|
|
74
78
|
|
|
75
|
-
|
|
79
|
+
_Note: This endpoint only accessible in `build` scope and the permission is tied to the pipeline that first creates the command._
|
|
76
80
|
|
|
77
81
|
`POST /commands`
|
|
78
82
|
|
|
@@ -80,51 +84,79 @@ Creating a command will store the command data (`namespace`, `name`, `version`,
|
|
|
80
84
|
|
|
81
85
|
'namespace', 'name', 'version', 'description', 'maintainer', 'format', commandFormat (`habitat` or `docker` or `binary`)
|
|
82
86
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
- `namespace` - Namespace of the command
|
|
88
|
+
- `name` - Name of the command
|
|
89
|
+
- `version` - Version of the command
|
|
90
|
+
- `description` - Description of the command
|
|
91
|
+
- `maintainer` - Maintainer of the command
|
|
92
|
+
- `format` - `habitat` or `docker` or `binary`
|
|
93
|
+
- `habitat` or `docker` or `binary` - Config of the command. This field is an object that includes properties of each command format.
|
|
90
94
|
|
|
91
95
|
Example payload:
|
|
96
|
+
|
|
92
97
|
```json
|
|
93
98
|
{
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
99
|
+
"namespace": "foo",
|
|
100
|
+
"name": "bar",
|
|
101
|
+
"version": "1.7",
|
|
102
|
+
"description": "this is a command",
|
|
103
|
+
"maintainer": "foo@bar.com",
|
|
104
|
+
"format": "habitat",
|
|
105
|
+
"habitat": {
|
|
106
|
+
"mode": "remote",
|
|
107
|
+
"package": "core/git/2.14.1",
|
|
108
|
+
"command": "git"
|
|
109
|
+
}
|
|
105
110
|
}
|
|
106
111
|
```
|
|
107
112
|
|
|
108
113
|
##### Delete a command
|
|
114
|
+
|
|
109
115
|
Deleting a command will delete a command and all of its associated tags and versions.
|
|
110
116
|
|
|
111
|
-
`DELETE /commands/{name}`
|
|
117
|
+
`DELETE /commands/{namespace}/{name}`
|
|
118
|
+
|
|
119
|
+
###### Arguments
|
|
120
|
+
|
|
121
|
+
- `namespace` - Namespace of the command
|
|
122
|
+
- `name` - Name of the command
|
|
123
|
+
|
|
124
|
+
##### Delete a version of a command
|
|
125
|
+
|
|
126
|
+
Deleting a specific version of a command also deletes the associated tags for that version.
|
|
127
|
+
|
|
128
|
+
`DELETE /commands/{namespace}/{name}/versions/{version}`
|
|
112
129
|
|
|
113
130
|
###### Arguments
|
|
114
131
|
|
|
115
|
-
|
|
132
|
+
- `namespace` - Namespace of the command
|
|
133
|
+
- `name` - Name of the command
|
|
134
|
+
- `version` - Version of the command
|
|
116
135
|
|
|
117
136
|
#### Command Tag
|
|
137
|
+
|
|
118
138
|
Command Tag allows fetching on command version by tag. For example, command `mynamespace/mycommand@1.2.0` as `stable`.
|
|
119
139
|
|
|
120
140
|
##### Create/Update a tag
|
|
121
141
|
|
|
122
142
|
If the command tag already exists, it will update the tag with the version. If the command tag doesn't exist yet, this endpoint will create the tag.
|
|
123
143
|
|
|
124
|
-
You can also call this endpoint with tag instead of the exact version. In this case, same version will have two tags.
|
|
144
|
+
You can also call this endpoint with tag instead of the exact version. In this case, same version will have two tags. (e.g. version 1.0.0 tagged with both latest and stable)
|
|
125
145
|
|
|
126
|
-
|
|
146
|
+
_Note: This endpoint is only accessible in `build` scope and the permission is tied to the pipeline that creates the command._
|
|
127
147
|
|
|
128
148
|
`PUT /commands/{namespace}/{name}/tags/{tagName}` with the following payload
|
|
129
149
|
|
|
130
|
-
|
|
150
|
+
- `version` - Exact version or tag of the command (ex: `1.1.0`, `latest`)
|
|
151
|
+
|
|
152
|
+
##### Delete a tag
|
|
153
|
+
|
|
154
|
+
Delete a specific tag of a command.
|
|
155
|
+
|
|
156
|
+
`DELETE /commands/{namespace}/{name}/tags/{tagName}`
|
|
157
|
+
|
|
158
|
+
###### Arguments
|
|
159
|
+
|
|
160
|
+
- `namespace` - Namespace of the command
|
|
161
|
+
- `name` - Name of the command
|
|
162
|
+
- `tagName` - Tag of the command (e.g. `stable`, `latest`, etc)
|
|
@@ -7,6 +7,7 @@ const getRoute = require('./get');
|
|
|
7
7
|
const listRoute = require('./list');
|
|
8
8
|
const removeRoute = require('./remove');
|
|
9
9
|
const removeTagRoute = require('./removeTag');
|
|
10
|
+
const removeVersionRoute = require('./removeVersion');
|
|
10
11
|
const listTagsRoute = require('./listTags');
|
|
11
12
|
const listVersionsRoute = require('./listVersions');
|
|
12
13
|
const updateTrustedRoute = require('./updateTrusted');
|
|
@@ -80,6 +81,7 @@ const commandsPlugin = {
|
|
|
80
81
|
getRoute(),
|
|
81
82
|
removeRoute(),
|
|
82
83
|
removeTagRoute(),
|
|
84
|
+
removeVersionRoute(),
|
|
83
85
|
listRoute(),
|
|
84
86
|
listVersionsRoute(),
|
|
85
87
|
listTagsRoute(),
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const boom = require('@hapi/boom');
|
|
4
|
+
const joi = require('joi');
|
|
5
|
+
const schema = require('screwdriver-data-schema');
|
|
6
|
+
const commandBaseSchema = schema.models.command.base;
|
|
7
|
+
|
|
8
|
+
module.exports = () => ({
|
|
9
|
+
method: 'DELETE',
|
|
10
|
+
path: '/commands/{namespace}/{name}/versions/{version}',
|
|
11
|
+
options: {
|
|
12
|
+
description: 'Delete the specified version of commands and the tags associated with it',
|
|
13
|
+
notes: 'Returns null if successful',
|
|
14
|
+
tags: ['api', 'commands'],
|
|
15
|
+
auth: {
|
|
16
|
+
strategies: ['token'],
|
|
17
|
+
scope: ['build', 'user', '!guest']
|
|
18
|
+
},
|
|
19
|
+
handler: async (request, h) => {
|
|
20
|
+
const { namespace, name, version } = request.params;
|
|
21
|
+
const { credentials } = request.auth;
|
|
22
|
+
const { commandFactory, commandTagFactory } = request.server.app;
|
|
23
|
+
const { canRemove } = request.server.plugins.commands;
|
|
24
|
+
|
|
25
|
+
return Promise.all([
|
|
26
|
+
commandFactory.get({ namespace, name, version }),
|
|
27
|
+
commandTagFactory.list({ params: { namespace, name, version } })
|
|
28
|
+
])
|
|
29
|
+
.then(async ([command, tags]) => {
|
|
30
|
+
if (!command) {
|
|
31
|
+
throw boom.notFound(
|
|
32
|
+
`Command ${name} with version ${version} in namespace ${namespace} does not exist`
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
await canRemove(credentials, command, 'admin', request.server.app);
|
|
37
|
+
|
|
38
|
+
const promises = command.remove();
|
|
39
|
+
const tagPromises = tags.map(tag => tag.remove());
|
|
40
|
+
|
|
41
|
+
await Promise.all([promises, ...tagPromises]);
|
|
42
|
+
|
|
43
|
+
return h.response().code(204);
|
|
44
|
+
})
|
|
45
|
+
.catch(err => {
|
|
46
|
+
throw err;
|
|
47
|
+
});
|
|
48
|
+
},
|
|
49
|
+
validate: {
|
|
50
|
+
params: joi.object({
|
|
51
|
+
name: commandBaseSchema.extract('name'),
|
|
52
|
+
namespace: commandBaseSchema.extract('namespace'),
|
|
53
|
+
version: commandBaseSchema.extract('version')
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|