screwdriver-api
Version:
API server for the Screwdriver.cd service
47 lines (41 loc) • 1.35 kB
JavaScript
;
const boom = require('@hapi/boom');
const joi = require('joi');
const schema = require('screwdriver-data-schema');
const getSchema = schema.models.pipeline.get;
const idSchema = schema.models.pipeline.base.extract('id');
module.exports = () => ({
method: 'GET',
path: '/pipelines/{id}',
options: {
description: 'Get a single pipeline',
notes: 'Returns a pipeline record',
tags: ['api', 'pipelines'],
auth: {
strategies: ['token'],
scope: ['user', 'build', 'pipeline']
},
handler: async (request, h) => {
const { canAccessPipeline } = request.server.plugins.pipelines;
const { credentials } = request.auth;
return canAccessPipeline(credentials, request.params.id, 'pull', request.server.app)
.then(pipeline => {
if (!pipeline) {
throw boom.notFound('Pipeline does not exist');
}
return h.response(pipeline.toJson());
})
.catch(err => {
throw err;
});
},
response: {
schema: getSchema
},
validate: {
params: joi.object({
id: idSchema
})
}
}
});