Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

null coalesce when detecting docker cred helpers #481

Merged
merged 2 commits into from
Apr 5, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
null coalesce when detecting docker cred helpers (#477)
  • Loading branch information
joshspicer committed Apr 5, 2023
commit 46b9bb6b960acd67c9978cdf1c0fa24c675431bd
8 changes: 4 additions & 4 deletions src/spec-configuration/httpOCIRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ async function getCredential(params: CommonParams, ociRef: OCIRef | OCICollectio
if (await isLocalFile(dockerConfigPath)) {
const dockerConfig: DockerConfigFile = jsonc.parse((await readLocalFile(dockerConfigPath)).toString());

configContainsAuth = Object.keys(dockerConfig.credHelpers).length > 0 || !!dockerConfig.credsStore || Object.keys(dockerConfig.auths).length > 0;
configContainsAuth = Object.keys(dockerConfig.credHelpers ?? {}).length > 0 || !!dockerConfig.credsStore || Object.keys(dockerConfig.auths ?? {}).length > 0;
if (dockerConfig.credHelpers && dockerConfig.credHelpers[registry]) {
const credHelper = dockerConfig.credHelpers[registry];
output.write(`[httpOci] Found credential helper '${credHelper}' in '${dockerConfigPath}' registry '${registry}'`, LogLevel.Trace);
Expand Down Expand Up @@ -259,14 +259,14 @@ async function existsInPath(filename: string): Promise<boolean> {
return false;
}

async function getCredentialFromHelper(params: CommonParams, registry: string, credHelperName: string) : Promise<{ base64EncodedCredential: string | undefined; refreshToken: string | undefined } | undefined>{
async function getCredentialFromHelper(params: CommonParams, registry: string, credHelperName: string): Promise<{ base64EncodedCredential: string | undefined; refreshToken: string | undefined } | undefined> {
const { output } = params;

let helperOutput: Buffer;
try {
const { stdout } = await runCommandNoPty({
exec: plainExec(undefined),
cmd: 'docker-credential-'+credHelperName,
cmd: 'docker-credential-' + credHelperName,
args: ['get'],
stdin: Buffer.from(registry, 'utf-8'),
output,
Expand All @@ -281,7 +281,7 @@ async function getCredentialFromHelper(params: CommonParams, registry: string, c
}

let errors: jsonc.ParseError[] = [];
const creds:CredentialHelperResult = jsonc.parse(helperOutput.toString(), errors);
const creds: CredentialHelperResult = jsonc.parse(helperOutput.toString(), errors);
if (errors.length !== 0) {
output.write(`[httpOci] Credential helper ${credHelperName} returned non-JSON response "${helperOutput.toString()}" for registry ${registry}`, LogLevel.Warning);
return undefined;
Expand Down