How to use the assert-plus.optionalString function in assert-plus

To help you get started, we’ve selected a few assert-plus 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 splunk / splunk-aws-project-trumpet / cloudtrail-serverless / lambda_code / cloudtrail_logger / node_modules / dashdash / lib / dashdash.js View on Github external
function bashCompletionSpecFromOptions(args) {
    assert.object(args, 'args');
    assert.object(args.options, 'args.options');
    assert.optionalString(args.context, 'args.context');
    assert.optionalBool(args.includeHidden, 'args.includeHidden');
    assert.optionalArrayOfString(args.argtypes, 'args.argtypes');

    var context = args.context || '';
    var includeHidden = (args.includeHidden === undefined
        ? false : args.includeHidden);

    var spec = [];
    var shortopts = [];
    var longopts = [];
    var optargs = [];
    (args.options || []).forEach(function (o) {
        if (o.group !== undefined && o.group !== null) {
            // Skip group headers.
            return;
        }
github joyent / node-http-signature / lib / signer.js View on Github external
signRequest: function signRequest(request, options) {
    assert.object(request, 'request');
    assert.object(options, 'options');
    assert.optionalString(options.algorithm, 'options.algorithm');
    assert.string(options.keyId, 'options.keyId');
    assert.optionalArrayOfString(options.headers, 'options.headers');
    assert.optionalString(options.httpVersion, 'options.httpVersion');

    if (!request.getHeader('Date'))
      request.setHeader('Date', jsprim.rfc1123(new Date()));
    if (!options.headers)
      options.headers = ['date'];
    if (!options.httpVersion)
      options.httpVersion = '1.1';

    var alg = [];
    if (options.algorithm) {
      options.algorithm = options.algorithm.toLowerCase();
      alg = validateAlgorithm(options.algorithm);
    }

    var i;
    var stringToSign = '';
github widdix / cfn-create-or-update / index.js View on Github external
exports.createOrUpdate = (args, cb) => {
  assert.object(args, 'args');
  assert.string(args.stackName, 'stackName');
  assert.optionalString(args.templateBody, 'templateBody');
  assert.optionalString(args.templateUrl, 'templateUrl');
  assert.optionalArrayOfObject(args.parameters, 'parameters');
  if (args.parameters !== undefined) {
    args.parameters.forEach((parameter, i) => {
      assert.string(parameter.ParameterKey, `parameters[${i}].parameterKey`);
      assert.optionalString(parameter.ParameterValue, `parameters[${i}].parameterValue`);
      assert.optionalBool(parameter.UsePreviousValue, `parameters[${i}].UsePreviousValue`);
    });
  }
  assert.optionalArrayOfString(args.capabilities, 'capabilities');
  assert.optionalArrayOfString(args.resourceTypes, 'resourceTypes');
  assert.optionalString(args.roleArn, 'roleArn');
  assert.optionalString(args.stackPolicyBody, 'stackPolicyBody');
  assert.optionalString(args.stackPolicyUrl, 'stackPolicyUrl');
  assert.optionalArrayOfString(args.notificationArns, 'notificationArns');
  assert.optionalArrayOfObject(args.tags, 'tags');
  if (args.tags !== undefined) {
github joyent / dragnet / lib / source-fileset.js View on Github external
function FileSetDataSource(args)
{
	mod_assertplus.object(args, 'args');
	mod_assertplus.object(args.log, 'args.log');
	mod_assertplus.optionalString(args.dataroot, 'args.dataroot');

	this.fss_log = args.log;
	this.fss_dataroot = args.dataroot;
}
github joyent / smartos-live / src / fw / lib / fw.js View on Github external
function add(opts, callback) {
    try {
        validateOpts(opts);
        assert.optionalArrayOfObject(opts.rules, 'opts.rules');
        assert.optionalArrayOfObject(opts.localVMs, 'opts.localVMs');
        assert.optionalArrayOfObject(opts.remoteVMs, 'opts.remoteVMs');
        assert.optionalString(opts.createdBy, 'opts.createdBy');

        var optRules = opts.rules || [];
        var optLocalVMs = opts.localVMs || [];
        var optRemoteVMs = opts.remoteVMs || [];
        if (optRules.length === 0 && optLocalVMs.length === 0
            && optRemoteVMs.length === 0) {
            throw new Error(
                'Payload must contain one of: rules, localVMs, remoteVMs');
        }
    } catch (err) {
        return callback(err);
    }
    var log = util_log.entry(opts, 'add');

    pipeline({
    funcs: [
github restify / node-restify / lib / plugins / static.js View on Github external
function serveStatic(options) {
    var opts = options || {};

    if (typeof opts.appendRequestPath === 'undefined') {
        opts.appendRequestPath = true;
    }

    assert.object(opts, 'options');
    assert.string(opts.directory, 'options.directory');
    assert.optionalNumber(opts.maxAge, 'options.maxAge');
    assert.optionalObject(opts.match, 'options.match');
    assert.optionalString(opts.charSet, 'options.charSet');
    assert.optionalString(opts.file, 'options.file');
    assert.bool(opts.appendRequestPath, 'options.appendRequestPath');

    var p = path.normalize(opts.directory).replace(/\\/g, '/');
    var re = new RegExp('^' + escapeRE(p) + '/?.*');

    function serveFileFromStats(file, err, stats, isGzip, req, res, next) {
        if (typeof req.closed === 'function' && req.closed()) {
            next(false);
            return;
        }

        if (err) {
            next(new ResourceNotFoundError(err, '%s', req.path()));
            return;
        } else if (!stats.isFile()) {
github joyent / smartos-live / src / fw / node_modules / cmdln / index.js View on Github external
function Cmdln(config) {
    var self = this;
    assert.optionalObject(config, 'config');
    config = config || {};
    assert.optionalString(config.name, 'config.name')
    assert.optionalString(config.desc, 'config.desc')
    assert.optionalArrayOfObject(config.options, 'config.options');
    assert.optionalArrayOfString(config.synopses, 'config.synopses');
    assert.optionalObject(config.helpOpts, 'config.helpOpts')
    assert.optionalString(config.helpBody, 'config.helpBody')
    assert.optionalObject(config.helpSubcmds, 'config.helpSubcmds');

    this.name = config.name || this.constructor.name.toLowerCase();
    this.desc = config.desc;
    this.synopses = config.synopses || DEFAULT_SYNOPSES;
    this.options = config.options || DEFAULT_OPTIONS;
    this.helpOpts = config.helpOpts || {};
    this.helpBody = config.helpBody;
    this.helpSubcmds = config.helpSubcmds || null;
    if (!this.helpOpts.indent)
        this.helpOpts.indent = space(4);
    else if (typeof (this.helpOpts.indent) === 'number')
        this.helpOpts.indent = space(this.helpOpts.indent);
    if (!this.helpOpts.groupIndent) {
        var gilen = Math.round(this.helpOpts.indent.length / 2);
        this.helpOpts.groupIndent = space(gilen);
github joyent / moray / main.js View on Github external
function setupLogger(config) {
    var cfg_b = config.bunyan;
    assert.object(cfg_b, 'config.bunyan');
    assert.optionalString(cfg_b.level, 'config.bunyan.level');
    assert.optionalObject(cfg_b.syslog, 'config.bunyan.syslog');

    var level = LOG.level();

    if (cfg_b.syslog && !LOG_LEVEL_OVERRIDE) {
        assert.string(cfg_b.syslog.facility,
                      'config.bunyan.syslog.facility');
        assert.string(cfg_b.syslog.type, 'config.bunyan.syslog.type');

        var facility = bsyslog.facility[cfg_b.syslog.facility];
        LOG = bunyan.createLogger({
            name: NAME,
            serializers: mod_cmd.LOG_SERIALIZERS,
            streams: [ {
                level: level,
                type: 'raw',
github joyent / sdc-docker / lib / backends / sdc / networks.js View on Github external
function externalNetworkByName(opts, container, payload, callback) {
    assert.object(opts, 'opts');
    assert.object(opts.app, 'opts.app');
    assert.object(opts.config, 'opts.config');
    assert.object(opts.config.napi, 'opts.config.napi');
    assert.optionalString(opts.config.externalNetwork,
        'opts.config.externalNetwork');
    assert.object(opts.account, 'opts.account');
    assert.uuid(opts.account.uuid, 'opts.account.uuid');
    assert.uuid(opts.req_id, 'opts.req_id');
    assert.object(payload, 'payload');
    assert.func(callback, 'callback');

    var externalNetworkName;
    var labels = container.Labels || {};
    var log = opts.log;

    if (Object.prototype.hasOwnProperty.call(labels,
        TRITON_PUBLIC_NETWORK_LABEL))
    {
        externalNetworkName = labels[TRITON_PUBLIC_NETWORK_LABEL];
    }
github joyent / smartos-live / src / img / node_modules / sdc-clients / lib / imgapi.js View on Github external
function removeImageAcl(uuid, acl, account, options, callback) {
    var self = this;
    assert.string(uuid, 'uuid');
    if (typeof (account) === 'function') {
        callback = account;
        options = {};
        account = undefined;
    } else if (typeof (options) === 'function') {
        callback = options;
        options = {};
    }
    assert.optionalString(account, 'account');
    assert.arrayOfString(acl, 'acl');
    assert.object(options, 'options');
    assert.optionalObject(options.headers, 'options.headers');
    assert.func(callback, 'callback');

    var path = self._path(format('/images/%s/acl', uuid), {
        channel: self.channel,
        action: 'remove',
        account: account
    });
    self._getAuthHeaders(function (hErr, headers) {
        if (hErr) {
            callback(hErr);
            return;
        }
        if (options.headers) {