How to use the validator.isUUID function in validator

To help you get started, we’ve selected a few validator 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 devarchy / website / server / database / thingdb / validate / thing.js View on Github external
return;
        }

        if( value === undefined ) {
            errors.push('property `'+prop+'` is equal to `undefined` which is forbidden');
            return;
        }

        assert(prop_spec.validation);

        // TODO - implement validation for type 'Thing.resource', ...
        assert(prop_spec.validation.type);
     // const eraser_value = [null, undefined];
        const eraser_value = [null];
        if( [String, Array].includes( prop_spec.validation.type.constructor ) ) {
            if( !eraser_value.includes(value) && (!value || value.constructor!==String || !validator.isUUID(value)) ) {
                errors.push('property `'+prop+'` has value `'+value+'` but value is expected to be a UUID');
            }
        }
        else {
            // TODO properly handle unserialze Date from DB (problem: JSON saves Date as String -> same for json_data)
            const types = prop_spec.validation.type === Date ? [Date, String] : [prop_spec.validation.type];
            if( !eraser_value.includes(value) && !types.includes(value.constructor) ) {
                errors.push('property `'+prop+'` has value `'+value+'` but value is expected to be a '+prop_spec.validation.type);
            }
        }

        let test = prop_spec.validation.test;
        if( test ) {
            if( ! test(value, {Thing: arg.Thing}) ) {
                errors.push('property `'+prop+'` with value `'+value+'` failed validation test provided by schema');
            }
github cneira / zcage / lib / zone.js View on Github external
function container_wait(id, condition, callback) {
    var wstat = 'running';
    var previous = [];
    if (condition) {
        wstat = condition;
    }
    while (true) {
        if (validator.isUUID(id)) {
            z = getdata(id, id);
        } else {
            z = getdata(id);
        }
        if (z == null) {
            if (callback) {
                callback(404, {
                    message: "No such container: " + zname
                });
            }
            break;
        }
        previous.push(z.state);
        if (z.state == wstat || (previous.length > 1 && z.state != previous[previous.length - 2])) {
            if (callback)
                callback(200, {
github cneira / zcage / lib / zone.js View on Github external
function destroy(zonename, dzvol, callback) {
    if (!isAbletoexec()) {
	console.log(
	    "You must be root or use an account with Primary Administrator Role to Activate zcage (pfexec zcage activate)"
	);
	return null;
    }
    var zoption = '-z';
    var z = '';
    if (validator.isUUID(zonename)) {
	z = getdata(zonename, zonename);
	zoption = '-u';
    } else {
	z = getdata(zonename);
    }

    var zdestroy;

    if (z == null) {
	console.log(chalk `Destroying zone: ${zonename}  [{red.bold ERR}] `);
	console.log(`${zonename} does not exists`);
	if (callback) {
	    callback(404, {
		message: "No such container: " + zonename
	    });
	}
github wisnuc / appifi / src / fruitmix / lib / media.js View on Github external
const isUUID = (uuid) => (typeof uuid === 'string') ? validator.isUUID(uuid) : false
const isSHA256 = (sha256) => (typeof sha256 === 'string') ? /[a-f0-9]{64}/.test(sha256) : false
github cneira / zcage / lib / zone.js View on Github external
});
        }
        var errorText = iz.stderr.toString().trim();
        if (errorText) {
            console.log("Error installing " + errorText);
            return iz.status;
        }

    } else {

        if (zone_spec && zone_spec['with-image'] && brand != 'kvm' && brand != 'bhyve') {
            if (debug.enabled)
                console.log("installing ", zonename);

            let option = '-s';
            if (validator.isUUID(uuid)) {
                img = zfs.ZCAGE.IMAGES + '/' + uuid + '.zss.gz';
            } else {
                img = zfs.ZCAGE.IMAGES + '/' + uuid;
                option = '-t';
            }
            if (debug.enabled)
                console.log("installing img", img);

            iz = spawnSync('pfexec', ['zoneadm', '-z', zonename, 'install', option,
                img
            ], {
                shell: true
            });

            var errorText = iz.stderr.toString().trim();
            if (errorText) {
github microsoft / tfs-cli / app / lib / jsonvalidate.ts View on Github external
public validateTask(taskPath: string, taskData: any) {
        var vn = (taskData.name || taskPath);

        if (!taskData.id || !check.isUUID(taskData.id)) {
            throw new InvalidFieldException(vn + ': id is a required guid');
        }

        if (!taskData.name || !check.isAlphanumeric(taskData.name)) {
            throw new InvalidFieldException(vn + ': name is a required alphanumeric string');
        }

        if (!taskData.friendlyName || !check.isLength(taskData.friendlyName, 1, 40)) {
            throw new InvalidFieldException(vn + ': friendlyName is a required string <= 40 chars');
        }

        if (!taskData.instanceNameFormat) {
            throw new InvalidFieldException(vn + ': instanceNameFormat is required');
        }
	}
}
github wisnuc / appifi / src / system / index.js View on Github external
const isValidBootArgs = body => 
  typeof body === 'object' 
    && body !== null
    && !!['poweroff', 'reboot', 'rebootMaintenance', 'rebootNormal'].includes(body.op)
    && body.op === 'rebootNormal' 
      ? (typeof body.target === 'string' && validator.isUUID(body.target))
      : true
github wisnuc / appifi / src / system / sysconfig.js View on Github external
const validateLastUsedVolume = (luv) => 
  luv === null || (typeof luv === 'string' && validator.isUUID(luv)) ? luv : undefined
github wisnuc / appifi / src / appifi / lib / utility.js View on Github external
const composeJsonLabel = (uuid, recipe) => {
  
  if (!uuid || !validator.isUUID(uuid)) return null
  if (!validateRecipe(recipe)) return null

  let version = '1.0'
  return stringify({version, uuid, recipe})  
}