Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle proxy settings for aws-sdk #152

Merged
merged 1 commit into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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 (httpsProxy) {
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
Loading