Skip to content

Commit

Permalink
Fix fetching registry credentials when using Gcloud cred helper (#764)
Browse files Browse the repository at this point in the history
  • Loading branch information
HiranmayaGundu committed Jul 13, 2024
1 parent c7df5ff commit 3830959
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,23 @@ describe("CredentialProvider", () => {
).toBeUndefined();
});

it("should default to the registry url when the server url is not returned", async () => {
mockExecReturns(JSON.stringify({ "https://registry.example.com": "username" }));
mockSpawnReturns(
0,
JSON.stringify({
Username: "username",
Secret: "secret",
})
);

expect(await credentialProvider.getAuthConfig("https://registry.example.com", containerRuntimeConfig)).toEqual({
registryAddress: "https://registry.example.com",
username: "username",
password: "secret",
});
});

it("should return undefined when no auth config found for registry", async () => {
mockExecReturns(JSON.stringify({ registry2: "username" }));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ export abstract class CredentialProvider implements RegistryAuthLocator {
log.debug(`Executing Docker credential provider "${programName}"`);

const credentials = await this.listCredentials(programName);
if (!Object.keys(credentials).some((aRegistry) => registryMatches(aRegistry, registry))) {

const credentialForRegistry = Object.keys(credentials).find((aRegistry) => registryMatches(aRegistry, registry));
if (!credentialForRegistry) {
log.debug(`No credential found for registry "${registry}"`);
return undefined;
}
Expand All @@ -34,7 +36,7 @@ export abstract class CredentialProvider implements RegistryAuthLocator {
return {
username: response.Username,
password: response.Secret,
registryAddress: response.ServerURL,
registryAddress: response.ServerURL ?? credentialForRegistry,
};
}

Expand Down

0 comments on commit 3830959

Please sign in to comment.