How to use the jsprim.validateJsonObject function in jsprim

To help you get started, we’ve selected a few jsprim 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 joyent / manatee / lib / postgresMgr.js View on Github external
function PostgresMgr(options) {
    assert.object(options, 'options');
    assert.object(options.log, 'options.log');
    assert.ifError(mod_jsprim.validateJsonObject(CONFIG_SCHEMA, options));

    EventEmitter.call(this);

    /** @type {Bunyan} The bunyan log object */
    this._log = options.log.child({component: 'PostgresMgr'}, true);
    var log = this._log;
    var self = this;

    self._postgres = null; /* The child postgres process */

    self._defaultVersion = options.defaultVersion;
    self._pgBaseDir = options.pgBaseDir;
    self._versions = options.versions;
    self._dataConf = path.resolve(options.dataConfig);

    /*
github joyent / dragnet / lib / stream-util.js View on Github external
readToEndJson(stream, function (err, obj) {
		if (!err && schema)
			err = mod_jsprim.validateJsonObject(schema, obj);

		if (err)
			callback(new VError(err, 'read "%s"', filename));
		else
			callback(null, obj);
	});
}
github joyent / dragnet / lib / config-common.js View on Github external
function loadConfig(input)
{
	var dc, error;

	mod_assertplus.object(input);
	error = mod_jsprim.validateJsonObject(dnConfigSchemaBase, input);
	if (error instanceof Error)
		return (new VError(error, 'failed to load config'));

	mod_assertplus.number(input.vmaj);
	mod_assertplus.number(input.vmin);
	if (input.vmaj !== dnConfigMajor)
		return (new VError('failed to load config: major ' +
		    'version ("%s") not supported', input.vmaj));

	error = mod_jsprim.validateJsonObject(dnConfigSchemaCurrent, input);
	if (error instanceof Error)
		return (new VError(error, 'failed to load config'));

	dc = new DragnetConfig();

	input.datasources.forEach(function (dsconfig) {
		dc.dc_datasources[dsconfig.name] = {
		    'ds_backend': dsconfig.backend,
		    'ds_backend_config': dsconfig.backend_config,
		    'ds_filter': dsconfig.filter,
		    'ds_format': dsconfig.dataFormat
		};
	});

	input.metrics.forEach(function (metconfig) {
		var dsname, metname;
github joyent / manatee-state-machine / lib / validation.js View on Github external
{
	var copy, error;

	/*
	 * We want consumers to be able to assume that "deposed" is present, so
	 * it's required in the schema.  But we don't want a flag day for its
	 * introduction, so we insert it here (into our private copy).  Recall
	 * that the caller is supposed to use the value returned by this
	 * validator, not assume that just because we don't return an error that
	 * they can use the original copy.
	 */
	copy = mod_jsprim.deepCopy(clusterState);
	if (copy !== null && !copy.hasOwnProperty('deposed'))
		copy['deposed'] = [];

	error = mod_jsprim.validateJsonObject(schemas.zkState, copy);
	if (error instanceof Error)
		return (error);

	if (copy === null)
		return (null);

	if (copy.sync === null &&
	    (copy.oneNodeWriteMode === undefined ||
	    !copy.oneNodeWriteMode)) {
		return (new VError('"sync" may not be null outside of ' +
		    'one-node-write mode'));
	}

	error = mod_lsn.xlogValidate(clusterState.initWal);
	return (error instanceof Error ? error : copy);
}
github joyent / manatee-state-machine / lib / validation.js View on Github external
function validateAndCopy(schema, obj)
{
	var error;
	error = mod_jsprim.validateJsonObject(schema, obj);
	if (error !== null)
		return (error);
	return (mod_jsprim.deepCopy(obj));
}
github joyent / dragnet / lib / config-common.js View on Github external
function loadConfig(input)
{
	var dc, error;

	mod_assertplus.object(input);
	error = mod_jsprim.validateJsonObject(dnConfigSchemaBase, input);
	if (error instanceof Error)
		return (new VError(error, 'failed to load config'));

	mod_assertplus.number(input.vmaj);
	mod_assertplus.number(input.vmin);
	if (input.vmaj !== dnConfigMajor)
		return (new VError('failed to load config: major ' +
		    'version ("%s") not supported', input.vmaj));

	error = mod_jsprim.validateJsonObject(dnConfigSchemaCurrent, input);
	if (error instanceof Error)
		return (new VError(error, 'failed to load config'));

	dc = new DragnetConfig();

	input.datasources.forEach(function (dsconfig) {
github joyent / manatee / lib / postgresMgr.js View on Github external
PostgresMgr.prototype.getTunables = function (version, major) {
    var tunables;
    var options = {
        synchronous_commit: 'remote_write'
    };

    try {
        tunables = JSON.parse(fs.readFileSync(this.tunablesFile, 'utf8'));
    } catch (e) {
        throw new verror.VError(e, 'failed to load %s', this.tunablesFile);
    }

    assert.ifError(mod_jsprim.validateJsonObject(TUNABLES_SCHEMA, tunables));

    function copy(source) {
        mod_jsprim.forEachKey(source, function (key, value) {
            options[key] = value;
        });
    }

    if (mod_jsprim.hasKey(tunables, 'common')) {
        copy(tunables['common']);
    }

    if (mod_jsprim.hasKey(tunables, major)) {
        copy(tunables[major]);
    }

    if (mod_jsprim.hasKey(tunables, version)) {