screwdriver-api 6.0.14 → 6.0.16
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
|
@@ -117,6 +117,20 @@ Deleting a template will delete a template and all of its associated tags and ve
|
|
|
117
117
|
|
|
118
118
|
* `name` - Name of the template
|
|
119
119
|
|
|
120
|
+
##### Delete a version
|
|
121
|
+
|
|
122
|
+
Delete the template version and all of its associated tags.
|
|
123
|
+
If the deleted version was the last published, the API would set the `latest` attribute of the previous version to `true`.
|
|
124
|
+
|
|
125
|
+
`DELETE /templates/{name}/versions/{version}`
|
|
126
|
+
|
|
127
|
+
###### Arguments
|
|
128
|
+
|
|
129
|
+
'name', 'version'
|
|
130
|
+
|
|
131
|
+
* `name` - Name of the template
|
|
132
|
+
* `version` - Version of the template
|
|
133
|
+
|
|
120
134
|
#### Template Tag
|
|
121
135
|
Template tag allows fetching on template version by tag. For example, tag `mytemplate@1.1.0` as `stable`.
|
|
122
136
|
|
|
@@ -10,6 +10,7 @@ const listVersionsRoute = require('./listVersions');
|
|
|
10
10
|
const listVersionsWithMetricsRouter = require('./listVersionsWithMetric');
|
|
11
11
|
const removeRoute = require('./remove');
|
|
12
12
|
const removeTagRoute = require('./removeTag');
|
|
13
|
+
const removeVersionRoute = require('./removeVersion');
|
|
13
14
|
const updateTrustedRoute = require('./updateTrusted');
|
|
14
15
|
const getTemplateByIdRoute = require('./getTemplateById');
|
|
15
16
|
|
|
@@ -84,6 +85,7 @@ const templatesPlugin = {
|
|
|
84
85
|
listVersionsWithMetricsRouter(),
|
|
85
86
|
removeRoute(),
|
|
86
87
|
removeTagRoute(),
|
|
88
|
+
removeVersionRoute(),
|
|
87
89
|
updateTrustedRoute(),
|
|
88
90
|
getTemplateByIdRoute()
|
|
89
91
|
]);
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const boom = require('@hapi/boom');
|
|
4
|
+
const joi = require('joi');
|
|
5
|
+
const schema = require('screwdriver-data-schema');
|
|
6
|
+
const nameSchema = schema.models.template.base.extract('name');
|
|
7
|
+
const exactVersionSchema = schema.config.template.exactVersion;
|
|
8
|
+
|
|
9
|
+
module.exports = () => ({
|
|
10
|
+
method: 'DELETE',
|
|
11
|
+
path: '/templates/{name}/versions/{version}',
|
|
12
|
+
options: {
|
|
13
|
+
description: 'Delete the specified version of template and the tags associated with it',
|
|
14
|
+
notes: 'Returns null if successful',
|
|
15
|
+
tags: ['api', 'templates'],
|
|
16
|
+
auth: {
|
|
17
|
+
strategies: ['token'],
|
|
18
|
+
scope: ['build', 'user', '!guest']
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
handler: async (request, h) => {
|
|
22
|
+
const { name, version } = request.params;
|
|
23
|
+
const { credentials } = request.auth;
|
|
24
|
+
const { templateFactory, templateTagFactory } = request.server.app;
|
|
25
|
+
const { canRemove } = request.server.plugins.templates;
|
|
26
|
+
let shouldUpdateLatest = false;
|
|
27
|
+
|
|
28
|
+
return Promise.all([
|
|
29
|
+
templateFactory.get({ name, version }),
|
|
30
|
+
templateTagFactory.list({ params: { name, version } })
|
|
31
|
+
])
|
|
32
|
+
.then(([template, tags]) => {
|
|
33
|
+
if (!template) {
|
|
34
|
+
throw boom.notFound(`Template ${name} with version ${version} does not exist`);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return canRemove(credentials, template, 'admin', request.server.app)
|
|
38
|
+
.then(() => {
|
|
39
|
+
shouldUpdateLatest = template.latest;
|
|
40
|
+
const removeTemplatePromise = template.remove();
|
|
41
|
+
const removeTagPromises = tags.map(tag => tag.remove());
|
|
42
|
+
|
|
43
|
+
return Promise.all([removeTemplatePromise, ...removeTagPromises]).then(() => {
|
|
44
|
+
if (shouldUpdateLatest) {
|
|
45
|
+
return templateFactory
|
|
46
|
+
.list({
|
|
47
|
+
params: { name },
|
|
48
|
+
sort: 'descending',
|
|
49
|
+
sortBy: 'createTime',
|
|
50
|
+
paginate: { count: 1 }
|
|
51
|
+
})
|
|
52
|
+
.then(templates => {
|
|
53
|
+
if (templates.length > 0) {
|
|
54
|
+
const newLatestTemplate = templates[0];
|
|
55
|
+
|
|
56
|
+
newLatestTemplate.latest = true;
|
|
57
|
+
|
|
58
|
+
return newLatestTemplate.update();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return Promise.resolve();
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return Promise.resolve();
|
|
66
|
+
});
|
|
67
|
+
})
|
|
68
|
+
.then(() => h.response().code(204));
|
|
69
|
+
})
|
|
70
|
+
.catch(err => {
|
|
71
|
+
throw err;
|
|
72
|
+
});
|
|
73
|
+
},
|
|
74
|
+
validate: {
|
|
75
|
+
params: joi.object({
|
|
76
|
+
name: nameSchema,
|
|
77
|
+
version: exactVersionSchema
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
});
|