How to use the joi.reach function in joi

To help you get started, we’ve selected a few joi 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 / 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']
        },
        plugins: {
github screwdriver-cd / screwdriver / plugins / pipelines / syncPRs.js View on Github external
'use strict';

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

module.exports = () => ({
    method: 'POST',
    path: '/pipelines/{id}/sync/pullrequests',
    config: {
        description: 'Add or update pull request of a pipeline',
        notes: 'Add or update pull request jobs',
        tags: ['api', 'pipelines'],
        auth: {
            strategies: ['token'],
            scope: ['user', '!guest']
        },
        plugins: {
            'hapi-swagger': {
                security: [{ token: [] }]
            }
github muraljs / joiql / index.js View on Github external
fields: () => omitBy(mapValues(desc.children, (child, k) => {
            if (presence(child, 'forbidden')) return null
            return { type: descToType(Joi.reach(schema, k), true) }
          }), isNull)
        })
github muraljs / joiql / index.js View on Github external
          fields: () => descsToFields(mapValues(desc.children, (child, k) => Joi.reach(schema, k)))
        })
github screwdriver-cd / screwdriver / plugins / tokens / update.js View on Github external
'use strict';

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

module.exports = () => ({
    method: 'PUT',
    path: '/tokens/{id}',
    config: {
        description: 'Update a token',
        notes: 'Update a specific token',
        tags: ['api', 'tokens'],
        auth: {
            strategies: ['token'],
            scope: ['user', '!guest']
        },
        plugins: {
            'hapi-swagger': {
                security: [{ token: [] }]
            }
github screwdriver-cd / screwdriver / plugins / pipelines / jobBadge.js View on Github external
}
                };

                return job.getBuilds(listConfig)
                    .then(builds => reply.redirect(getUrl(Object.assign(
                        badgeConfig,
                        {
                            builds,
                            subject: `${pipeline.name}:${jobName}`
                        }))));
            }).catch(() => reply.redirect(getUrl(badgeConfig)));
        },
        validate: {
            params: {
                id: idSchema,
                jobName: joi.reach(schema.models.job.base, 'name')
            }
        }
    }
});
github screwdriver-cd / screwdriver / plugins / events / get.js View on Github external
'use strict';

const boom = require('boom');
const joi = require('joi');
const schema = require('screwdriver-data-schema');
const getSchema = schema.models.event.get;
const idSchema = joi.reach(schema.models.event.base, 'id');

module.exports = () => ({
    method: 'GET',
    path: '/events/{id}',
    config: {
        description: 'Get a single event',
        notes: 'Returns a event record',
        tags: ['api', 'events'],
        auth: {
            strategies: ['token'],
            scope: ['user', 'build', 'pipeline']
        },
        plugins: {
            'hapi-swagger': {
                security: [{ token: [] }]
            }
github screwdriver-cd / screwdriver / plugins / pipelines / badge.js View on Github external
'use strict';

const joi = require('joi');
const schema = require('screwdriver-data-schema');
const workflowParser = require('screwdriver-workflow-parser');
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}  [buildsStatus=[]]       An array of builds
 * @param  {String} [subject='job']         Subject of the badge
 * @return {String}
 */
function getUrl({
    badgeService,
    statusColor,
    encodeBadgeSubject,
    buildsStatus = [],
github screwdriver-cd / screwdriver / plugins / commands / get.js View on Github external
'use strict';

const boom = require('boom');
const joi = require('joi');
const schema = require('screwdriver-data-schema');
const getSchema = schema.models.command.get;
const namespaceSchema = joi.reach(schema.models.command.base, 'namespace');
const nameSchema = joi.reach(schema.models.command.base, 'name');
const versionSchema = joi.reach(schema.models.command.base, 'version');
const tagSchema = joi.reach(schema.models.commandTag.base, 'tag');

module.exports = () => ({
    method: 'GET',
    path: '/commands/{namespace}/{name}/{versionOrTag}',
    config: {
        description: 'Get a single command given command namespace, name and version or tag',
        notes: 'Returns a command record',
        tags: ['api', 'commands'],
        auth: {
            strategies: ['token'],
            scope: ['user', 'build']
        },
        plugins: {
            'hapi-swagger': {
                security: [{ token: [] }]