Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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');
}
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, {
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
});
}
const isUUID = (uuid) => (typeof uuid === 'string') ? validator.isUUID(uuid) : false
const isSHA256 = (sha256) => (typeof sha256 === 'string') ? /[a-f0-9]{64}/.test(sha256) : false
});
}
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) {
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');
}
}
}
test: v => validator.isUUID(v),
},
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
const validateLastUsedVolume = (luv) =>
luv === null || (typeof luv === 'string' && validator.isUUID(luv)) ? luv : undefined
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})
}