-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaws.js
More file actions
35 lines (28 loc) · 978 Bytes
/
aws.js
File metadata and controls
35 lines (28 loc) · 978 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const aws = require("aws-sdk");
const getAuthToken = async function (region) {
const ecr = new aws.ECR({
customUserAgent: "amazon-ecr-login-for-github-actions",
region: region,
});
const authTokenRequest = {};
const authTokenResponse = await ecr
.getAuthorizationToken(authTokenRequest)
.promise();
if (
!Array.isArray(authTokenResponse.authorizationData) ||
!authTokenResponse.authorizationData.length
) {
throw new Error(
"Could not retrieve an authorization token from Amazon ECR"
);
}
const authData = authTokenResponse.authorizationData[0];
const authToken = Buffer.from(authData.authorizationToken, "base64").toString(
"utf-8"
);
const creds = authToken.split(":", 2);
const proxyEndpoint = authData.proxyEndpoint;
const registryUri = proxyEndpoint.replace(/^https?:\/\//, "");
return { username: creds[0], password: creds[1], registryUri: registryUri };
};
exports.getAuthToken = getAuthToken;