Skip to content

Commit c4545c3

Browse files
committed
Add allow list option to setup-foreman
1 parent b1303c6 commit c4545c3

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ inputs:
1717
allow-external-github-orgs:
1818
required: false
1919
description: 'Allow installing from external GitHub organizations'
20+
github-orgs-allow-list:
21+
required: false
22+
description: 'Comma separated list of orgs that are allowed even if external orgs are not allowed'
2023
artifactory-url:
2124
required: false
2225
description: 'Artifactory URL to use for downloading Foreman tools'

src/configFile.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ const MANIFEST = "foreman.toml";
1818

1919
function checkSameOrgToolSpecs(
2020
manifestContent: foremanConfig,
21-
org: string
21+
org: string,
22+
allowList: string[]
2223
): boolean {
2324
const tools = manifestContent.tools;
2425
if (tools == null) {
@@ -44,13 +45,13 @@ function checkSameOrgToolSpecs(
4445
);
4546
}
4647
if (tool_org.toLowerCase() != org) {
47-
return false;
48+
return allowList.includes(tool_org.toLowerCase())
4849
}
4950
}
5051
return true;
5152
}
5253

53-
async function checkSameOrgInConfig(org: string): Promise<void> {
54+
async function checkSameOrgInConfig(org: string, allowList: string[]): Promise<void> {
5455
const manifestPath = await findUp(MANIFEST);
5556
if (manifestPath == undefined) {
5657
throw new Error("setup-foreman could not find Foreman config file");
@@ -63,7 +64,7 @@ async function checkSameOrgInConfig(org: string): Promise<void> {
6364
);
6465
}
6566
const manifestContent = parse(data);
66-
const sameGithubOrgSource = checkSameOrgToolSpecs(manifestContent, org);
67+
const sameGithubOrgSource = checkSameOrgToolSpecs(manifestContent, org, allowList);
6768
if (!sameGithubOrgSource) {
6869
throw new Error(
6970
`All GitHub orgs in Foreman config must match the org setup-foreman runs in: ${org}. To disable this check, set the \"allow-external-github-orgs\" option to true.`

src/main.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ async function run(): Promise<void> {
1919
const allowExternalGithubOrgs: string = getInput(
2020
"allow-external-github-orgs"
2121
).toLowerCase();
22+
const githubOrgsAllowList: string[] = getInput(
23+
"github-orgs-allow-list"
24+
).split(",").map((org: string) => org.trim().toLowerCase()).filter((org) => org !== "");
2225
const artifactoryUrl = getInput("artifactory-url");
2326
const artifactoryToken = getInput("artifactory-token");
2427

@@ -85,7 +88,7 @@ async function run(): Promise<void> {
8588
`Could not find repository owner setup-foreman is running in`
8689
);
8790
}
88-
configFile.checkSameOrgInConfig(owner.toLowerCase());
91+
configFile.checkSameOrgInConfig(owner.toLowerCase(), githubOrgsAllowList);
8992
}
9093

9194
await foreman.installTools();

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"compilerOptions": {
3-
"target": "es6",
3+
"target": "es2016",
44
"module": "commonjs",
55
"outDir": "./lib",
66
"rootDir": "./src",

0 commit comments

Comments
 (0)