Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const getSecrets = cached('secret', async () => {
try {
// via http://gunargessner.com/gcloud-env-vars/
const [contents] = await gcs
.bucket(bucketName)
.file('secrets.env')
.download()
const secrets = dotenv.parse(contents)
console.log('Secrets loaded with keys', Object.keys(secrets))
return secrets
} catch (error) {
throw new VError(error, 'getSecrets() failed')
}
})
export function mutate(subproject: Subproject.Subproject, event: Event): Result.Type {
if (event.type !== "subproject_assigned") {
throw new VError(`illegal event type: ${event.type}`);
}
// Since we cannot have any side effects here, the existance of a user is expected to
// be validated before the event is produced.
subproject.assignee = event.assignee;
}
const projectId = request.query.projectId;
if (!isNonemptyString(projectId)) {
reply.status(404).send({
apiVersion: "1.0",
error: {
code: 404,
message: "required query parameter `projectId` not present (must be non-empty string)",
},
});
return;
}
try {
const projectResult = await service.getProject(ctx, user, projectId);
if (Result.isErr(projectResult)) {
throw new VError(projectResult, "project.viewDetails failed");
}
const project: Project.Project = projectResult;
const exposedProject: ExposedProject = {
allowedIntents: getAllowedIntents([user.id].concat(user.groups), project.permissions),
data: {
id: project.id,
creationUnixTs: toUnixTimestampStr(project.createdAt),
status: project.status,
displayName: project.displayName,
assignee: project.assignee,
description: project.description,
thumbnail: project.thumbnail,
projectedBudgets: project.projectedBudgets,
additionalData: project.additionalData,
tags: project.tags,
const expectations = definition.contracts.expectations.map(expectation => {
return new Contract({
type: Contract.Types.EXPECTATION,
dir: expectation.dir,
integrationType: expectation.integration,
meta: _.defaultTo(expectation.meta, {}),
upstream: {
repo: expectation.upstream.repo,
dir: _.defaultTo(expectation.upstream.dir, 'contracts')
}
});
});
return promises.concat(expectations);
} catch (err) {
throw new VError(
err,
`Failed to fetch contracts for workspace: ${workspace.project.repo}/${workspace.project
.dir}` +
`@ ${workspace.rev}` +
err.message
);
}
}
};
module.exports.process = function (context) {
if (!(_.has(this.push, "value"))) {
throw new verror.VError({
name: "InvalidActionValue.push",
info: {
path: this.path + ".push.value",
value: this.push.value
}
}, "push action requires a .value value");
}
if (!_.has(this.push, "array")) {
throw new verror.VError({
name: "InvalidActionTarget.push",
info: {
path: this.path + ".push.array"
}
}, "push action requires an .array value");
}
var array = this.push.array;
async function getOrganizationAddressOrThrow(
conn: ConnToken,
ctx: Ctx,
organization: string,
): Promise {
const organizationAddress = await getOrganizationAddress(conn.multichainClient, organization);
if (!organizationAddress) {
throw new VError(
{ info: { ctx, organization } },
`No organization address found for ${organization}`,
);
}
return organizationAddress;
}
next = function (idx, err) {
/*
* Note that nfunc_args contains the args we will pass to the
* next func in the func-list the user gave us. Except for
* 'tryEach', which passes cb's. However, it will pass
* 'nfunc_args' to its final callback -- see below.
*/
var res_key, nfunc_args, entry, nextentry;
if (err === undefined)
err = null;
if (idx != current) {
throw (new mod_verror.VError(
'vasync.waterfall: function %d ("%s") invoked ' +
'its callback twice', idx,
rv['operations'][idx].funcname));
}
mod_assert.equal(idx, rv['ndone'],
'idx should be equal to ndone');
entry = rv['operations'][rv['ndone']++];
if (opts.args.impl === 'tryEach' ||
opts.args.impl === 'waterfall') {
nfunc_args = Array.prototype.slice.call(arguments, 2);
res_key = 'results';
entry['results'] = nfunc_args;
} else if (opts.args.impl === 'pipeline') {
nfunc_args = [ opts.args.uarg ];
res_key = 'result';
.catch(err => {
throw new VError(
`Consumer [ ${pair.consumerProjectRev.project()
.repo}:${pair.consumerProjectRev.project()
.dir}/ @ ${pair.consumerProjectRev.rev()} ] ` +
`expectations of type (${pair.consumerExpectation
.integrationType}) is broken: \n` +
`============================================================================ \n` +
err.message
);
});
})
(request, reply) => {
const ctx: Ctx = { requestId: request.id, source: "http" };
const user: ServiceUser = {
id: (request as AuthenticatedRequest).user.userId,
groups: (request as AuthenticatedRequest).user.groups,
};
const bodyResult = validateRequestBody(request.body);
if (Result.isErr(bodyResult)) {
const { code, body } = toHttpError(
new VError(bodyResult, "failed to grant project permission"),
);
reply.status(code).send(body);
return;
}
const { projectId, subprojectId, identity: grantee, intent } = bodyResult.data;
service
.grantSubprojectPermission(ctx, user, projectId, subprojectId, grantee, intent)
.then(() => {
const code = 200;
const body = {
apiVersion: "1.0",
data: {},
};
reply.status(code).send(body);
fs.readFile(file, function (err, data) {
if (err) {
if (err.code === 'ENOENT') {
return callback(new verror.VError(
'File "%s" does not exist.', file));
}
return callback(new verror.VError(
'Error reading "%s": %s', file, err.message));
}
return callback(null, JSON.parse(data.toString()));
});
}