From f2a415e34f61d5e081971262133681873cc2abdf Mon Sep 17 00:00:00 2001 From: Liora Milbaum <liora@lmb.co.il> Date: Sat, 29 Apr 2023 20:51:03 +0300 Subject: [PATCH] refactor(datasource/docker): Using URL module for improved readability (#21809) --- lib/modules/datasource/docker/common.ts | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/modules/datasource/docker/common.ts b/lib/modules/datasource/docker/common.ts index 6f6b6cdb8f..5dc02fb406 100644 --- a/lib/modules/datasource/docker/common.ts +++ b/lib/modules/datasource/docker/common.ts @@ -136,31 +136,33 @@ export async function getAuthHeaders( return opts.headers ?? null; } - let scope = `repository:${dockerRepository}:pull`; + const authUrl = new URL(`${authenticateHeader.params.realm}`); + // repo isn't known to server yet, so causing wrong scope `repository:user/image:pull` if ( is.string(authenticateHeader.params.scope) && !apiCheckUrl.endsWith('/v2/') ) { - scope = authenticateHeader.params.scope; + authUrl.searchParams.append('scope', authenticateHeader.params.scope); + } else { + authUrl.searchParams.append( + 'scope', + `repository:${dockerRepository}:pull` + ); } - let service = authenticateHeader.params.service; - if (is.string(service)) { - service = `service=${service}&`; - } else { - service = ``; + if (is.string(authenticateHeader.params.service)) { + authUrl.searchParams.append('service', authenticateHeader.params.service); } - const authUrl = `${authenticateHeader.params.realm}?${service}scope=${scope}`; logger.trace( - { registryHost, dockerRepository, authUrl }, + { registryHost, dockerRepository, authUrl: authUrl.href }, `Obtaining docker registry token` ); opts.noAuth = true; const authResponse = ( await http.getJson<{ token?: string; access_token?: string }>( - authUrl, + authUrl.href, opts ) ).body; -- GitLab