screwdriver-api
Version:
API server for the Screwdriver.cd service
53 lines (44 loc) • 1.51 kB
JavaScript
;
const boom = require('@hapi/boom');
const joi = require('joi');
const schema = require('screwdriver-data-schema');
const baseSchema = schema.models.template.base;
module.exports = () => ({
method: 'PUT',
path: '/templates/{name}/trusted',
options: {
description: "Update a template's trusted property",
notes: 'Returns null if successful',
tags: ['api', 'templates', 'trusted'],
auth: {
strategies: ['token'],
scope: ['admin', '!guest']
},
handler: async (request, h) => {
const { name } = request.params;
const { templateFactory } = request.server.app;
const { trusted } = request.payload;
// get the earliest entry
const templates = await templateFactory.list({
params: { name, latest: true }
});
if (templates.length === 0) {
throw boom.notFound(`Template ${name} does not exist`);
}
const template = templates[0];
template.trusted = trusted;
return template.update().then(
() => h.response().code(204),
err => h.response(boom.boomify(err))
);
},
validate: {
params: joi.object({
name: baseSchema.extract('name')
}),
payload: joi.object({
trusted: baseSchema.extract('trusted')
})
}
}
});