Skip to content

Commit 946b2aa

Browse files
authored
Merge pull request #436 from berviantoleo/feat/update-aws-sdk-v3
feat: Update to AWS SDK v3
2 parents 303ccb9 + b088af0 commit 946b2aa

File tree

4 files changed

+4212
-3222
lines changed

4 files changed

+4212
-3222
lines changed

index.js

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
const core = require('@actions/core');
22
const exec = require('@actions/exec');
3-
const aws = require('aws-sdk');
43
const proxy = require('https-proxy-agent');
4+
const { ECRClient, GetAuthorizationTokenCommand } = require("@aws-sdk/client-ecr");
5+
const { ECRPUBLICClient, GetAuthorizationTokenCommand: GetAuthorizationTokenCommandPublic } = require("@aws-sdk/client-ecr-public");
56

67
const ECR_LOGIN_GITHUB_ACTION_USER_AGENT = 'amazon-ecr-login-for-github-actions';
78
const ECR_PUBLIC_REGISTRY_URI = 'public.ecr.aws';
@@ -28,32 +29,32 @@ const REGISTRY_TYPES = {
2829
public: 'public'
2930
};
3031

31-
3232
function configureProxy(httpProxy) {
3333
const proxyFromEnv = process.env.HTTP_PROXY || process.env.http_proxy;
3434

3535
if (httpProxy || proxyFromEnv) {
3636
let proxyToSet;
3737

38-
if (httpProxy){
38+
if (httpProxy) {
3939
core.info(`Setting proxy from action input: ${httpProxy}`);
4040
proxyToSet = httpProxy;
4141
} else {
4242
core.info(`Setting proxy from environment: ${proxyFromEnv}`);
4343
proxyToSet = proxyFromEnv;
4444
}
4545

46-
aws.config.update({
47-
httpOptions: { agent: proxy(proxyToSet) }
48-
});
46+
const httpOptions = { agent: proxy(proxyToSet) };
47+
return httpOptions;
4948
}
49+
return null;
5050
}
5151

52-
async function getEcrAuthTokenWrapper(authTokenRequest) {
53-
const ecr = new aws.ECR({
52+
async function getEcrAuthTokenWrapper(authTokenRequest, httpOptions) {
53+
const ecr = new ECRClient({
5454
customUserAgent: ECR_LOGIN_GITHUB_ACTION_USER_AGENT
5555
});
56-
const authTokenResponse = await ecr.getAuthorizationToken(authTokenRequest).promise();
56+
const command = new GetAuthorizationTokenCommand(authTokenRequest);
57+
const authTokenResponse = await ecr.send(command, httpOptions);
5758
if (!authTokenResponse) {
5859
throw new Error('Amazon ECR authorization token returned no data');
5960
} else if (!authTokenResponse.authorizationData || !Array.isArray(authTokenResponse.authorizationData)) {
@@ -65,11 +66,12 @@ async function getEcrAuthTokenWrapper(authTokenRequest) {
6566
return authTokenResponse;
6667
}
6768

68-
async function getEcrPublicAuthTokenWrapper(authTokenRequest) {
69-
const ecrPublic = new aws.ECRPUBLIC({
69+
async function getEcrPublicAuthTokenWrapper(authTokenRequest, httpOptions) {
70+
const ecrPublic = new ECRPUBLICClient({
7071
customUserAgent: ECR_LOGIN_GITHUB_ACTION_USER_AGENT
7172
});
72-
const authTokenResponse = await ecrPublic.getAuthorizationToken(authTokenRequest).promise();
73+
const command = new GetAuthorizationTokenCommandPublic(authTokenRequest);
74+
const authTokenResponse = await ecrPublic.send(command, httpOptions);
7375
if (!authTokenResponse) {
7476
throw new Error('Amazon ECR Public authorization token returned no data');
7577
} else if (!authTokenResponse.authorizationData) {
@@ -107,7 +109,7 @@ async function run() {
107109
}
108110

109111
// Configures proxy
110-
configureProxy(httpProxy);
112+
const proxyOptions = configureProxy(httpProxy);
111113

112114
// Get the ECR/ECR Public authorization token(s)
113115
const authTokenRequest = {};
@@ -120,15 +122,15 @@ async function run() {
120122
authTokenRequest.registryIds = registryIds;
121123
}
122124
const authTokenResponse = registryType === REGISTRY_TYPES.private ?
123-
await getEcrAuthTokenWrapper(authTokenRequest) :
124-
await getEcrPublicAuthTokenWrapper(authTokenRequest);
125+
await getEcrAuthTokenWrapper(authTokenRequest, proxyOptions) :
126+
await getEcrPublicAuthTokenWrapper(authTokenRequest, proxyOptions);
125127

126128
// Login to each registry
127129
for (const authData of authTokenResponse.authorizationData) {
128130
const authToken = Buffer.from(authData.authorizationToken, 'base64').toString('utf-8');
129131
const creds = authToken.split(':', 2);
130132
const proxyEndpoint = authData.proxyEndpoint;
131-
const registryUri = proxyEndpoint.replace(/^https?:\/\//,'');
133+
const registryUri = proxyEndpoint.replace(/^https?:\/\//, '');
132134

133135
core.info(`Logging into registry ${registryUri}`);
134136

@@ -179,6 +181,7 @@ async function run() {
179181
}
180182

181183
module.exports = {
184+
configureProxy,
182185
run,
183186
replaceSpecialCharacters
184187
};

0 commit comments

Comments
 (0)