Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
dc92ab6
Consider registries_credentials as input
marcogario Jul 30, 2024
3b3012e
Clean-up logging
marcogario Aug 2, 2024
e4afb79
More debugging of credentials
marcogario Aug 13, 2024
f736881
Support URL
marcogario Aug 13, 2024
1bd7fdc
Merge remote-tracking branch 'origin/main' into marcogario/proxy_64
marcogario Aug 13, 2024
5b34615
Validate credentials input
marcogario Aug 15, 2024
7baf392
fixes
marcogario Aug 15, 2024
0b84d89
Try upload teh proxy logs
marcogario Aug 15, 2024
02328f9
Update changelog and version after v3.26.3
github-actions[bot] Aug 19, 2024
d615d5c
Update checked-in dependencies
github-actions[bot] Aug 19, 2024
339aada
Merge pull request #2432 from github/mergeback/v3.26.3-to-main-883d8588
henrymercer Aug 19, 2024
512e306
Merge pull request #2404 from github/marcogario/proxy_64
aibaars Aug 20, 2024
202b3b9
Stop checking disk usage for MacOS ARM with SIP disabled (#2434)
angelapwen Aug 20, 2024
4067cda
Add deprecation message to `add-snippets` input.
rvermeulen Aug 21, 2024
ec21b8f
Update changelog with deprecation.
rvermeulen Aug 21, 2024
d7c48ef
Add link to PR deprecating `add-snippets` to CHANGELOG.md
rvermeulen Aug 21, 2024
7388c47
Merge branch 'main' into rvermeulen/deprecate-add-snippets
rvermeulen Aug 21, 2024
72bc3f7
Address incorrect changelog location
rvermeulen Aug 21, 2024
ae01f80
Merge pull request #2436 from rvermeulen/rvermeulen/deprecate-add-sni…
rvermeulen Aug 21, 2024
e354359
Update changelog for v3.26.4
github-actions[bot] Aug 21, 2024
f0f3afe
Merge main into releases/v3 (#2437)
angelapwen Aug 21, 2024
a5b0999
Revert "Update version and changelog for v2.26.3"
github-actions[bot] Aug 21, 2024
a5a1c19
Revert "Update checked-in dependencies"
github-actions[bot] Aug 21, 2024
e9925c1
Merge remote-tracking branch 'origin/releases/v3' into backport-v2.26…
github-actions[bot] Aug 21, 2024
1de3044
Update version and changelog for v2.26.4
github-actions[bot] Aug 21, 2024
4799b0f
Update checked-in dependencies
github-actions[bot] Aug 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Consider registries_credentials as input
  • Loading branch information
marcogario committed Jul 30, 2024
commit dc92ab6239882e606e05bdd154915f887765d7f2
71 changes: 49 additions & 22 deletions lib/start-proxy-action.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/start-proxy-action.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

86 changes: 60 additions & 26 deletions src/start-proxy-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,46 +89,37 @@ function generateCertificateAuthority(): CertificateAuthority {
}

async function runWrapper() {
// Setup logging
const tempDir = actionsUtil.getTemporaryDirectory();
const logFilePath = path.resolve(tempDir, "proxy.log");
const input = actionsUtil.getOptionalInput("registry_secrets") || "[]";
const credentials = JSON.parse(input) as Credential[];
const ca = generateCertificateAuthority();
const proxy_password = actionsUtil.getOptionalInput("proxy_password");
core.saveState("proxy-log-file", logFilePath);

let proxy_auth: BasicAuthCredentials | undefined = undefined;
if (proxy_password) {
proxy_auth = {
username: PROXY_USER,
password: proxy_password,
};
}
// Get the configuration options
const credentials = getCredentials();
const ca = generateCertificateAuthority();
const proxyAuth = getProxyAuth();

const proxyConfig: ProxyConfig = {
all_credentials: credentials,
ca,
proxy_auth,
proxy_auth: proxyAuth,
};

// Start the Proxy
const proxyBin = await getProxyBinaryPath();
await startProxy(proxyBin, proxyConfig, logFilePath);
}

async function startProxy(binPath: string, config: ProxyConfig, logFilePath: string) {
const host = "127.0.0.1";
let proxyBin = toolcache.find(UPDATEJOB_PROXY, UPDATEJOB_PROXY_VERSION);
if (!proxyBin) {
const temp = await toolcache.downloadTool(UPDATEJOB_PROXY_URL);
const extracted = await toolcache.extractTar(temp);
proxyBin = await toolcache.cacheDir(
extracted,
UPDATEJOB_PROXY,
UPDATEJOB_PROXY_VERSION,
);
}
proxyBin = path.join(proxyBin, UPDATEJOB_PROXY);
let port = 49152;
try {
let subprocess: ChildProcess | undefined = undefined;
let tries = 5;
let subprocessError: Error | undefined = undefined;
while (tries-- > 0 && !subprocess && !subprocessError) {
subprocess = spawn(
proxyBin,
binPath,
["-addr", `${host}:${port}`, "-config", "-", "-logfile", logFilePath],
{
detached: true,
Expand All @@ -149,7 +140,7 @@ async function runWrapper() {
subprocess = undefined;
}
});
subprocess.stdin?.write(JSON.stringify(proxyConfig));
subprocess.stdin?.write(JSON.stringify(config));
subprocess.stdin?.end();
// Wait a little to allow the proxy to start
await util.delay(1000);
Expand All @@ -160,12 +151,55 @@ async function runWrapper() {
core.info(`Proxy started on ${host}:${port}`);
core.setOutput("proxy_host", host);
core.setOutput("proxy_port", port.toString());
core.setOutput("proxy_ca_certificate", ca.cert);
core.setOutput("proxy_ca_certificate", config.ca.cert);
} catch (error) {
core.setFailed(
`start-proxy action failed: ${util.wrapError(error).message}`,
);
}
}

// getCredentials returns registry credentials from action inputs.
// It prefers `registries_credentials` over `registry_secrets`.
// If neither is set, it returns an empty array.
function getCredentials(): Credential[] {
const encodedCredentials = actionsUtil.getOptionalInput("registries_credentials");
if (encodedCredentials !== undefined) {
core.info(`Using encoded credentials.`);
const credentialsStr = Buffer.from(encodedCredentials, "base64").toString();
return JSON.parse(credentialsStr) as Credential[];
}
core.info(`Using structured credentials.`);
const registrySecrets = actionsUtil.getOptionalInput("registry_secrets") || "[]";
return JSON.parse(registrySecrets) as Credential[];
}

// getProxyAuth returns the authentication information for the proxy itself.
function getProxyAuth(): BasicAuthCredentials | undefined{
const proxy_password = actionsUtil.getOptionalInput("proxy_password");
if (proxy_password) {
return {
username: PROXY_USER,
password: proxy_password,
};
}
return ;
}


async function getProxyBinaryPath(): Promise<string> {
let proxyBin = toolcache.find(UPDATEJOB_PROXY, UPDATEJOB_PROXY_VERSION);
if (!proxyBin) {
const temp = await toolcache.downloadTool(UPDATEJOB_PROXY_URL);
const extracted = await toolcache.extractTar(temp);
proxyBin = await toolcache.cacheDir(
extracted,
UPDATEJOB_PROXY,
UPDATEJOB_PROXY_VERSION,
);
}
proxyBin = path.join(proxyBin, UPDATEJOB_PROXY);
return proxyBin;
}

void runWrapper();
3 changes: 3 additions & 0 deletions start-proxy/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ inputs:
description: The URLs and credentials of package registries
required: false
default: "[]"
registries_credentials:
description: Base64 encoded JSON configuration for the URLs and credentials of the package registries
required: false
proxy_password:
required: false
description: The password of the proxy
Expand Down