@snyk/snyk-docker-pull
Advanced tools
Comparing version 2.1.1 to 3.0.0
@@ -10,5 +10,14 @@ import * as tmp from "tmp"; | ||
} | ||
export interface DockerPullOptions { | ||
username?: string; | ||
password?: string; | ||
reqOptions?: any; | ||
/** | ||
* loadImage will default to true if no value is sent | ||
*/ | ||
loadImage?: boolean; | ||
} | ||
export declare class DockerPull { | ||
private static findDockerBinary; | ||
pull(username: string, password: string, registryBase: string, repo: string, tag: string, reqOptions?: any, loadImage?: boolean): Promise<DockerPullResult>; | ||
pull(registryBase: string, repo: string, tag: string, opt?: DockerPullOptions): Promise<DockerPullResult>; | ||
private getLayers; | ||
@@ -15,0 +24,0 @@ private buildImage; |
@@ -42,12 +42,10 @@ "use strict"; | ||
} | ||
async pull(username, password, registryBase, repo, tag, | ||
// weak typing on the client | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
reqOptions = {}, loadImage = true) { | ||
const manifest = await registryClient.getManifest(registryBase, repo, tag, username, password, reqOptions); | ||
async pull(registryBase, repo, tag, opt) { | ||
const loadImage = (opt === null || opt === void 0 ? void 0 : opt.loadImage) === undefined ? true : opt.loadImage; | ||
const manifest = await registryClient.getManifest(registryBase, repo, tag, opt === null || opt === void 0 ? void 0 : opt.username, opt === null || opt === void 0 ? void 0 : opt.password, opt === null || opt === void 0 ? void 0 : opt.reqOptions); | ||
const imageConfigMetadata = manifest.config; | ||
const imageConfig = await registryClient.getImageConfig(registryBase, repo, imageConfigMetadata.digest, username, password, reqOptions); | ||
const imageConfig = await registryClient.getImageConfig(registryBase, repo, imageConfigMetadata.digest, opt === null || opt === void 0 ? void 0 : opt.username, opt === null || opt === void 0 ? void 0 : opt.password, opt === null || opt === void 0 ? void 0 : opt.reqOptions); | ||
const t0 = Date.now(); | ||
const layersConfigs = manifest.layers; | ||
const missingLayers = await this.getLayers(layersConfigs, registryBase, username, password, repo, reqOptions); | ||
const missingLayers = await this.getLayers(layersConfigs, registryBase, repo, opt === null || opt === void 0 ? void 0 : opt.username, opt === null || opt === void 0 ? void 0 : opt.password, opt === null || opt === void 0 ? void 0 : opt.reqOptions); | ||
const pullDuration = Date.now() - t0; | ||
@@ -78,3 +76,3 @@ let imageDigest; | ||
} | ||
async getLayers(layersConfigs, registryBase, username, password, repo, | ||
async getLayers(layersConfigs, registryBase, repo, username, password, | ||
// weak typing on the client | ||
@@ -81,0 +79,0 @@ // eslint-disable-next-line @typescript-eslint/no-explicit-any |
@@ -1,1 +0,1 @@ | ||
export { DockerPull, DockerPullResult } from "./docker-pull"; | ||
export { DockerPull, DockerPullOptions, DockerPullResult } from "./docker-pull"; |
@@ -43,3 +43,3 @@ { | ||
}, | ||
"version": "2.1.1" | ||
"version": "3.0.0" | ||
} |
@@ -18,2 +18,14 @@ import { types } from "@snyk/docker-registry-v2-client"; | ||
export interface DockerPullOptions { | ||
username?: string; | ||
password?: string; | ||
// weak typing on the client | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
reqOptions?: any; | ||
/** | ||
* loadImage will default to true if no value is sent | ||
*/ | ||
loadImage?: boolean; | ||
} | ||
const DEFAULT_LAYER_JSON = { | ||
@@ -54,12 +66,8 @@ created: "0001-01-01T00:00:00Z", | ||
public async pull( | ||
username: string, | ||
password: string, | ||
registryBase: string, | ||
repo: string, | ||
tag: string, | ||
// weak typing on the client | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
reqOptions = {} as any, | ||
loadImage = true | ||
opt?: DockerPullOptions | ||
): Promise<DockerPullResult> { | ||
const loadImage = opt?.loadImage === undefined ? true : opt.loadImage; | ||
const manifest: types.ImageManifest = await registryClient.getManifest( | ||
@@ -69,5 +77,5 @@ registryBase, | ||
tag, | ||
username, | ||
password, | ||
reqOptions | ||
opt?.username, | ||
opt?.password, | ||
opt?.reqOptions | ||
); | ||
@@ -80,5 +88,5 @@ | ||
imageConfigMetadata.digest, | ||
username, | ||
password, | ||
reqOptions | ||
opt?.username, | ||
opt?.password, | ||
opt?.reqOptions | ||
); | ||
@@ -90,6 +98,6 @@ const t0 = Date.now(); | ||
registryBase, | ||
username, | ||
password, | ||
repo, | ||
reqOptions | ||
opt?.username, | ||
opt?.password, | ||
opt?.reqOptions | ||
); | ||
@@ -133,5 +141,5 @@ const pullDuration = Date.now() - t0; | ||
registryBase, | ||
username, | ||
password, | ||
repo: string, | ||
username?: string, | ||
password?: string, | ||
// weak typing on the client | ||
@@ -138,0 +146,0 @@ // eslint-disable-next-line @typescript-eslint/no-explicit-any |
@@ -1,1 +0,1 @@ | ||
export { DockerPull, DockerPullResult } from "./docker-pull"; | ||
export { DockerPull, DockerPullOptions, DockerPullResult } from "./docker-pull"; |
@@ -1,2 +0,2 @@ | ||
import { DockerPull } from "../../src/docker-pull"; | ||
import { DockerPull, DockerPullOptions } from "../../src/docker-pull"; | ||
import { removeImage } from "../utils"; | ||
@@ -9,15 +9,12 @@ import * as path from "path"; | ||
test("private image pull and load", async () => { | ||
const username = process.env.SNYK_DRA_DOCKER_HUB_USERNAME; | ||
const password = process.env.SNYK_DRA_DOCKER_HUB_PASSWORD; | ||
const repo = process.env.SNYK_DRA_DOCKER_HUB_REPOSITORY; | ||
const opt: DockerPullOptions = { | ||
username: process.env.SNYK_DRA_DOCKER_HUB_USERNAME, | ||
password: process.env.SNYK_DRA_DOCKER_HUB_PASSWORD | ||
}; | ||
const dockerPull: DockerPull = new DockerPull(); | ||
const imageDigest: string = ( | ||
await dockerPull.pull( | ||
username, | ||
password, | ||
"registry-1.docker.io", | ||
repo, | ||
"alpine" | ||
) | ||
await dockerPull.pull("registry-1.docker.io", repo, "alpine", opt) | ||
).imageDigest; | ||
@@ -30,17 +27,13 @@ expect(imageDigest).toBeDefined(); | ||
test("private image pull and build", async () => { | ||
const username = process.env.SNYK_DRA_DOCKER_HUB_USERNAME; | ||
const password = process.env.SNYK_DRA_DOCKER_HUB_PASSWORD; | ||
const repo = process.env.SNYK_DRA_DOCKER_HUB_REPOSITORY; | ||
const opt: DockerPullOptions = { | ||
username: process.env.SNYK_DRA_DOCKER_HUB_USERNAME, | ||
password: process.env.SNYK_DRA_DOCKER_HUB_PASSWORD, | ||
loadImage: false | ||
}; | ||
const dockerPull: DockerPull = new DockerPull(); | ||
const stagingDir = ( | ||
await dockerPull.pull( | ||
username, | ||
password, | ||
"registry-1.docker.io", | ||
repo, | ||
"alpine", | ||
{}, | ||
false | ||
) | ||
await dockerPull.pull("registry-1.docker.io", repo, "alpine", opt) | ||
).stagingDir; | ||
@@ -47,0 +40,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36019
662