@@ -21,6 +21,7 @@ const fs = require('fs');
2121const moment = require ( 'moment' ) ;
2222const path = require ( 'path' ) ;
2323const yaml = require ( 'js-yaml' ) ;
24+ const proc = require ( 'child_process' ) ;
2425
2526function loadKubeConfig ( ) {
2627 const kubeCfgPath = path . join ( process . env . HOME , '.kube/config' ) ;
@@ -104,6 +105,7 @@ function getToken(userInfo) {
104105 const token = _ . get ( userInfo , 'user.token' ) ||
105106 _ . get ( userInfo , 'user.auth-provider.config.id-token' ) ;
106107 const accessToken = _ . get ( userInfo , 'user.auth-provider.config.access-token' ) ;
108+ let cmd = _ . get ( userInfo , 'user.exec.command' ) ;
107109 if ( token ) {
108110 return token ;
109111 } else if ( accessToken ) {
@@ -117,6 +119,29 @@ function getToken(userInfo) {
117119 }
118120 }
119121 return accessToken ;
122+ } else if ( cmd && cmd === 'aws' ) {
123+ const args = _ . get ( userInfo , 'user.exec.args' ) ;
124+ if ( args ) {
125+ cmd = `${ cmd } ${ args . join ( ' ' ) } ` ;
126+ }
127+ const env = _ . get ( userInfo , 'user.exec.env' , [ ] ) ;
128+ if ( env ) {
129+ const profile = _ . find ( env , e => e . name === 'AWS_PROFILE' ) ;
130+ if ( profile ) {
131+ cmd = `${ cmd } --profile ${ profile . value } ` ;
132+ }
133+ }
134+ let output = { } ;
135+ try {
136+ output = proc . execSync ( cmd ) ;
137+ } catch ( err ) {
138+ throw new Error ( `Failed to refresh token: ${ err . message } ` ) ;
139+ }
140+ const resultObj = JSON . parse ( output ) ;
141+ const execToken = _ . get ( resultObj , 'status.token' ) ;
142+ if ( execToken ) {
143+ return execToken ;
144+ }
120145 }
121146 return null ;
122147}
0 commit comments