Skip to content

Commit 613b83f

Browse files
authored
Merge pull request #390 from peter-evans/update-distribution
Update distribution
2 parents c090b2b + 3c54c28 commit 613b83f

File tree

1 file changed

+159
-1
lines changed

1 file changed

+159
-1
lines changed

dist/index.js

+159-1
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
247247
});
248248
};
249249
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;
251251
const command_1 = __nccwpck_require__(351);
252252
const file_command_1 = __nccwpck_require__(717);
253253
const utils_1 = __nccwpck_require__(278);
254254
const os = __importStar(__nccwpck_require__(87));
255255
const path = __importStar(__nccwpck_require__(622));
256+
const oidc_utils_1 = __nccwpck_require__(41);
256257
/**
257258
* The code to exit an action
258259
*/
@@ -521,6 +522,12 @@ function getState(name) {
521522
return process.env[`STATE_${name}`] || '';
522523
}
523524
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;
524531
//# sourceMappingURL=core.js.map
525532

526533
/***/ }),
@@ -574,6 +581,90 @@ exports.issueCommand = issueCommand;
574581

575582
/***/ }),
576583

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+
577668
/***/ 278:
578669
/***/ ((__unused_webpack_module, exports) => {
579670

@@ -609,6 +700,7 @@ function toCommandProperties(annotationProperties) {
609700
}
610701
return {
611702
title: annotationProperties.title,
703+
file: annotationProperties.file,
612704
line: annotationProperties.startLine,
613705
endLine: annotationProperties.endLine,
614706
col: annotationProperties.startColumn,
@@ -833,6 +925,72 @@ function getOctokitOptions(token, options) {
833925
exports.getOctokitOptions = getOctokitOptions;
834926
//# sourceMappingURL=utils.js.map
835927

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+
836994
/***/ }),
837995

838996
/***/ 925:

0 commit comments

Comments
 (0)