mirror of
https://github.com/aws-actions/configure-aws-credentials.git
synced 2026-03-12 18:07:10 -04:00
Feat: proxy implementation (#246)
* feat: implement proxy feature * see #222 * refactor: pr changes Co-authored-by: Peter Woodworth <44349620+peterwoodworth@users.noreply.github.com>
This commit is contained in:
25
index.js
25
index.js
@@ -3,6 +3,7 @@ const aws = require('aws-sdk');
|
||||
const assert = require('assert');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const proxy = require('https-proxy-agent');
|
||||
|
||||
// Use 1hr as role duration when using session token or OIDC
|
||||
// Otherwise, use the max duration of GitHub action (6hr)
|
||||
@@ -260,6 +261,26 @@ const retryAndBackoff = async (fn, isRetryable, retries = 0, maxRetries = 12, ba
|
||||
}
|
||||
}
|
||||
|
||||
function configureProxy(proxyServer) {
|
||||
const proxyFromEnv = process.env.HTTP_PROXY || process.env.http_proxy;
|
||||
|
||||
if (proxyFromEnv || proxyServer) {
|
||||
let proxyToSet = null;
|
||||
|
||||
if (proxyServer){
|
||||
console.log(`Setting proxy from actions input: ${proxyServer}`);
|
||||
proxyToSet = proxyServer;
|
||||
} else {
|
||||
console.log(`Setting proxy from environment: ${proxyFromEnv}`);
|
||||
proxyToSet = proxyFromEnv;
|
||||
}
|
||||
|
||||
aws.config.update({
|
||||
httpOptions: { agent: proxy(proxyToSet) }
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async function run() {
|
||||
try {
|
||||
// Get inputs
|
||||
@@ -278,6 +299,7 @@ async function run() {
|
||||
const roleSkipSessionTaggingInput = core.getInput('role-skip-session-tagging', { required: false })|| 'false';
|
||||
const roleSkipSessionTagging = roleSkipSessionTaggingInput.toLowerCase() === 'true';
|
||||
const webIdentityTokenFile = core.getInput('web-identity-token-file', { required: false });
|
||||
const proxyServer = core.getInput('http-proxy', { required: false });
|
||||
|
||||
if (!region.match(REGION_REGEX)) {
|
||||
throw new Error(`Region is not valid: ${region}`);
|
||||
@@ -307,6 +329,9 @@ async function run() {
|
||||
|
||||
exportCredentials({accessKeyId, secretAccessKey, sessionToken});
|
||||
}
|
||||
|
||||
// Configures proxy
|
||||
configureProxy(proxyServer);
|
||||
|
||||
// Attempt to load credentials from the GitHub OIDC provider.
|
||||
// If a user provides an IAM Role Arn and DOESN'T provide an Access Key Id
|
||||
|
||||
Reference in New Issue
Block a user