diff --git a/src/cli.ts b/src/cli.ts index b6affc8..fb60d1e 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -6,14 +6,14 @@ import * as path from "path"; import * as fse from "fs-extra"; import * as fs from "fs"; -import { DEFAULT_DOCKER_REGISTRY, createRegistry, processToken, parseFullImageUrl } from "./registry"; +import { DEFAULT_DOCKER_REGISTRY, createRegistry, parseFullImageUrl } from "./registry"; import appLayerCreator from "./appLayerCreator"; import dockerExporter from "./dockerExporter"; import tarExporter from "./tarExporter"; import logger from "./logger"; import { InsecureRegistrySupport, Options } from "./types"; -import {omit, getPreferredPlatform, parseImage} from "./utils"; +import { omit, getPreferredPlatform } from "./utils"; import { ensureEmptyDir } from "./fileutil"; import { VERSION } from "./version"; @@ -282,12 +282,7 @@ async function run(options: Options) { const todir = await ensureEmptyDir(path.join(tmpdir, "to")); const allowInsecure = options.allowInsecureRegistries ? InsecureRegistrySupport.YES : InsecureRegistrySupport.NO; const fromRegistryUrl = options.fromRegistry ?? DEFAULT_DOCKER_REGISTRY; - const fromRegistry = await createRegistry( - fromRegistryUrl, - options.fromImage, - allowInsecure, - options.fromToken, - ); + const fromRegistry = await createRegistry(fromRegistryUrl, options.fromImage, allowInsecure, options.fromToken); const originalManifest = await fromRegistry.download( options.fromImage, fromdir, @@ -310,7 +305,7 @@ async function run(options: Options) { } if (options.toRegistry) { if (!options.token && allowInsecure == InsecureRegistrySupport.NO) { - throw new Error("Need auth token to upload to " + options.toRegistry) + throw new Error("Need auth token to upload to " + options.toRegistry); } const toRegistry = await createRegistry( options.toRegistry, diff --git a/src/registry.ts b/src/registry.ts index b5f0ba0..a54830e 100644 --- a/src/registry.ts +++ b/src/registry.ts @@ -151,7 +151,7 @@ function uploadContent( }); } -export async function processToken( +async function processToken( registryBaseUrl: string, allowInsecure: InsecureRegistrySupport, imagePath: string, @@ -178,7 +178,7 @@ export async function processToken( ); return `Bearer ${resp.token}`; } - if (!token) return "" + if (!token) return ""; //We allow to pull from tokenless registries if (token.startsWith("Basic ")) return token; if (token.startsWith("ghp_")) return "Bearer " + Buffer.from(token).toString("base64"); return "Bearer " + token; @@ -195,7 +195,7 @@ export async function createRegistry( auth?: string, optimisticToRegistryCheck = false, ): Promise { - const token = await processToken(registryBaseUrl, allowInsecure, imagePath, auth) + const token = await processToken(registryBaseUrl, allowInsecure, imagePath, auth); async function exists(image: Image, layer: Layer) { const url = `${registryBaseUrl}${image.path}/blobs/${layer.digest}`; return await checkIfLayerExists(