How to use the hoek.assert function in hoek

To help you get started, we’ve selected a few hoek 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 mozilla / api.webmaker.org / scripts / migrate.js View on Github external
var Hoek = require('hoek');
var spawn = require('cross-spawn');
var BPromise = require('bluebird');
var fs = BPromise.promisifyAll(require('fs'));
var path = require('path');

var defaults = {
  // default account has no password. Except on Windows, where it asks for a password during installation
  POSTGRE_CONNECTION_STRING: 'postgre://postgres@localhost:5432/webmaker'
};

process.env = Hoek.applyToDefaults(defaults, process.env);

var pgConnString = url.parse(process.env.POSTGRE_CONNECTION_STRING);
Hoek.assert(pgConnString.auth, 'Your PosgreSQL connection string must at least contain a username');
Hoek.assert(pgConnString.hostname, 'Your PosgreSQL connection string must specify a hostname');
Hoek.assert(pgConnString.port, 'Your PosgreSQL connection string must specify a port');
Hoek.assert(pgConnString.port, 'Your PosgreSQL connection string must specify a database');

var pgAuth = pgConnString.auth.split(':');
process.env.PGPASSWORD = pgAuth[1];

fs.readdirAsync('./migrations').each(function(filename) {
  return new BPromise(function(resolve, reject) {
    var create = spawn(
      'psql',
      [
        '-h', pgConnString.hostname,
        '-p', pgConnString.port,
        '-d', pgConnString.path.replace('/', ''),
        '-U', pgAuth[0],
        '-f', path.join( './migrations', filename)], {
github opendistro-for-elasticsearch / security-kibana-plugin / lib / session / sessionPlugin.js View on Github external
const register = function (server, options) {
    let results = Joi.validate(options, internals.config);
    Hoek.assert(!results.error, results.error);

    let settings = results.value;


    // @todo Don't register e.g. authenticate() when we have Kerberos or Proxy-Auth?
    server.ext('onPreAuth', function (request, h) {
        request.auth.securitySessionStorage = {

            /**
             * Tries to authenticate a user. If multitenancy is enabled, we also try to validate that the
             * user has at least one valid tenant
             * @param {object} credentials
             * @returns {Promise<*>}
             */
            authenticate: async function(credentials, options = {}) {
                try {
github hapijs / hapi / lib / auth.js View on Github external
internals.Auth.prototype.default = function (options) {

    Schema.assert('auth', options, 'default strategy');
    Hoek.assert(!this.settings.default, 'Cannot set default strategy more than once');

    var settings = Hoek.clone(options);             // options can be reused

    if (typeof settings === 'string') {
        settings = {
            strategies: [settings],
            mode: 'required'
        };
    }
    else if (settings.strategy) {
        settings.strategies = [settings.strategy];
        delete settings.strategy;
    }

    Hoek.assert(settings.strategies && settings.strategies.length, 'Default authentication strategy missing strategy name');
github BigRoomStudios / schwifty-migrate-diff / lib / index.js View on Github external
const db2JoiTypes = dbColsToConvert.reduce((collector, columnName) => {

                const currentColumn = dbSchema[columnName];

                // dbColsToConvert has filtered out invalid db column types
                // and fed them to skippedCols, no error will be
                // produced here
                const [, knexType] = Mappings.convertFuncs.db2Knex(currentColumn);

                Hoek.assert(Mappings.maps.knexJoiMap[knexType], `The left side of knexJoiMap must be in parity with the right side of columnCompilerKnexMap. Failed for ${knexType}`);

                // No errors should be produced
                const [, db2Joi] = Mappings.convertFuncs.knex2JoiType(knexType);

                return Object.assign({}, collector, {
                    [columnName]: db2Joi
                });
            }, {});
github daviddias / simple-raytracer / node_modules / code / lib / index.js View on Github external
internals.assert = function (assertion, condition, error) {

    if (!condition) {
        delete internals.locations[assertion._location];
        Hoek.assert(condition, error);
    }
};
github flaviuse / mern-authentication / client / node_modules / joi / lib / types / lazy / index.js View on Github external
set(fn, options) {

        Hoek.assert(typeof fn === 'function', 'You must provide a function as first argument');
        Hoek.assert(options === undefined || (options && typeof options === 'object' && !Array.isArray(options)), `Options must be an object`);

        if (options) {
            const unknownOptions = Object.keys(options).filter((key) => !['once'].includes(key));
            Hoek.assert(unknownOptions.length === 0, `Options contain unknown keys: ${unknownOptions}`);
            Hoek.assert(options.once === undefined || typeof options.once === 'boolean', 'Option "once" must be a boolean');
        }

        const obj = this.clone();
        obj._flags.lazy = fn;

        if (options && options.once !== obj._flags.once) {
            obj._flags.once = options.once;
        }

        return obj;
github hapi-learning / hapi-learning / app / utils / storage.js View on Github external
exports.register = function(server, options, next) {

    Hoek.assert(options.root, 'option.root is required');

    internals.File = server.app.models.File;

    internals.root = options.root;
    internals.relativeTo = Path.join(internals.root, options.storage || 'storage');
    internals.courseFolder = Path.join(internals.relativeTo, options.courses || 'courses');
    internals.documents = options.documents || 'documents';
    internals.homepage = 'homepage';

    internals.initialize();

    const Storage = load();

    server.app.storage = Storage;
    next();
};
github hapijs / catbox / lib / redis.js View on Github external
exports.Connection = internals.Connection = function (options) {

    Hoek.assert(this.constructor === internals.Connection, 'Redis cache client must be instantiated using new');

    this.settings = options;
    this.client = null;
    return this;
};
github flaviuse / mern-authentication / client / node_modules / joi / lib / index.js View on Github external
joi._defaults = (schema) => {

            if (this._defaults) {
                schema = this._defaults(schema);
                Hoek.assert(schema instanceof this.constructor, 'defaults() must return a schema');
            }

            schema = fn(schema);
            Hoek.assert(schema instanceof this.constructor, 'defaults() must return a schema');
            return schema;
        };