How to use screwdriver-data-schema - 10 common examples

To help you get started, we’ve selected a few screwdriver-data-schema examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github screwdriver-cd / screwdriver / plugins / pipelines / helper.js View on Github external
const formatCheckoutUrl = (checkoutUrl) => {
    let result = checkoutUrl;
    const MATCH_COMPONENT_BRANCH_NAME = 4;
    const matched = (schema.config.regex.CHECKOUT_URL).exec(result);
    let branchName = matched[MATCH_COMPONENT_BRANCH_NAME];

    // Check if branch name exists
    if (!branchName) {
        branchName = '#master';
    }

    // Do not convert branch name to lowercase
    result = result.split('#')[0].toLowerCase().concat(branchName);

    return result;
};
github screwdriver-cd / screwdriver / plugins / events / create.js View on Github external
payload.creator = creator;
                }

                // Trigger "~pr" needs to have PR number given
                // Note: To kick start builds for all jobs under a PR,
                // you need both the prNum and the trigger "~pr" as startFrom
                if (startFrom.match(validationSchema.config.regex.PR_TRIGGER) && !prNum) {
                    throw boom.badRequest('Trigger "~pr" must be accompanied by a PR number');
                }

                if (!prNum) {
                    // If PR number isn't given, induce it from "startFrom"
                    // Match PR-prNum, then extract prNum
                    // e.g. if startFrom is "PR-1:main", prNumFullName will be "PR-1"; prNum will be "1"
                    const prNumFullName = startFrom.match(
                        validationSchema.config.regex.PR_JOB_NAME
                    );

                    prNum = prNumFullName ? prNumFullName[1].split('-')[1] : null;
                }

                // Fetch the job and user models
                return Promise.all([
                    pipelineFactory.get(pipelineId),
                    userFactory.get({ username, scmContext })
                ]).then(([pipeline, user]) => {
                    // In pipeline scope, check if the token is allowed to the pipeline
                    if (!isValidToken(pipeline.id, request.auth.credentials)) {
                        throw boom.unauthorized('Token does not have permission to this pipeline');
                    }

                    let scmConfig;
github screwdriver-cd / screwdriver / plugins / events / create.js View on Github external
if (meta) {
                    payload.meta = meta;
                }

                if (causeMessage) {
                    payload.causeMessage = causeMessage;
                }

                if (creator) {
                    payload.creator = creator;
                }

                // Trigger "~pr" needs to have PR number given
                // Note: To kick start builds for all jobs under a PR,
                // you need both the prNum and the trigger "~pr" as startFrom
                if (startFrom.match(validationSchema.config.regex.PR_TRIGGER) && !prNum) {
                    throw boom.badRequest('Trigger "~pr" must be accompanied by a PR number');
                }

                if (!prNum) {
                    // If PR number isn't given, induce it from "startFrom"
                    // Match PR-prNum, then extract prNum
                    // e.g. if startFrom is "PR-1:main", prNumFullName will be "PR-1"; prNum will be "1"
                    const prNumFullName = startFrom.match(
                        validationSchema.config.regex.PR_JOB_NAME
                    );

                    prNum = prNumFullName ? prNumFullName[1].split('-')[1] : null;
                }

                // Fetch the job and user models
                return Promise.all([
github screwdriver-cd / screwdriver / plugins / templates / removeTag.js View on Github external
'use strict';

const boom = require('boom');
const joi = require('joi');
const schema = require('screwdriver-data-schema');
const baseSchema = schema.models.templateTag.base;

/* Currently, only build scope is allowed to tag template due to security reasons.
 * The same pipeline that publishes the template has the permission to tag it.
 */
module.exports = () => ({
    method: 'DELETE',
    path: '/templates/{templateName}/tags/{tagName}',
    config: {
        description: 'Delete a template tag',
        notes: 'Delete a specific template',
        tags: ['api', 'templates'],
        auth: {
            strategies: ['token'],
            scope: ['build']
        },
        plugins: {
github screwdriver-cd / screwdriver / plugins / tokens / create.js View on Github external
})
                .then((token) => {
                    const location = urlLib.format({
                        host: request.headers.host,
                        port: request.headers.port,
                        protocol: request.server.info.protocol,
                        pathname: `${request.path}/${token.id}`
                    });

                    return reply(token.toJson()).header('Location', location).code(201);
                })
                // something broke, respond with error
                .catch(err => reply(boom.boomify(err)));
        },
        validate: {
            payload: schema.models.token.create
        }
    }
});
github screwdriver-cd / screwdriver / plugins / status.js View on Github external
exports.register = (server, options, next) => {
    // Add the status route
    server.route({
        method: 'GET',
        path: '/status',
        handler: (request, reply) => reply('OK'),
        config: {
            description: 'API status',
            notes: 'Should respond with 200: ok',
            tags: ['api'],
            response: {
                schema: schema.api.status
            }
        }
    });
    next();
};
github screwdriver-cd / screwdriver / plugins / commands / create.js View on Github external
/* eslint no-underscore-dangle: ["error", { "allow": ["_data", "_shot"] }] */

'use strict';

const boom = require('boom');
const schema = require('screwdriver-data-schema');
const validator = require('screwdriver-command-validator');
const hoek = require('hoek');
const urlLib = require('url');
const req = require('request');
const VERSION_REGEX = schema.config.regex.VERSION;
const DEFAULT_BYTES = 1024 * 1024 * 1024; // 1GB

/**
 * Publish file to the store
 * @method publishFileToStore
 * @param  {CommandFactory} commandFactory      commandFactory
 * @param  {Object}         config              Command config
 * @param  {Uint8Array}     file                File published to the store
 * @param  {String}         storeUrl            URL to the store
 * @param  {String}         authToken           Bearer Token to be passed to the store
 * @return {Promise}
 */
function publishFileToStore(commandFactory, config, file, storeUrl, authToken) {
    const [, major, minor] = VERSION_REGEX.exec(config.version);
    const searchVersion = minor ? `${major}${minor}` : major;
    let publishVersion;
github screwdriver-cd / screwdriver / plugins / commands / createTag.js View on Github external
'use strict';

const boom = require('boom');
const joi = require('joi');
const schema = require('screwdriver-data-schema');
const baseSchema = schema.models.commandTag.base;
const urlLib = require('url');
const VERSION_REGEX = schema.config.regex.VERSION;
const exactVersionSchema = joi.reach(schema.models.commandTag.base, 'version');
const tagSchema = joi.reach(schema.models.commandTag.base, 'tag');

/* Currently, only build scope is allowed to tag command due to security reasons.
 * The same pipeline that publishes the command has the permission to tag it.
 */
module.exports = () => ({
    method: 'PUT',
    path: '/commands/{namespace}/{name}/tags/{tagName}',
    config: {
        description: 'Add or update a command tag',
        notes: 'Add or update a specific command',
        tags: ['api', 'commands'],
        auth: {
            strategies: ['token'],
            scope: ['build', '!guest']
github screwdriver-cd / screwdriver / plugins / pipelines / jobBadge.js View on Github external
'use strict';

const joi = require('joi');
const schema = require('screwdriver-data-schema');
const tinytim = require('tinytim');
const idSchema = joi.reach(schema.models.pipeline.base, 'id');

/**
 * Generate Badge URL
 * @method getUrl
 * @param  {String} badgeService            Badge service url
 * @param  {Object} statusColor             Mapping for status and color
 * @param  {Function} encodeBadgeSubject    Function to encode subject
 * @param  {Array}  [builds=[]]             An array of builds
 * @param  {String} [subject='job']         Subject of the badge
 * @return {String}
 */
function getUrl({ badgeService, statusColor, encodeBadgeSubject, builds = [], subject = 'job' }) {
    let color = 'lightgrey';
    let status = 'unknown';

    if (builds.length > 0) {
github screwdriver-cd / screwdriver / plugins / pipelines / tokens / list.js View on Github external
'use strict';

const boom = require('boom');
const joi = require('joi');
const schema = require('screwdriver-data-schema');
const getSchema = joi.array().items(schema.models.token.get);
const pipelineIdSchema = joi.reach(schema.models.pipeline.base, 'id');

module.exports = () => ({
    method: 'GET',
    path: '/pipelines/{id}/tokens',
    config: {
        description: 'List tokens for pipeline',
        notes: 'List tokens for a specific pipeline',
        tags: ['api', 'tokens'],
        auth: {
            strategies: ['token'],
            scope: ['user', '!guest']
        },
        plugins: {
            'hapi-swagger': {
                security: [{ token: [] }]

screwdriver-data-schema

Internal Data Schema of Screwdriver

BSD-3-Clause
Latest version published 1 day ago

Package Health Score

81 / 100
Full package analysis