Skip to content

Commit

Permalink
Update packages. Support for private docker registry
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 15, 2023
1 parent d57cbbc commit 0586b06
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 93 deletions.
2 changes: 1 addition & 1 deletion analyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ const setFileRef = (allImports, src, file, pathnode, specifiers = []) => {
}
const fileRelativeLoc = relative(src, file);
// remove unexpected extension imports
if (/\.(svg|png|jpg|d\.ts)/.test(pathway)) {
if (/\.(svg|png|jpg|json|d\.ts)/.test(pathway)) {
return;
}
const importedModules = specifiers
Expand Down
58 changes: 56 additions & 2 deletions docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,60 @@ const getDefaultOptions = () => {
hooks: { beforeError: [] },
mutableDefaults: true
};
// Support for private registry
if (existsSync(join(homedir(), ".docker", "config.json"))) {
const configData = readFileSync(
join(homedir(), ".docker", "config.json"),
"utf-8"
);
if (configData) {
try {
const configJson = JSON.parse(configData);
if (configJson.auths) {
for (const serverAddress of Object.keys(configJson.auths)) {
if (
process.env.DOCKER_SERVER_ADDRESS &&
process.env.DOCKER_SERVER_ADDRESS.trim().length &&
process.env.DOCKER_SERVER_ADDRESS !== serverAddress
) {
continue;
}
if (configJson.auths[serverAddress].auth) {
opts.headers = {
"X-Registry-Auth": configJson.auths[serverAddress].auth
};
console.log(
`Using the existing authentication token for the docker server ${serverAddress}`
);
break;
}
}
}
} catch (err) {
// pass
}
}
} else if (process.env.DOCKER_AUTH_CONFIG) {
opts.headers = {
"X-Registry-Auth": process.env.DOCKER_AUTH_CONFIG
};
} else if (
process.env.DOCKER_USER &&
process.env.DOCKER_PASSWORD &&
process.env.DOCKER_EMAIL &&
process.env.DOCKER_SERVER_ADDRESS
) {
opts.headers = {
"X-Registry-Auth": Buffer.from(
JSON.stringify({
username: process.env.DOCKER_USER,
password: process.env.DOCKER_PASSWORD,
email: process.env.DOCKER_EMAIL,
serveraddress: process.env.DOCKER_SERVER_ADDRESS
})
).toString("base64")
};
}
const userInfo = _userInfo();
opts.podmanPrefixUrl = isWin ? "" : `http://unix:/run/podman/podman.sock:`;
opts.podmanRootlessPrefixUrl = isWin
Expand All @@ -126,8 +180,8 @@ const getDefaultOptions = () => {
opts.prefixUrl = isWin
? WIN_LOCAL_TLS
: isDockerRootless
? `http://unix:${homedir()}/.docker/run/docker.sock:`
: "http://unix:/var/run/docker.sock:";
? `http://unix:${homedir()}/.docker/run/docker.sock:`
: "http://unix:/var/run/docker.sock:";
}
}
} else {
Expand Down
Loading

0 comments on commit 0586b06

Please sign in to comment.