Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public async handle(e: EventFired, ctx: HandlerContext): Promise {
const sdmGoal = e.data.SdmGoal[0] as SdmGoalEvent;
if (!(await cancelableGoal(sdmGoal, this.configuration))) {
logger.info("Not exciting this process because goal can't be canceled");
return Success;
}
await verifyGoal(sdmGoal, this.configuration.sdm.goalSigning, ctx);
logger.info("Exiting this process because goal was canceled");
// exit immediately with 0 to make sure k8s doesn't re-schedule this pod
automationClientInstance().configuration.ws.termination.graceful = false;
if (cluster.isWorker) {
await (automationClientInstance().webSocketHandler as ClusterWorkerRequestProcessor).sendShutdown(0, ctx as any);
}
safeExit(0);
return Success;
}
}
parameters: T,
ctx: HandlerContext): Promise {
const name = typeof command === "string" ? command : command.name;
const trigger = (ctx as any as AutomationContextAware).trigger;
const md = automationClientInstance().automationServer.automations.commands
.find(c => c.name === name);
if (!md) {
return {
code: 1,
message: `Command '${name}' could not be found`,
};
} else {
// Invoke the command
return automationClientInstance().automationServer.invokeCommand(
prepareCommandInvocation(md, parameters),
prepareHandlerContext(ctx, trigger),
);
}
}
public eventIncoming(payload: EventIncoming) {
if (cluster.isWorker) {
// Register event handler locally only
const maker = () => new FulfillGoalOnRequested(
this.implementationMapper,
this.projectLoader,
this.repoRefResolver,
this.credentailsResolver,
this.logFactory);
automationClientInstance().withEventHandler(maker);
}
}
jobSpec.spec.template.spec = containerSpec;
jobSpec.spec.template.spec.affinity = affinity;
jobSpec.metadata.name =
`${deploymentName}-job-${goal.goalSetId.slice(0, 7)}-${goalName}`;
jobSpec.metadata.namespace = deploymentNamespace;
jobSpec.spec.template.spec.restartPolicy = "Never";
jobSpec.spec.template.spec.containers[0].name = jobSpec.metadata.name;
jobSpec.spec.template.spec.containers[0].env.push({
name: "ATOMIST_JOB_NAME",
value: jobSpec.metadata.name,
},
{
name: "ATOMIST_REGISTRATION_NAME",
value: `${automationClientInstance().configuration.name}-job-${goal.goalSetId.slice(0, 7)}-${goalName}`,
},
{
name: "ATOMIST_GOAL_TEAM",
value: ctx.workspaceId,
},
{
name: "ATOMIST_GOAL_TEAM_NAME",
value: (ctx as any as AutomationContextAware).context.workspaceName,
},
{
name: "ATOMIST_GOAL_ID",
value: (goal as any).id,
},
{
name: "ATOMIST_GOAL_SET_ID",
value: goal.goalSetId,
this.commandHandlers.forEach(eh => automationClientInstance().withCommandHandler(eh));
}
export function shouldFulfill(sdmGoal: SdmGoalEvent,
registration: string = automationClientInstance().configuration.name): boolean {
const provenance = sdmGoal.fulfillment.registration;
return provenance === registration || registration.startsWith(`${provenance}-job`);
}
return async cli => {
const pj = require(path.join(appRoot.path, "package.json"));
const clientPj = require(path.join(appRoot.path, "node_modules", "@atomist", "automation-client", "package.json"));
const sdmPj = require(path.join(appRoot.path, "node_modules", "@atomist", "sdm", "package.json"));
const sdmCorePj = require(path.join(appRoot.path, "node_modules", "@atomist", "sdm-core", "package.json"));
const gitInfo = info(automationClientInstance().automations.automations);
const msg: SlackMessage = {
attachments: [{
author_name: pj.author && pj.author.name ? pj.author.name : pj.author,
title: sdm.name,
title_link: pj.homepage,
fallback: sdm.name,
text: `${pj.description}
Version: ${codeLine(sdm.configuration.version)} - License: ${codeLine(pj.license)}`,
}, {
author_name: "Details",
fallback: "Details",
text: `Sha: ${codeLine(gitInfo.git && gitInfo.git.sha ? gitInfo.git.sha.slice(0, 7) : "n/a")}
Repository: ${codeLine(gitInfo.git && gitInfo.git.repository ? gitInfo.git.repository : "n/a")}
Policy: ${codeLine(sdm.configuration.policy)}
Environment: ${codeLine(sdm.configuration.environment)}
variables: { registration: () => [automationClientInstance()?.configuration?.name] },
}))
function reportStart(sdmGoal: SdmGoal, progressLog: ProgressLog) {
progressLog.write(`---`);
progressLog.write(`Goal: ${sdmGoal.name} - ${sdmGoal.environment}`);
progressLog.write(`GoalSet: ${sdmGoal.goalSet} - ${sdmGoal.goalSetId}`);
progressLog.write(
`SDM: ${automationClientInstance().configuration.name}@${automationClientInstance().configuration.version}`);
progressLog.write(`---`);
}
export function k8sJobEnv(podSpec: k8s.V1Pod, goalEvent: SdmGoalEvent, context: HandlerContext): k8s.V1EnvVar[] {
const goalName = k8sJobGoalName(goalEvent);
const jobName = k8sJobName(podSpec, goalEvent);
const envVars: k8s.V1EnvVar[] = [
{
name: "ATOMIST_JOB_NAME",
value: jobName,
},
{
name: "ATOMIST_REGISTRATION_NAME",
value: `${automationClientInstance().configuration.name}-job-${goalEvent.goalSetId.slice(0, 7)}-${goalName}`,
},
{
name: "ATOMIST_GOAL_TEAM",
value: context.workspaceId,
},
{
name: "ATOMIST_GOAL_TEAM_NAME",
value: (context as any as AutomationContextAware).context.workspaceName,
},
{
name: "ATOMIST_GOAL_ID",
value: (goalEvent as any).id,
},
{
name: "ATOMIST_GOAL_SET_ID",
value: goalEvent.goalSetId,