Skip to content

Commit aac07d2

Browse files
committed
Include registry_types whenever CODEQL_PROXY_URLS is set
1 parent de57c4a commit aac07d2

3 files changed

Lines changed: 95 additions & 2 deletions

File tree

‎lib/entry-points.js‎

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/status-report.test.ts‎

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@ import * as sinon from "sinon";
33

44
import * as actionsUtil from "./actions-util";
55
import { Config } from "./config-utils";
6-
import { EnvVar } from "./environment";
6+
import { EnvVar, RegistryProxyVars } from "./environment";
77
import { BuiltInLanguage } from "./languages";
88
import { getRunnerLogger } from "./logging";
99
import { ToolsSource } from "./setup-codeql";
10+
import type { Registry } from "./start-proxy";
1011
import {
1112
ActionName,
1213
createInitWithConfigStatusReport,
1314
createStatusReportBase,
1415
getActionsStatus,
16+
getRegistryTypesFromEnv,
1517
InitStatusReport,
1618
InitWithConfigStatusReport,
1719
} from "./status-report";
@@ -20,11 +22,54 @@ import {
2022
setupActionsVars,
2123
createTestConfig,
2224
makeMacro,
25+
getTestEnv,
26+
RecordingLogger,
2327
} from "./testing-utils";
2428
import { BuildMode, ConfigurationError, withTmpDir, wrapError } from "./util";
2529

2630
setupTests(test);
2731

32+
test("getRegistryTypesFromEnv - gets unique registry types from environment", async (t) => {
33+
const logger = new RecordingLogger(true);
34+
const env = getTestEnv({
35+
[RegistryProxyVars.PROXY_URLS]: JSON.stringify([
36+
{ type: "git_source", url: "https://example.com" },
37+
{ type: "git_source", url: "https://github.com" },
38+
{ type: "docker_registry", url: "https://registry.example.com" },
39+
] satisfies Array<Partial<Registry>>),
40+
});
41+
42+
const result = getRegistryTypesFromEnv(logger, env);
43+
t.deepEqual(result, ["git_source", "docker_registry"].sort().join(","));
44+
});
45+
46+
test("getRegistryTypesFromEnv - returns undefined if the env var is not set", async (t) => {
47+
const logger = new RecordingLogger(true);
48+
const env = getTestEnv({});
49+
50+
const result = getRegistryTypesFromEnv(logger, env);
51+
t.is(result, undefined);
52+
});
53+
54+
test("getRegistryTypesFromEnv - returns undefined if the env var is not valid JSON", async (t) => {
55+
const logger = new RecordingLogger(true);
56+
const env = getTestEnv({ [RegistryProxyVars.PROXY_URLS]: "[" });
57+
58+
const result = getRegistryTypesFromEnv(logger, env);
59+
t.is(result, undefined);
60+
});
61+
62+
test("getRegistryTypesFromEnv - returns undefined if the env var is unexpected JSON", async (t) => {
63+
const logger = new RecordingLogger(true);
64+
const env = getTestEnv({
65+
// Top-level object rather than an array of objects.
66+
[RegistryProxyVars.PROXY_URLS]: JSON.stringify({ type: "git_source" }),
67+
});
68+
69+
const result = getRegistryTypesFromEnv(logger, env);
70+
t.is(result, undefined);
71+
});
72+
2873
function setupEnvironmentAndStub(tmpDir: string) {
2974
setupActionsVars(tmpDir, tmpDir, {
3075
GITHUB_EVENT_NAME: "dynamic",

‎src/status-report.ts‎

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ import type { ComputedInput, InputName } from "./config/inputs";
1717
import { parseRegistriesWithoutCredentials } from "./config/pack-registries";
1818
import type { DependencyCacheRestoreStatusReport } from "./dependency-caching";
1919
import { DocUrl } from "./doc-url";
20-
import { EnvVar } from "./environment";
20+
import { EnvVar, getEnv, ReadOnlyEnv, RegistryProxyVars } from "./environment";
2121
import { getRef } from "./git-utils";
2222
import type { Logger } from "./logging";
2323
import type { OverlayBaseDatabaseDownloadStats } from "./overlay/caching";
2424
import { getRepositoryNwo } from "./repository";
2525
import type { ToolsSource } from "./setup-codeql";
26+
import type { Registry } from "./start-proxy";
2627
import {
2728
ConfigurationError,
2829
getRequiredEnvParam,
@@ -268,6 +269,35 @@ export interface EventReport {
268269
started_at: string;
269270
}
270271

272+
/**
273+
* Attempts to retrieve a list of private registry types from the `CODEQL_PROXY_URLS` environment
274+
* variable and returns it as a comma-separated string if successful. Returns `undefined` otherwise.
275+
*/
276+
export function getRegistryTypesFromEnv(
277+
logger: Logger,
278+
env: ReadOnlyEnv = getEnv(),
279+
): string | undefined {
280+
// Try to get the value of the environment variable.
281+
const value = env.getOptional(RegistryProxyVars.PROXY_URLS);
282+
283+
if (value === undefined) {
284+
return undefined;
285+
}
286+
287+
// Try to parse the JSON we expect to find in it and return the comma-separated list of
288+
// (unique) registry types.
289+
try {
290+
const data = JSON.parse(value) as Registry[];
291+
const types = new Set(data.map((r) => r.type));
292+
return Array.from(types).sort().join(",");
293+
} catch (err) {
294+
logger.debug(
295+
`Failed to parse '${RegistryProxyVars.PROXY_URLS}' containing '${value}': ${getErrorMessage(err)}.`,
296+
);
297+
return undefined;
298+
}
299+
}
300+
271301
/**
272302
* Compose a StatusReport.
273303
*
@@ -330,6 +360,7 @@ export async function createStatusReportBase(
330360
job_name: jobName,
331361
job_run_uuid: jobRunUUID,
332362
ref,
363+
registry_types: getRegistryTypesFromEnv(logger),
333364
runner_os: runnerOs,
334365
started_at: workflowStartedAt,
335366
status,

0 commit comments

Comments
 (0)