Skip to content

Commit

Permalink
Smaller fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
eoftedal committed Jan 18, 2024
1 parent f6dfee4 commit c658881
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
13 changes: 4 additions & 9 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function uploadContent(
});
}

export async function processToken(
async function processToken(
registryBaseUrl: string,
allowInsecure: InsecureRegistrySupport,
imagePath: string,
Expand All @@ -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;
Expand All @@ -195,7 +195,7 @@ export async function createRegistry(
auth?: string,
optimisticToRegistryCheck = false,
): Promise<Registry> {
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(
Expand Down

0 comments on commit c658881

Please sign in to comment.