@@ -24,6 +24,18 @@ import {
2424 RawCredential ,
2525 Registry ,
2626 Credential ,
27+ AuthConfig ,
28+ isToken ,
29+ isAzureConfig ,
30+ Token ,
31+ UsernamePassword ,
32+ AzureConfig ,
33+ isAWSConfig ,
34+ AWSConfig ,
35+ isJFrogConfig ,
36+ JFrogConfig ,
37+ isUsernamePassword ,
38+ hasUsername ,
2739} from "./start-proxy/types" ;
2840import {
2941 ActionName ,
@@ -274,6 +286,54 @@ function getRegistryAddress(registry: Partial<Registry>): Address {
274286 }
275287}
276288
289+ /** Extracts an `AuthConfig` value from `config`. */
290+ export function getAuthConfig ( config : Partial < AuthConfig > ) : AuthConfig {
291+ // Start by checking for the OIDC configurations, since they have required properties
292+ // which we can use to identify them.
293+ if ( isAzureConfig ( config ) ) {
294+ return {
295+ tenant_id : config . tenant_id ,
296+ client_id : config . client_id ,
297+ } satisfies AzureConfig ;
298+ } else if ( isAWSConfig ( config ) ) {
299+ return {
300+ aws_region : config . aws_region ,
301+ account_id : config . account_id ,
302+ role_name : config . role_name ,
303+ domain : config . domain ,
304+ domain_owner : config . domain_owner ,
305+ audience : config . audience ,
306+ } satisfies AWSConfig ;
307+ } else if ( isJFrogConfig ( config ) ) {
308+ return {
309+ jfrog_oidc_provider_name : config . jfrog_oidc_provider_name ,
310+ identity_mapping_name : config . identity_mapping_name ,
311+ audience : config . audience ,
312+ } satisfies JFrogConfig ;
313+ } else if ( isToken ( config ) ) {
314+ // For token-based authentication, both the token and username are optional.
315+ // If the token is absent, then it doesn't matter if we end up treating it
316+ // as a `UsernamePassword` object internally.
317+
318+ // Mask token to reduce chance of accidental leakage in logs, if we have one.
319+ if ( isDefined ( config . token ) ) {
320+ core . setSecret ( config . token ) ;
321+ }
322+
323+ return { username : config . username , token : config . token } satisfies Token ;
324+ } else {
325+ // Mask password to reduce chance of accidental leakage in logs, if we have one.
326+ if ( "password" in config && isDefined ( config . password ) ) {
327+ core . setSecret ( config . password ) ;
328+ }
329+
330+ return {
331+ username : "username" in config ? config . username : undefined ,
332+ password : "password" in config ? config . password : undefined ,
333+ } satisfies UsernamePassword ;
334+ }
335+ }
336+
277337// getCredentials returns registry credentials from action inputs.
278338// It prefers `registries_credentials` over `registry_secrets`.
279339// If neither is set, it returns an empty array.
@@ -332,13 +392,7 @@ export function getCredentials(
332392 }
333393
334394 // Mask credentials to reduce chance of accidental leakage in logs.
335- if ( isDefined ( e . password ) ) {
336- core . setSecret ( e . password ) ;
337- }
338- if ( isDefined ( e . token ) ) {
339- core . setSecret ( e . token ) ;
340- }
341-
395+ const authConfig = getAuthConfig ( e ) ;
342396 const address = getRegistryAddress ( e ) ;
343397
344398 // Filter credentials based on language if specified. `type` is the registry type.
@@ -366,9 +420,13 @@ export function getCredentials(
366420
367421 // If the password or token looks like a GitHub PAT, warn if no username is configured.
368422 if (
369- ! isDefined ( e . username ) &&
370- ( ( isDefined ( e . password ) && isPAT ( e . password ) ) ||
371- ( isDefined ( e . token ) && isPAT ( e . token ) ) )
423+ ( ( ! hasUsername ( authConfig ) || ! isDefined ( authConfig . username ) ) &&
424+ isUsernamePassword ( authConfig ) &&
425+ isDefined ( authConfig . password ) &&
426+ isPAT ( authConfig . password ) ) ||
427+ ( isToken ( authConfig ) &&
428+ isDefined ( authConfig . token ) &&
429+ isPAT ( authConfig . token ) )
372430 ) {
373431 logger . warning (
374432 `A ${ e . type } private registry is configured for ${ e . host || e . url } using a GitHub Personal Access Token (PAT), but no username was provided. ` +
@@ -379,9 +437,7 @@ export function getCredentials(
379437
380438 out . push ( {
381439 type : e . type ,
382- username : e . username ,
383- password : e . password ,
384- token : e . token ,
440+ ...authConfig ,
385441 ...address ,
386442 } ) ;
387443 }
0 commit comments