diff --git a/lib/start-proxy-action.js b/lib/start-proxy-action.js index 5881cacead..8d101315aa 100644 --- a/lib/start-proxy-action.js +++ b/lib/start-proxy-action.js @@ -47817,13 +47817,13 @@ function parseLanguage(language) { return void 0; } var LANGUAGE_TO_REGISTRY_TYPE = { - java: "maven_repository", - csharp: "nuget_feed", - javascript: "npm_registry", - python: "python_index", - ruby: "rubygems_server", - rust: "cargo_registry", - go: "goproxy_server" + java: ["maven_repository"], + csharp: ["nuget_feed"], + javascript: ["npm_registry"], + python: ["python_index"], + ruby: ["rubygems_server"], + rust: ["cargo_registry"], + go: ["goproxy_server", "git_source"] }; function isDefined(value) { return value !== void 0 && value !== null; @@ -47870,7 +47870,7 @@ function getCredentials(logger, registrySecrets, registriesCredentials, language "Invalid credentials - must specify host or url" ); } - if (registryTypeForLanguage && e.type !== registryTypeForLanguage) { + if (registryTypeForLanguage && !registryTypeForLanguage.some((t) => t === e.type)) { continue; } const isPrintable2 = (str2) => { diff --git a/src/start-proxy.test.ts b/src/start-proxy.test.ts index c9682edcf5..3e2748aaf9 100644 --- a/src/start-proxy.test.ts +++ b/src/start-proxy.test.ts @@ -11,6 +11,14 @@ setupTests(test); const toEncodedJSON = (data: any) => Buffer.from(JSON.stringify(data)).toString("base64"); +const mixedCredentials = [ + { type: "npm_registry", host: "npm.pkg.github.com", token: "abc" }, + { type: "maven_repository", host: "maven.pkg.github.com", token: "def" }, + { type: "nuget_feed", host: "nuget.pkg.github.com", token: "ghi" }, + { type: "goproxy_server", host: "goproxy.example.com", token: "jkl" }, + { type: "git_source", host: "github.com/github", token: "mno" }, +]; + test("getCredentials prefers registriesCredentials over registrySecrets", async (t) => { const registryCredentials = Buffer.from( JSON.stringify([ @@ -94,13 +102,6 @@ test("getCredentials throws error when credential missing host and url", async ( }); test("getCredentials filters by language when specified", async (t) => { - const mixedCredentials = [ - { type: "npm_registry", host: "npm.pkg.github.com", token: "abc" }, - { type: "maven_repository", host: "maven.pkg.github.com", token: "def" }, - { type: "nuget_feed", host: "nuget.pkg.github.com", token: "ghi" }, - { type: "goproxy_server", host: "goproxy.example.com", token: "jkl" }, - ]; - const credentials = startProxyExports.getCredentials( getRunnerLogger(true), undefined, @@ -111,13 +112,21 @@ test("getCredentials filters by language when specified", async (t) => { t.is(credentials[0].type, "maven_repository"); }); +test("getCredentials returns all for a language when specified", async (t) => { + const credentials = startProxyExports.getCredentials( + getRunnerLogger(true), + undefined, + toEncodedJSON(mixedCredentials), + "go", + ); + t.is(credentials.length, 2); + + const credentialsTypes = credentials.map((c) => c.type); + t.assert(credentialsTypes.includes("goproxy_server")); + t.assert(credentialsTypes.includes("git_source")); +}); + test("getCredentials returns all credentials when no language specified", async (t) => { - const mixedCredentials = [ - { type: "npm_registry", host: "npm.pkg.github.com", token: "abc" }, - { type: "maven_repository", host: "maven.pkg.github.com", token: "def" }, - { type: "nuget_feed", host: "nuget.pkg.github.com", token: "ghi" }, - { type: "goproxy_server", host: "goproxy.example.com", token: "jkl" }, - ]; const credentialsInput = toEncodedJSON(mixedCredentials); const credentials = startProxyExports.getCredentials( diff --git a/src/start-proxy.ts b/src/start-proxy.ts index d74884bfd4..0532e68f0d 100644 --- a/src/start-proxy.ts +++ b/src/start-proxy.ts @@ -55,14 +55,14 @@ export function parseLanguage(language: string): KnownLanguage | undefined { return undefined; } -const LANGUAGE_TO_REGISTRY_TYPE: Partial> = { - java: "maven_repository", - csharp: "nuget_feed", - javascript: "npm_registry", - python: "python_index", - ruby: "rubygems_server", - rust: "cargo_registry", - go: "goproxy_server", +const LANGUAGE_TO_REGISTRY_TYPE: Partial> = { + java: ["maven_repository"], + csharp: ["nuget_feed"], + javascript: ["npm_registry"], + python: ["python_index"], + ruby: ["rubygems_server"], + rust: ["cargo_registry"], + go: ["goproxy_server", "git_source"], } as const; /** @@ -140,7 +140,10 @@ export function getCredentials( // Filter credentials based on language if specified. `type` is the registry type. // E.g., "maven_feed" for Java/Kotlin, "nuget_repository" for C#. - if (registryTypeForLanguage && e.type !== registryTypeForLanguage) { + if ( + registryTypeForLanguage && + !registryTypeForLanguage.some((t) => t === e.type) + ) { continue; }