Skip to content

Commit

Permalink
use env based credentials first for docker
Browse files Browse the repository at this point in the history
Signed-off-by: Prabhu Subramanian <prabhu@appthreat.com>
  • Loading branch information
prabhu committed Nov 20, 2023
1 parent 0b53f6a commit eebe399
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ if (
isContainerd = true;
}

// Cache the registry auth keys
const registry_auth_keys = {};

/**
* Method to get all dirs matching a name
*
Expand Down Expand Up @@ -1084,6 +1087,9 @@ export const removeImage = async (fullImageName, force = false) => {
};

export const getCredsFromHelper = (exeSuffix, serverAddress) => {
if (registry_auth_keys[serverAddress]) {
return registry_auth_keys[serverAddress];
}
let credHelperExe = `docker-credential-${exeSuffix}`;
if (isWin) {
credHelperExe = credHelperExe + ".exe";
Expand All @@ -1098,7 +1104,12 @@ export const getCredsFromHelper = (exeSuffix, serverAddress) => {
} else if (result.stdout) {
const cmdOutput = Buffer.from(result.stdout).toString();
try {
return JSON.parse(cmdOutput);
const authPayload = JSON.parse(cmdOutput);
const authKey = Buffer.from(JSON.stringify(authPayload)).toString(
"base64"
);
registry_auth_keys[serverAddress] = authKey;
return authKey;
} catch (err) {
return undefined;
}
Expand Down

0 comments on commit eebe399

Please sign in to comment.