Skip to content

Commit 7baf392

Browse files
committed
fixes
1 parent 5b34615 commit 7baf392

File tree

4 files changed

+43
-30
lines changed

4 files changed

+43
-30
lines changed

lib/start-proxy-action.js

+9-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/start-proxy-action.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/start-proxy-action.ts

+32-21
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import * as toolcache from "@actions/tool-cache";
66
import { pki } from "node-forge";
77

88
import * as actionsUtil from "./actions-util";
9-
import * as util from "./util";
109
import { getActionsLogger, Logger } from "./logging";
10+
import * as util from "./util";
1111

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

101101
// Get the configuration options
102102
const credentials = getCredentials(logger);
103-
logger.info(`Credentials loaded for the following registries:\n ${credentials.map(c => credentialToStr(c)).join("\n")}`);
103+
logger.info(
104+
`Credentials loaded for the following registries:\n ${credentials
105+
.map((c) => credentialToStr(c))
106+
.join("\n")}`,
107+
);
104108

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

119-
async function startProxy(binPath: string, config: ProxyConfig, logFilePath: string, logger: Logger) {
123+
async function startProxy(
124+
binPath: string,
125+
config: ProxyConfig,
126+
logFilePath: string,
127+
logger: Logger,
128+
) {
120129
const host = "127.0.0.1";
121130
let port = 49152;
122131
try {
@@ -170,10 +179,12 @@ async function startProxy(binPath: string, config: ProxyConfig, logFilePath: str
170179
// It prefers `registries_credentials` over `registry_secrets`.
171180
// If neither is set, it returns an empty array.
172181
function getCredentials(logger: Logger): Credential[] {
173-
const registriesCredentials = actionsUtil.getOptionalInput("registries_credentials");
182+
const registriesCredentials = actionsUtil.getOptionalInput(
183+
"registries_credentials",
184+
);
174185
const registrySecrets = actionsUtil.getOptionalInput("registry_secrets");
175186

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

188199
// Parse and validate the credentials
189200
const parsed = JSON.parse(credentialsStr) as Credential[];
190-
let out: Credential[] = []
191-
parsed.forEach(e => {
201+
const out: Credential[] = [];
202+
for (const e of parsed) {
192203
if (e.url === undefined && e.host === undefined) {
193-
throw "Invalid credentials - must specify host or url"
204+
throw new Error("Invalid credentials - must specify host or url");
194205
}
195206
out.push({
196-
type: e.type,
197-
host: e.host,
198-
url: e.url,
199-
username: e.username,
200-
password: e.password,
201-
token: e.token,
202-
})
203-
});
207+
type: e.type,
208+
host: e.host,
209+
url: e.url,
210+
username: e.username,
211+
password: e.password,
212+
token: e.token,
213+
});
214+
}
204215
return out;
205216
}
206217

207218
// getProxyAuth returns the authentication information for the proxy itself.
208-
function getProxyAuth(): BasicAuthCredentials | undefined{
219+
function getProxyAuth(): BasicAuthCredentials | undefined {
209220
const proxy_password = actionsUtil.getOptionalInput("proxy_password");
210221
if (proxy_password) {
211222
return {
212223
username: PROXY_USER,
213224
password: proxy_password,
214225
};
215226
}
216-
return ;
227+
return;
217228
}
218229

219-
220230
async function getProxyBinaryPath(): Promise<string> {
221231
let proxyBin = toolcache.find(UPDATEJOB_PROXY, UPDATEJOB_PROXY_VERSION);
222232
if (!proxyBin) {
@@ -233,8 +243,9 @@ async function getProxyBinaryPath(): Promise<string> {
233243
}
234244

235245
function credentialToStr(c: Credential): string {
236-
return `Type: ${c.type}; Host: ${c.host}; Url: ${c.url} Username: ${c.username}; Password: ${c.password !== undefined}; Token: ${c.token !== undefined}`
246+
return `Type: ${c.type}; Host: ${c.host}; Url: ${c.url} Username: ${
247+
c.username
248+
}; Password: ${c.password !== undefined}; Token: ${c.token !== undefined}`;
237249
}
238250

239-
240251
void runWrapper();

start-proxy/action.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: "CodeQL: Start proxy"
2-
description: "[Experimental] Start HTTP proxy server"
2+
description: "[Experimental] Start HTTP proxy server. This action is for internal GitHub used only and will change without notice."
33
author: "GitHub"
44
inputs:
55
registry_secrets:

0 commit comments

Comments
 (0)