Skip to content

Commit

Permalink
handle proxy settings for aws-sdk
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
  • Loading branch information
crazy-max committed Feb 16, 2022
1 parent 17f28ab commit 5720e5c
Show file tree
Hide file tree
Showing 8 changed files with 58,064 additions and 3,350 deletions.
984 changes: 984 additions & 0 deletions dist/bridge.js

Large diffs are not rendered by default.

1,033 changes: 1,033 additions & 0 deletions dist/events.js

Large diffs are not rendered by default.

58,148 changes: 54,807 additions & 3,341 deletions dist/index.js

Large diffs are not rendered by default.

473 changes: 473 additions & 0 deletions dist/setup-node-sandbox.js

Large diffs are not rendered by default.

462 changes: 462 additions & 0 deletions dist/setup-sandbox.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -31,7 +31,8 @@
"@actions/exec": "^1.1.0",
"@actions/io": "^1.1.1",
"@aws-sdk/client-ecr": "^3.45.0",
"@aws-sdk/client-ecr-public": "^3.45.0"
"@aws-sdk/client-ecr-public": "^3.45.0",
"proxy-agent": "^5.0.0"
},
"devDependencies": {
"@types/jest": "^26.0.23",
Expand Down
28 changes: 26 additions & 2 deletions src/aws.ts
@@ -1,6 +1,8 @@
import * as core from '@actions/core';
import {ECR} from '@aws-sdk/client-ecr';
import {ECRPUBLIC} from '@aws-sdk/client-ecr-public';
import {NodeHttpHandler} from '@aws-sdk/node-http-handler';
import ProxyAgent from 'proxy-agent';

const ecrRegistryRegex = /^(([0-9]{12})\.dkr\.ecr\.(.+)\.amazonaws\.com(.cn)?)(\/([^:]+)(:.+)?)?$/;

Expand Down Expand Up @@ -54,6 +56,20 @@ export const getRegistriesData = async (registry: string, username?: string, pas
authTokenRequest['registryIds'] = accountIDs;
}

let httpProxyAgent: any = null;
const httpProxy = process.env.http_proxy || process.env.HTTP_PROXY || '';
if (httpProxy) {
core.debug(`Using http proxy ${httpProxy}`);
httpProxyAgent = new ProxyAgent(httpProxy);
}

let httpsProxyAgent: any = null;
const httpsProxy = process.env.https_proxy || process.env.HTTPS_PROXY || '';
if (httpProxy) {
core.debug(`Using https proxy ${httpsProxy}`);
httpsProxyAgent = new ProxyAgent(httpsProxy);
}

const credentials =
username && password
? {
Expand All @@ -67,7 +83,11 @@ export const getRegistriesData = async (registry: string, username?: string, pas
const ecrPublic = new ECRPUBLIC({
customUserAgent: 'docker-login-action',
credentials,
region: region
region: region,
requestHandler: new NodeHttpHandler({
httpAgent: httpProxyAgent,
httpsAgent: httpsProxyAgent
})
});
const authTokenResponse = await ecrPublic.getAuthorizationToken(authTokenRequest);
if (!authTokenResponse.authorizationData || !authTokenResponse.authorizationData.authorizationToken) {
Expand All @@ -87,7 +107,11 @@ export const getRegistriesData = async (registry: string, username?: string, pas
const ecr = new ECR({
customUserAgent: 'docker-login-action',
credentials,
region: region
region: region,
requestHandler: new NodeHttpHandler({
httpAgent: httpProxyAgent,
httpsAgent: httpsProxyAgent
})
});
const authTokenResponse = await ecr.getAuthorizationToken(authTokenRequest);
if (!Array.isArray(authTokenResponse.authorizationData) || !authTokenResponse.authorizationData.length) {
Expand Down

0 comments on commit 5720e5c

Please sign in to comment.