Skip to content

Commit

Permalink
Clean-up logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Gario committed Aug 2, 2024
1 parent dc92ab6 commit 3b3012e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
16 changes: 9 additions & 7 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.

18 changes: 11 additions & 7 deletions src/start-proxy-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { pki } from "node-forge";

import * as actionsUtil from "./actions-util";
import * as util from "./util";
import { getActionsLogger, Logger } from "./logging";

const UPDATEJOB_PROXY = "update-job-proxy";
const UPDATEJOB_PROXY_VERSION = "v2.0.20240722180912";
Expand Down Expand Up @@ -89,13 +90,17 @@ function generateCertificateAuthority(): CertificateAuthority {
}

async function runWrapper() {
// Setup logging
const logger = getActionsLogger();

// Setup logging for the proxy
const tempDir = actionsUtil.getTemporaryDirectory();
const logFilePath = path.resolve(tempDir, "proxy.log");
core.saveState("proxy-log-file", logFilePath);
const proxyLogFilePath = path.resolve(tempDir, "proxy.log");
core.saveState("proxy-log-file", proxyLogFilePath);

// Get the configuration options
const credentials = getCredentials();
logger.debug(`Credentials loaded for the following URLs:\n ${credentials.map(c => c.host).join("\n")}`)

const ca = generateCertificateAuthority();
const proxyAuth = getProxyAuth();

Expand All @@ -107,10 +112,10 @@ async function runWrapper() {

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

async function startProxy(binPath: string, config: ProxyConfig, logFilePath: string) {
async function startProxy(binPath: string, config: ProxyConfig, logFilePath: string, logger: Logger) {
const host = "127.0.0.1";
let port = 49152;
try {
Expand Down Expand Up @@ -148,7 +153,7 @@ async function startProxy(binPath: string, config: ProxyConfig, logFilePath: str
if (subprocessError) {
throw subprocessError;
}
core.info(`Proxy started on ${host}:${port}`);
logger.info(`Proxy started on ${host}:${port}`);
core.setOutput("proxy_host", host);
core.setOutput("proxy_port", port.toString());
core.setOutput("proxy_ca_certificate", config.ca.cert);
Expand All @@ -165,7 +170,6 @@ async function startProxy(binPath: string, config: ProxyConfig, logFilePath: str
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[];
}
Expand Down

0 comments on commit 3b3012e

Please sign in to comment.