@@ -247,12 +247,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
247
247
} ) ;
248
248
} ;
249
249
Object . defineProperty ( exports , "__esModule" , ( { value : true } ) ) ;
250
- exports . getState = exports . saveState = exports . group = exports . endGroup = exports . startGroup = exports . info = exports . notice = exports . warning = exports . error = exports . debug = exports . isDebug = exports . setFailed = exports . setCommandEcho = exports . setOutput = exports . getBooleanInput = exports . getMultilineInput = exports . getInput = exports . addPath = exports . setSecret = exports . exportVariable = exports . ExitCode = void 0 ;
250
+ exports . getIDToken = exports . getState = exports . saveState = exports . group = exports . endGroup = exports . startGroup = exports . info = exports . notice = exports . warning = exports . error = exports . debug = exports . isDebug = exports . setFailed = exports . setCommandEcho = exports . setOutput = exports . getBooleanInput = exports . getMultilineInput = exports . getInput = exports . addPath = exports . setSecret = exports . exportVariable = exports . ExitCode = void 0 ;
251
251
const command_1 = __nccwpck_require__ ( 351 ) ;
252
252
const file_command_1 = __nccwpck_require__ ( 717 ) ;
253
253
const utils_1 = __nccwpck_require__ ( 278 ) ;
254
254
const os = __importStar ( __nccwpck_require__ ( 87 ) ) ;
255
255
const path = __importStar ( __nccwpck_require__ ( 622 ) ) ;
256
+ const oidc_utils_1 = __nccwpck_require__ ( 41 ) ;
256
257
/**
257
258
* The code to exit an action
258
259
*/
@@ -521,6 +522,12 @@ function getState(name) {
521
522
return process . env [ `STATE_${ name } ` ] || '' ;
522
523
}
523
524
exports . getState = getState ;
525
+ function getIDToken ( aud ) {
526
+ return __awaiter ( this , void 0 , void 0 , function * ( ) {
527
+ return yield oidc_utils_1 . OidcClient . getIDToken ( aud ) ;
528
+ } ) ;
529
+ }
530
+ exports . getIDToken = getIDToken ;
524
531
//# sourceMappingURL=core.js.map
525
532
526
533
/***/ } ) ,
@@ -574,6 +581,90 @@ exports.issueCommand = issueCommand;
574
581
575
582
/***/ } ) ,
576
583
584
+ /***/ 41 :
585
+ /***/ ( function ( __unused_webpack_module , exports , __nccwpck_require__ ) {
586
+
587
+ "use strict" ;
588
+
589
+ var __awaiter = ( this && this . __awaiter ) || function ( thisArg , _arguments , P , generator ) {
590
+ function adopt ( value ) { return value instanceof P ? value : new P ( function ( resolve ) { resolve ( value ) ; } ) ; }
591
+ return new ( P || ( P = Promise ) ) ( function ( resolve , reject ) {
592
+ function fulfilled ( value ) { try { step ( generator . next ( value ) ) ; } catch ( e ) { reject ( e ) ; } }
593
+ function rejected ( value ) { try { step ( generator [ "throw" ] ( value ) ) ; } catch ( e ) { reject ( e ) ; } }
594
+ function step ( result ) { result . done ? resolve ( result . value ) : adopt ( result . value ) . then ( fulfilled , rejected ) ; }
595
+ step ( ( generator = generator . apply ( thisArg , _arguments || [ ] ) ) . next ( ) ) ;
596
+ } ) ;
597
+ } ;
598
+ Object . defineProperty ( exports , "__esModule" , ( { value : true } ) ) ;
599
+ exports . OidcClient = void 0 ;
600
+ const http_client_1 = __nccwpck_require__ ( 925 ) ;
601
+ const auth_1 = __nccwpck_require__ ( 702 ) ;
602
+ const core_1 = __nccwpck_require__ ( 186 ) ;
603
+ class OidcClient {
604
+ static createHttpClient ( allowRetry = true , maxRetry = 10 ) {
605
+ const requestOptions = {
606
+ allowRetries : allowRetry ,
607
+ maxRetries : maxRetry
608
+ } ;
609
+ return new http_client_1 . HttpClient ( 'actions/oidc-client' , [ new auth_1 . BearerCredentialHandler ( OidcClient . getRequestToken ( ) ) ] , requestOptions ) ;
610
+ }
611
+ static getRequestToken ( ) {
612
+ const token = process . env [ 'ACTIONS_ID_TOKEN_REQUEST_TOKEN' ] ;
613
+ if ( ! token ) {
614
+ throw new Error ( 'Unable to get ACTIONS_ID_TOKEN_REQUEST_TOKEN env variable' ) ;
615
+ }
616
+ return token ;
617
+ }
618
+ static getIDTokenUrl ( ) {
619
+ const runtimeUrl = process . env [ 'ACTIONS_ID_TOKEN_REQUEST_URL' ] ;
620
+ if ( ! runtimeUrl ) {
621
+ throw new Error ( 'Unable to get ACTIONS_ID_TOKEN_REQUEST_URL env variable' ) ;
622
+ }
623
+ return runtimeUrl ;
624
+ }
625
+ static getCall ( id_token_url ) {
626
+ var _a ;
627
+ return __awaiter ( this , void 0 , void 0 , function * ( ) {
628
+ const httpclient = OidcClient . createHttpClient ( ) ;
629
+ const res = yield httpclient
630
+ . getJson ( id_token_url )
631
+ . catch ( error => {
632
+ throw new Error ( `Failed to get ID Token. \n
633
+ Error Code : ${ error . statusCode } \n
634
+ Error Message: ${ error . result . message } ` ) ;
635
+ } ) ;
636
+ const id_token = ( _a = res . result ) === null || _a === void 0 ? void 0 : _a . value ;
637
+ if ( ! id_token ) {
638
+ throw new Error ( 'Response json body do not have ID Token field' ) ;
639
+ }
640
+ return id_token ;
641
+ } ) ;
642
+ }
643
+ static getIDToken ( audience ) {
644
+ return __awaiter ( this , void 0 , void 0 , function * ( ) {
645
+ try {
646
+ // New ID Token is requested from action service
647
+ let id_token_url = OidcClient . getIDTokenUrl ( ) ;
648
+ if ( audience ) {
649
+ const encodedAudience = encodeURIComponent ( audience ) ;
650
+ id_token_url = `${ id_token_url } &audience=${ encodedAudience } ` ;
651
+ }
652
+ core_1 . debug ( `ID token url is ${ id_token_url } ` ) ;
653
+ const id_token = yield OidcClient . getCall ( id_token_url ) ;
654
+ core_1 . setSecret ( id_token ) ;
655
+ return id_token ;
656
+ }
657
+ catch ( error ) {
658
+ throw new Error ( `Error message: ${ error . message } ` ) ;
659
+ }
660
+ } ) ;
661
+ }
662
+ }
663
+ exports . OidcClient = OidcClient ;
664
+ //# sourceMappingURL=oidc-utils.js.map
665
+
666
+ /***/ } ) ,
667
+
577
668
/***/ 278 :
578
669
/***/ ( ( __unused_webpack_module , exports ) => {
579
670
@@ -609,6 +700,7 @@ function toCommandProperties(annotationProperties) {
609
700
}
610
701
return {
611
702
title : annotationProperties . title ,
703
+ file : annotationProperties . file ,
612
704
line : annotationProperties . startLine ,
613
705
endLine : annotationProperties . endLine ,
614
706
col : annotationProperties . startColumn ,
@@ -833,6 +925,72 @@ function getOctokitOptions(token, options) {
833
925
exports . getOctokitOptions = getOctokitOptions ;
834
926
//# sourceMappingURL=utils.js.map
835
927
928
+ /***/ } ) ,
929
+
930
+ /***/ 702 :
931
+ /***/ ( ( __unused_webpack_module , exports ) => {
932
+
933
+ "use strict" ;
934
+
935
+ Object . defineProperty ( exports , "__esModule" , ( { value : true } ) ) ;
936
+ class BasicCredentialHandler {
937
+ constructor ( username , password ) {
938
+ this . username = username ;
939
+ this . password = password ;
940
+ }
941
+ prepareRequest ( options ) {
942
+ options . headers [ 'Authorization' ] =
943
+ 'Basic ' +
944
+ Buffer . from ( this . username + ':' + this . password ) . toString ( 'base64' ) ;
945
+ }
946
+ // This handler cannot handle 401
947
+ canHandleAuthentication ( response ) {
948
+ return false ;
949
+ }
950
+ handleAuthentication ( httpClient , requestInfo , objs ) {
951
+ return null ;
952
+ }
953
+ }
954
+ exports . BasicCredentialHandler = BasicCredentialHandler ;
955
+ class BearerCredentialHandler {
956
+ constructor ( token ) {
957
+ this . token = token ;
958
+ }
959
+ // currently implements pre-authorization
960
+ // TODO: support preAuth = false where it hooks on 401
961
+ prepareRequest ( options ) {
962
+ options . headers [ 'Authorization' ] = 'Bearer ' + this . token ;
963
+ }
964
+ // This handler cannot handle 401
965
+ canHandleAuthentication ( response ) {
966
+ return false ;
967
+ }
968
+ handleAuthentication ( httpClient , requestInfo , objs ) {
969
+ return null ;
970
+ }
971
+ }
972
+ exports . BearerCredentialHandler = BearerCredentialHandler ;
973
+ class PersonalAccessTokenCredentialHandler {
974
+ constructor ( token ) {
975
+ this . token = token ;
976
+ }
977
+ // currently implements pre-authorization
978
+ // TODO: support preAuth = false where it hooks on 401
979
+ prepareRequest ( options ) {
980
+ options . headers [ 'Authorization' ] =
981
+ 'Basic ' + Buffer . from ( 'PAT:' + this . token ) . toString ( 'base64' ) ;
982
+ }
983
+ // This handler cannot handle 401
984
+ canHandleAuthentication ( response ) {
985
+ return false ;
986
+ }
987
+ handleAuthentication ( httpClient , requestInfo , objs ) {
988
+ return null ;
989
+ }
990
+ }
991
+ exports . PersonalAccessTokenCredentialHandler = PersonalAccessTokenCredentialHandler ;
992
+
993
+
836
994
/***/ } ) ,
837
995
838
996
/***/ 925 :
0 commit comments