Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function spawnAndWatch(spawnCommand: SpawnCommand,
options: SpawnOptions,
log: ProgressLog,
spOpts: Partial = {}): Promise {
const delimitedLog = new DelimitedWriteProgressLogDecorator(log, "\n");
// Set the goal default timeout to 10mins
if (!spOpts.timeout) {
spOpts.timeout = configurationValue("sdm.goal.timeout", 1000 * 60 * 10);
}
return clientSpawnAndWatch(spawnCommand, options, delimitedLog, spOpts);
}
correlation_id: trigger.correlation_id,
team: trigger.team,
command: trigger.command,
source: trigger.source,
parameters: trigger.parameters,
parameter_specs: _.map(newParameters, (v, k) => ({
...v,
name: k,
required: v.required !== undefined ? v.required : true,
pattern: v.pattern ? v.pattern.source : undefined,
})),
content_type: AtomistContinuationMimeType,
};
// Strangely send a message doesn't need a promise await; it is sync.
configurationValue("ws.lifecycle").send(response);
throw new CommandListenerExecutionInterruptError(
`Prompting for new parameters: ${_.map(newParameters, (v, k) => k).join(", ")}`);
};
}
export async function portIsInUse(host: string, port: number): Promise {
const httpClient = configurationValue("http.client.factory", DefaultHttpClientFactory).create();
const agent = new https.Agent({
rejectUnauthorized: false,
});
try {
await httpClient.exchange(`${host}:${port}`, {
method: HttpMethod.Head,
options: { httpsAgent: agent },
});
return true;
} catch {
return false;
}
}
export async function pendingGoalSets(ctx: HandlerContext,
name: string,
offset: number = 0,
fetch: number = 50): Promise {
const results = await ctx.graphClient.query({
name: "InProcessSdmGoalSets",
variables: {
fetch,
offset,
registration: [name],
},
options: {
...QueryNoCacheOptions,
log: configurationValue("sdm.query.logging", false),
},
});
return (results.SdmGoalSet || []).map(gs => gs);
}
export function slackFooter(): string {
return `${configurationValue("name")}`;
}
export async function listJobs(labelSelector?: string): Promise {
const kc = loadKubeConfig();
const batch = kc.makeApiClient(k8s.BatchV1Api);
if (configurationValue("sdm.k8s.job.singleNamespace", true)) {
const podNs = await readNamespace();
return (await batch.listNamespacedJob(
podNs,
undefined,
undefined,
undefined,
undefined,
labelSelector,
)).body.items;
} else {
return (await batch.listJobForAllNamespaces(
undefined,
undefined,
undefined,
labelSelector,
)).body.items;
return async (inv: EndpointVerificationInvocation) => {
const httpClient = configurationValue("http.client.factory", DefaultHttpClientFactory).create();
const agent = new https.Agent({
rejectUnauthorized: false,
});
if (!inv.url) {
throw new Error("Verify called with null URL");
}
try {
const resp = await httpClient.exchange(inv.url, {
method: HttpMethod.Get,
options: { httpsAgent: agent },
retry: retryOpts,
});
logger.debug(`lookFor200OnEndpointRootGet: Response for ${inv.url} was ${resp.status}`);
if (resp.status !== 200) {
throw new Error(`Unexpected response when getting ${inv.url}: ${resp.status}`);
}
return {
providerId: provider.providerId,
name: org.owner,
tasks: org.repos.map(repo => {
return {
providerId: provider.providerId,
repoId: repo.id,
owner: repo.owner,
name: repo.name,
branch: repo.defaultBranch || "master",
};
}),
};
});
const prefs: PreferenceStore = configurationValue("sdm.preferenceStoreFactory")(ctx);
for (const org of orgs) {
const analyzed = await prefs.get(preferenceKey(org.name), { scope: PreferenceScope.Sdm, defaultValue: false });
if (!analyzed || rerun) {
try {
await createJob({
command: calculateFingerprintTask([], []),
parameters: org.tasks,
name: `OrganizationAnalysis/${org.providerId}/${org.name}`,
description: `Analyzing repositories in ${bold(org.name)}`,
},
ctx);
await prefs.put(preferenceKey(org.name), true, { scope: PreferenceScope.Sdm });
} catch (e) {
logger.warn("Failed to create job for org '%s': %s", org.name, e.message);
}