Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
revision: templateVariables.revision,
comment: templateVariables.comment,
pushlog_id: parseInt(templateVariables.pushlog_id, 10),
pushdate: templateVariables.pushdate,
},
repository: {
url: templateVariables.url,
project: templateVariables.project,
level: templateVariables.level,
},
now: new Date().toJSON(),
as_slugid,
ownTaskId: as_slugid('decision'),
};
let result = jsone(yaml.safeLoad(template), context);
// https://bugzilla.mozilla.org/show_bug.cgi?id=1437562
// change `repo:...:*` to `repo:...:branch:default` for old revisions
// before this change landed in-tree.
result.tasks[0].scopes = result.tasks[0].scopes.map(scope => {
if (scope.startsWith('assume:repo:hg.mozilla.org/') && scope.endsWith(':*')) {
return scope.replace(/:\*$/, ':branch:default')
}
return scope;
});
return result;
}
const context = merge(
{
taskGroupId: task.taskGroupId,
taskId: task.taskId,
task,
input,
},
actions.variables
);
if (action.kind === 'task') {
const ownTaskId = nice();
context.ownTaskId = ownTaskId;
const newTask = jsone(action.task, context);
await apolloClient.mutate({
mutation: createTaskQuery,
variables: {
taskId: ownTaskId,
task: {
...formatTaskMutation(newTask),
// Call the queue with the decision task's scopes,
// as directed by the action spec
options: {
authorizedScopes: taskGroup.scopes || [],
},
},
},
});
const context = merge(
{
taskGroupId: task.taskGroupId,
taskId: task.taskId,
task,
input,
},
actions.variables
);
if (action.kind === 'task') {
const ownTaskId = nice();
context.ownTaskId = ownTaskId;
const newTask = jsone(action.task, context);
await apolloClient.mutate({
mutation: createTaskQuery,
variables: {
taskId: ownTaskId,
task: {
...newTask,
// Call the queue with the decision task's scopes,
// as directed by the action spec
options: {
authorizedScopes: taskGroup.scopes || [],
},
},
},
});
const ownTaskId = nice();
context.ownTaskId = ownTaskId;
const newTask = jsone(action.task, context);
// call the queue with the decision task's scopes, as directed by the action spec
const actionsQueue = this.props.queue.use({
authorizedScopes: this.props.decision.scopes || []
});
await actionsQueue.createTask(ownTaskId, newTask);
return ownTaskId;
}
// action.kind === 'hook'
const hookPayload = jsone(action.hookPayload, context);
const { hookId, hookGroupId } = action;
// verify that the decision task has the appropriate in-tree:action-hook:.. scope
const expansion = await this.props.auth.expandScopes({
scopes: this.props.decision.scopes
});
const expression = `in-tree:hook-action:${hookGroupId}/${hookId}`;
if (!satisfiesExpression(expansion.scopes, expression)) {
throw new Error(
`Action is misconfigured: decision task's scopes do not satisfy ${expression}`
);
}
const result = await this.props.hooks.triggerHook(
hookGroupId,
hookId,
task: {
...newTask,
// Call the queue with the decision task's scopes,
// as directed by the action spec
options: {
authorizedScopes: taskGroup.scopes || [],
},
},
},
});
return ownTaskId;
}
// Case where action.kind === 'hook'
const hookPayload = jsone(action.hookPayload, context);
const { hookId, hookGroupId } = action;
// verify that the decision task has
// the appropriate in-tree:action-hook:.. scope
const {
data: { expandScopes },
} = await apolloClient.query({
query: expandScopesQuery,
variables: {
scopes: taskGroup.scopes || [],
},
});
const expression = `in-tree:hook-action:${hookGroupId}/${hookId}`;
if (!satisfiesExpression(expandScopes, expression)) {
throw new Error(
`Action is misconfigured: decision task's scopes do not satisfy ${expression}`
const context = merge(
{
taskGroupId,
taskId,
task,
input
},
actions.variables
);
if (action.kind === 'task') {
const ownTaskId = nice();
context.ownTaskId = ownTaskId;
const newTask = jsone(action.task, context);
// call the queue with the decision task's scopes, as directed by the action spec
const actionsQueue = this.props.queue.use({
authorizedScopes: this.props.decision.scopes || []
});
await actionsQueue.createTask(ownTaskId, newTask);
return ownTaskId;
}
// action.kind === 'hook'
const hookPayload = jsone(action.hookPayload, context);
const { hookId, hookGroupId } = action;
// verify that the decision task has the appropriate in-tree:action-hook:.. scope
const expansion = await this.props.auth.expandScopes({
scopes: this.props.decision.scopes
const context = defaults(
{},
{
taskGroupId: decisionTaskId,
taskId: taskId || null,
input,
},
staticActionVariables,
);
const queue = taskcluster.getQueue(currentRepo.tc_root_url, testMode);
if (action.kind === 'task') {
context.task = task;
context.ownTaskId = actionTaskId;
const actionTask = jsone(action.task, context);
const decisionTask = await queue.task(decisionTaskId);
const submitQueue = queue.use({ authorizedScopes: decisionTask.scopes });
await submitQueue.createTask(actionTaskId, actionTask);
return actionTaskId;
}
if (action.kind === 'hook') {
const hookPayload = jsone(action.hookPayload, context);
const { hookId, hookGroupId } = action;
const auth = new Auth({ rootUrl: currentRepo.tc_root_url });
const userCredentials = testMode
? taskcluster.getMockCredentials()
: taskcluster.getCredentials(currentRepo.tc_root_url);
const queue = taskcluster.getQueue(currentRepo.tc_root_url, testMode);
if (action.kind === 'task') {
context.task = task;
context.ownTaskId = actionTaskId;
const actionTask = jsone(action.task, context);
const decisionTask = await queue.task(decisionTaskId);
const submitQueue = queue.use({ authorizedScopes: decisionTask.scopes });
await submitQueue.createTask(actionTaskId, actionTask);
return actionTaskId;
}
if (action.kind === 'hook') {
const hookPayload = jsone(action.hookPayload, context);
const { hookId, hookGroupId } = action;
const auth = new Auth({ rootUrl: currentRepo.tc_root_url });
const userCredentials = testMode
? taskcluster.getMockCredentials()
: taskcluster.getCredentials(currentRepo.tc_root_url);
if (!userCredentials) {
throw new Error(tcCredentialsMessage);
}
const hooks = new Hooks({
rootUrl: currentRepo.tc_root_url,
credentials: userCredentials.credentials,
});
const decisionTask = await queue.task(decisionTaskId);
const expansion = await auth.expandScopes({
scopes: decisionTask.scopes,