Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
marcogario committed Aug 15, 2024
1 parent 5b34615 commit 7baf392
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 30 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.

53 changes: 32 additions & 21 deletions src/start-proxy-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import * as toolcache from "@actions/tool-cache";
import { pki } from "node-forge";

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

const UPDATEJOB_PROXY = "update-job-proxy";
const UPDATEJOB_PROXY_VERSION = "v2.0.20240722180912";
Expand Down Expand Up @@ -100,7 +100,11 @@ async function runWrapper() {

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

const ca = generateCertificateAuthority();
const proxyAuth = getProxyAuth();
Expand All @@ -116,7 +120,12 @@ async function runWrapper() {
await startProxy(proxyBin, proxyConfig, proxyLogFilePath, logger);
}

async function startProxy(binPath: string, config: ProxyConfig, logFilePath: string, logger: Logger) {
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 @@ -170,10 +179,12 @@ async function startProxy(binPath: string, config: ProxyConfig, logFilePath: str
// It prefers `registries_credentials` over `registry_secrets`.
// If neither is set, it returns an empty array.
function getCredentials(logger: Logger): Credential[] {
const registriesCredentials = actionsUtil.getOptionalInput("registries_credentials");
const registriesCredentials = actionsUtil.getOptionalInput(
"registries_credentials",
);
const registrySecrets = actionsUtil.getOptionalInput("registry_secrets");

var credentialsStr: string;
let credentialsStr: string;
if (registriesCredentials !== undefined) {
logger.info(`Using registries_credentials input.`);
credentialsStr = Buffer.from(registriesCredentials, "base64").toString();
Expand All @@ -187,36 +198,35 @@ function getCredentials(logger: Logger): Credential[] {

// Parse and validate the credentials
const parsed = JSON.parse(credentialsStr) as Credential[];
let out: Credential[] = []
parsed.forEach(e => {
const out: Credential[] = [];
for (const e of parsed) {
if (e.url === undefined && e.host === undefined) {
throw "Invalid credentials - must specify host or url"
throw new Error("Invalid credentials - must specify host or url");
}
out.push({
type: e.type,
host: e.host,
url: e.url,
username: e.username,
password: e.password,
token: e.token,
})
});
type: e.type,
host: e.host,
url: e.url,
username: e.username,
password: e.password,
token: e.token,
});
}
return out;
}

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


async function getProxyBinaryPath(): Promise<string> {
let proxyBin = toolcache.find(UPDATEJOB_PROXY, UPDATEJOB_PROXY_VERSION);
if (!proxyBin) {
Expand All @@ -233,8 +243,9 @@ async function getProxyBinaryPath(): Promise<string> {
}

function credentialToStr(c: Credential): string {
return `Type: ${c.type}; Host: ${c.host}; Url: ${c.url} Username: ${c.username}; Password: ${c.password !== undefined}; Token: ${c.token !== undefined}`
return `Type: ${c.type}; Host: ${c.host}; Url: ${c.url} Username: ${
c.username
}; Password: ${c.password !== undefined}; Token: ${c.token !== undefined}`;
}


void runWrapper();
2 changes: 1 addition & 1 deletion start-proxy/action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: "CodeQL: Start proxy"
description: "[Experimental] Start HTTP proxy server"
description: "[Experimental] Start HTTP proxy server. This action is for internal GitHub used only and will change without notice."
author: "GitHub"
inputs:
registry_secrets:
Expand Down

0 comments on commit 7baf392

Please sign in to comment.