Skip to content

Commit 225c78f

Browse files
authored
null coalesce when detecting docker cred helpers (#481)
* null coalesce when detecting docker cred helpers (#477) * remove whitespace
1 parent 19f369f commit 225c78f

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

src/spec-configuration/httpOCIRegistry.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ async function getCredential(params: CommonParams, ociRef: OCIRef | OCICollectio
177177
if (await isLocalFile(dockerConfigPath)) {
178178
const dockerConfig: DockerConfigFile = jsonc.parse((await readLocalFile(dockerConfigPath)).toString());
179179

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

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

265265
let helperOutput: Buffer;
266266
try {
267267
const { stdout } = await runCommandNoPty({
268268
exec: plainExec(undefined),
269-
cmd: 'docker-credential-'+credHelperName,
269+
cmd: 'docker-credential-' + credHelperName,
270270
args: ['get'],
271271
stdin: Buffer.from(registry, 'utf-8'),
272272
output,
@@ -281,7 +281,7 @@ async function getCredentialFromHelper(params: CommonParams, registry: string, c
281281
}
282282

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

0 commit comments

Comments
 (0)