Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter registry credentials by language #2680

Merged
merged 3 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 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.

14 changes: 14 additions & 0 deletions src/start-proxy-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ const PROXY_USER = "proxy_user";
const KEY_SIZE = 2048;
const KEY_EXPIRY_YEARS = 2;

const LANGUAGE_TO_REGISTRY_TYPE = {
"java-kotlin": "maven_repository",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should you add kotlin as a standalone language?

Also there is languages.ts, which is where we've traditionally added language-specific logic. I think I'd prefer to move this declaration to that file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've pushed a commit where this logic better integrates with languages.ts, by reusing the Language type defined there.

I am 50/50 on whether we should move this map there. The main reason against doing so is that this information is really only useful for the proxy action and even the names of the registry types are fairly arbitrary and dependent on the specifics of the proxy binary. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine if the logic doesn't go into language.ts.

java: "maven_repository",
csharp: "nuget_feed",
} as const;

type CertificateAuthority = {
cert: string;
key: string;
Expand Down Expand Up @@ -192,6 +198,7 @@ function getCredentials(logger: Logger): Credential[] {
"registries_credentials",
);
const registrySecrets = actionsUtil.getOptionalInput("registry_secrets");
const language = actionsUtil.getOptionalInput("language");

let credentialsStr: string;
if (registriesCredentials !== undefined) {
Expand All @@ -212,6 +219,13 @@ function getCredentials(logger: Logger): Credential[] {
if (e.url === undefined && e.host === undefined) {
throw new Error("Invalid credentials - must specify host or url");
}

// Filter credentials based on language if specified. `type` is the registry type.
// E.g., "maven_feed" for Java/Kotlin, "nuget_repository" for C#.
if (language && LANGUAGE_TO_REGISTRY_TYPE[language] !== e.type) {
continue;
}

out.push({
type: e.type,
host: e.host,
Expand Down
3 changes: 3 additions & 0 deletions start-proxy/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ inputs:
description: GitHub token to use for authenticating with this instance of GitHub, used to upload debug artifacts.
default: ${{ github.token }}
required: false
language:
description: The programming language to setup the proxy for the correct ecosystem
required: false
outputs:
proxy_host:
description: The IP address of the proxy
Expand Down
Loading