Skip to content

Commit 3a8608a

Browse files
authored
Merge pull request #85 from peter-evans/update-distribution
Update distribution
2 parents 59fb538 + f3e2ad4 commit 3a8608a

File tree

1 file changed

+159
-1
lines changed

1 file changed

+159
-1
lines changed

dist/index.js

Lines changed: 159 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
206206
});
207207
};
208208
Object.defineProperty(exports, "__esModule", ({ value: true }));
209-
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;
209+
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;
210210
const command_1 = __nccwpck_require__(351);
211211
const file_command_1 = __nccwpck_require__(717);
212212
const utils_1 = __nccwpck_require__(278);
213213
const os = __importStar(__nccwpck_require__(87));
214214
const path = __importStar(__nccwpck_require__(622));
215+
const oidc_utils_1 = __nccwpck_require__(41);
215216
/**
216217
* The code to exit an action
217218
*/
@@ -480,6 +481,12 @@ function getState(name) {
480481
return process.env[`STATE_${name}`] || '';
481482
}
482483
exports.getState = getState;
484+
function getIDToken(aud) {
485+
return __awaiter(this, void 0, void 0, function* () {
486+
return yield oidc_utils_1.OidcClient.getIDToken(aud);
487+
});
488+
}
489+
exports.getIDToken = getIDToken;
483490
//# sourceMappingURL=core.js.map
484491

485492
/***/ }),
@@ -533,6 +540,90 @@ exports.issueCommand = issueCommand;
533540

534541
/***/ }),
535542

543+
/***/ 41:
544+
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
545+
546+
"use strict";
547+
548+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
549+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
550+
return new (P || (P = Promise))(function (resolve, reject) {
551+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
552+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
553+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
554+
step((generator = generator.apply(thisArg, _arguments || [])).next());
555+
});
556+
};
557+
Object.defineProperty(exports, "__esModule", ({ value: true }));
558+
exports.OidcClient = void 0;
559+
const http_client_1 = __nccwpck_require__(925);
560+
const auth_1 = __nccwpck_require__(702);
561+
const core_1 = __nccwpck_require__(186);
562+
class OidcClient {
563+
static createHttpClient(allowRetry = true, maxRetry = 10) {
564+
const requestOptions = {
565+
allowRetries: allowRetry,
566+
maxRetries: maxRetry
567+
};
568+
return new http_client_1.HttpClient('actions/oidc-client', [new auth_1.BearerCredentialHandler(OidcClient.getRequestToken())], requestOptions);
569+
}
570+
static getRequestToken() {
571+
const token = process.env['ACTIONS_ID_TOKEN_REQUEST_TOKEN'];
572+
if (!token) {
573+
throw new Error('Unable to get ACTIONS_ID_TOKEN_REQUEST_TOKEN env variable');
574+
}
575+
return token;
576+
}
577+
static getIDTokenUrl() {
578+
const runtimeUrl = process.env['ACTIONS_ID_TOKEN_REQUEST_URL'];
579+
if (!runtimeUrl) {
580+
throw new Error('Unable to get ACTIONS_ID_TOKEN_REQUEST_URL env variable');
581+
}
582+
return runtimeUrl;
583+
}
584+
static getCall(id_token_url) {
585+
var _a;
586+
return __awaiter(this, void 0, void 0, function* () {
587+
const httpclient = OidcClient.createHttpClient();
588+
const res = yield httpclient
589+
.getJson(id_token_url)
590+
.catch(error => {
591+
throw new Error(`Failed to get ID Token. \n
592+
Error Code : ${error.statusCode}\n
593+
Error Message: ${error.result.message}`);
594+
});
595+
const id_token = (_a = res.result) === null || _a === void 0 ? void 0 : _a.value;
596+
if (!id_token) {
597+
throw new Error('Response json body do not have ID Token field');
598+
}
599+
return id_token;
600+
});
601+
}
602+
static getIDToken(audience) {
603+
return __awaiter(this, void 0, void 0, function* () {
604+
try {
605+
// New ID Token is requested from action service
606+
let id_token_url = OidcClient.getIDTokenUrl();
607+
if (audience) {
608+
const encodedAudience = encodeURIComponent(audience);
609+
id_token_url = `${id_token_url}&audience=${encodedAudience}`;
610+
}
611+
core_1.debug(`ID token url is ${id_token_url}`);
612+
const id_token = yield OidcClient.getCall(id_token_url);
613+
core_1.setSecret(id_token);
614+
return id_token;
615+
}
616+
catch (error) {
617+
throw new Error(`Error message: ${error.message}`);
618+
}
619+
});
620+
}
621+
}
622+
exports.OidcClient = OidcClient;
623+
//# sourceMappingURL=oidc-utils.js.map
624+
625+
/***/ }),
626+
536627
/***/ 278:
537628
/***/ ((__unused_webpack_module, exports) => {
538629

@@ -568,6 +659,7 @@ function toCommandProperties(annotationProperties) {
568659
}
569660
return {
570661
title: annotationProperties.title,
662+
file: annotationProperties.file,
571663
line: annotationProperties.startLine,
572664
endLine: annotationProperties.endLine,
573665
col: annotationProperties.startColumn,
@@ -792,6 +884,72 @@ function getOctokitOptions(token, options) {
792884
exports.getOctokitOptions = getOctokitOptions;
793885
//# sourceMappingURL=utils.js.map
794886

887+
/***/ }),
888+
889+
/***/ 702:
890+
/***/ ((__unused_webpack_module, exports) => {
891+
892+
"use strict";
893+
894+
Object.defineProperty(exports, "__esModule", ({ value: true }));
895+
class BasicCredentialHandler {
896+
constructor(username, password) {
897+
this.username = username;
898+
this.password = password;
899+
}
900+
prepareRequest(options) {
901+
options.headers['Authorization'] =
902+
'Basic ' +
903+
Buffer.from(this.username + ':' + this.password).toString('base64');
904+
}
905+
// This handler cannot handle 401
906+
canHandleAuthentication(response) {
907+
return false;
908+
}
909+
handleAuthentication(httpClient, requestInfo, objs) {
910+
return null;
911+
}
912+
}
913+
exports.BasicCredentialHandler = BasicCredentialHandler;
914+
class BearerCredentialHandler {
915+
constructor(token) {
916+
this.token = token;
917+
}
918+
// currently implements pre-authorization
919+
// TODO: support preAuth = false where it hooks on 401
920+
prepareRequest(options) {
921+
options.headers['Authorization'] = 'Bearer ' + this.token;
922+
}
923+
// This handler cannot handle 401
924+
canHandleAuthentication(response) {
925+
return false;
926+
}
927+
handleAuthentication(httpClient, requestInfo, objs) {
928+
return null;
929+
}
930+
}
931+
exports.BearerCredentialHandler = BearerCredentialHandler;
932+
class PersonalAccessTokenCredentialHandler {
933+
constructor(token) {
934+
this.token = token;
935+
}
936+
// currently implements pre-authorization
937+
// TODO: support preAuth = false where it hooks on 401
938+
prepareRequest(options) {
939+
options.headers['Authorization'] =
940+
'Basic ' + Buffer.from('PAT:' + this.token).toString('base64');
941+
}
942+
// This handler cannot handle 401
943+
canHandleAuthentication(response) {
944+
return false;
945+
}
946+
handleAuthentication(httpClient, requestInfo, objs) {
947+
return null;
948+
}
949+
}
950+
exports.PersonalAccessTokenCredentialHandler = PersonalAccessTokenCredentialHandler;
951+
952+
795953
/***/ }),
796954

797955
/***/ 925:

0 commit comments

Comments
 (0)