File: /home/frenchy/www/french-american.org/current/node_modules/snyk-docker-plugin/lib/docker.ts
import * as subProcess from "./sub-process";
export { Docker, DockerOptions };
interface DockerOptions {
host?: string;
tlsVerify?: string;
tlsCert?: string;
tlsCaCert?: string;
tlsKey?: string;
}
class Docker {
public static run(args: string[], options?: DockerOptions) {
return subProcess.execute("docker", [
...Docker.createOptionsList(options),
...args,
]);
}
private static createOptionsList(options: any) {
const opts: string[] = [];
if (!options) {
return opts;
}
if (options.host) {
opts.push(`--host=${options.host}`);
}
if (options.tlscert) {
opts.push(`--tlscert=${options.tlscert}`);
}
if (options.tlscacert) {
opts.push(`--tlscacert=${options.tlscacert}`);
}
if (options.tlskey) {
opts.push(`--tlskey=${options.tlskey}`);
}
if (options.tlsverify) {
opts.push(`--tlsverify=${options.tlsverify}`);
}
return opts;
}
private optionsList: string[];
constructor(private targetImage: string, options?: DockerOptions) {
this.optionsList = Docker.createOptionsList(options);
}
public run(cmd: string, args: string[] = []) {
return subProcess.execute("docker", [
...this.optionsList,
"run",
"--rm",
"--entrypoint",
'""',
"--network",
"none",
this.targetImage,
cmd,
...args,
]);
}
public async inspect(targetImage: string) {
return await subProcess.execute("docker", [
...this.optionsList,
"inspect",
targetImage,
]);
}
public async catSafe(filename: string) {
try {
return await this.run("cat", [filename]);
} catch (error) {
const stderr: string = error.stderr;
if (typeof stderr === "string") {
if (
stderr.indexOf("No such file") >= 0 ||
stderr.indexOf("file not found") >= 0
) {
return { stdout: "", stderr: "" };
}
}
throw error;
}
}
}