@@ -47,16 +47,12 @@ async function download(vsn, plat) {
4747async function setupConfig ( vsn ) {
4848 let conf = core . getInput ( 'config' ) ;
4949 if ( ! conf ) {
50- if ( ! core . getInput ( "email" ) ) {
51- if ( ! process . env . PLURAL_CONSOLE_TOKEN ) {
52- core . info ( "if you want to use `plural cd` commands you need to set $PLURAL_CONSOLE_TOKEN and $PLURAL_CONSOLE_URL" )
53- }
50+ if ( ! core . getInput ( "email" ) && core . getInput ( "consoleUrl" ) ) {
5451 return
5552 }
5653
5754 if ( cmp ( vsn , '0.7.0' ) >= 0 ) {
5855 await setupTempConfig ( )
59- setOutput ( )
6056 } else {
6157 core . setFailed ( "you must use versions greater than 0.7.0 with temporary credentials" )
6258 }
@@ -76,25 +72,61 @@ async function setupConfig(vsn) {
7672async function setupTempConfig ( ) {
7773 const token = await core . getIDToken ( )
7874 const email = core . getInput ( 'email' )
75+ const consoleUrl = core . getInput ( 'consoleUrl' )
76+ if ( consoleUrl ) {
77+ return
78+ }
79+
7980 if ( ! email ) {
8081 core . info ( "`email` is required when authenticating with oidc" )
8182 return
8283 }
8384 const claims = jwt_decode ( token )
8485 core . info ( `logging in with jwt subject: ${ claims . sub } ` )
8586 await exec . exec ( `plural auth oidc github_actions --token ${ token } --email ${ email } ` )
87+ setOutput ( )
88+ }
89+
90+ async function getConsoleOIDCToken ( url , email ) {
91+ const token = await core . getIDToken ( )
92+ const claims = jwt_decode ( token )
93+ core . info ( `logging in with jwt subject: ${ claims . sub } ` )
94+
95+ const response = await fetch ( path . join ( url , 'v1/token/exchange' ) , {
96+ method : 'POST' ,
97+ headers : { 'Content-Type' : 'application/json' } ,
98+ body : JSON . stringify ( { email, jwt : token } ) ,
99+ } )
100+ if ( ! response . ok ) {
101+ const body = await response . text ( )
102+ core . setFailed ( `failed to exchange token: ${ response . status } ${ body } ` )
103+ return null
104+ }
105+ const data = await response . json ( )
106+ return data . access_token
86107}
87108
88109async function setupConsoleLogin ( ) {
89- const consoleToken = core . getInput ( 'console_token' ) ;
90- const consoleUrl = core . getInput ( 'console_url' ) ;
110+ let consoleToken = core . getInput ( 'consoleToken' ) ;
111+ const consoleUrl = core . getInput ( 'consoleUrl' ) ;
112+ const email = core . getInput ( 'email' ) ;
113+
114+ if ( consoleUrl && email && ! consoleToken ) {
115+ consoleToken = await getConsoleOIDCToken ( consoleUrl , email )
116+ if ( ! consoleToken ) {
117+ return
118+ }
119+ }
91120
92121 if ( consoleToken && consoleUrl ) {
93122 core . exportVariable ( 'PLURAL_CONSOLE_TOKEN' , consoleToken ) ;
94123 core . exportVariable ( 'PLURAL_CONSOLE_URL' , consoleUrl ) ;
95- core . info ( 'Console authentication configured with provided token and URL' ) ;
96- } else if ( consoleToken || consoleUrl ) {
97- core . setFailed ( 'Both console_token and console_url must be provided together' ) ;
124+ core . setSecret ( consoleToken )
125+ core . setOutput ( 'consoleToken' , consoleToken )
126+ core . setOutput ( 'consoleUrl' , consoleUrl )
127+ core . info ( 'Console authentication configured!' ) ;
128+ } else if ( consoleUrl ) {
129+ core . setFailed ( 'Both consoleToken and consoleUrl must be provided together' ) ;
98130 }
99131}
100132
@@ -104,9 +136,8 @@ function setOutput() {
104136 const token = config ?. spec ?. token || config ?. token
105137 if ( token ) {
106138 core . setSecret ( token )
139+ core . setOutput ( 'token' , config ?. spec ?. token || config ?. token )
107140 }
108-
109- core . setOutput ( 'token' , config ?. spec ?. token || config ?. token )
110141}
111142
112143run ( ) ;
0 commit comments