mirror of
https://github.com/docker/login-action.git
synced 2025-04-27 17:16:35 +02:00
refactor: use v3 sdk
Signed-off-by: Markus Maga <markus@maga.se>
This commit is contained in:
parent
d9927c4142
commit
58855695bb
5 changed files with 28595 additions and 39169 deletions
25
src/aws.ts
25
src/aws.ts
|
@ -1,5 +1,6 @@
|
|||
import * as core from '@actions/core';
|
||||
import * as aws from 'aws-sdk';
|
||||
import {ECR} from '@aws-sdk/client-ecr';
|
||||
import {ECRPUBLIC} from '@aws-sdk/client-ecr-public';
|
||||
|
||||
const ecrRegistryRegex = /^(([0-9]{12})\.dkr\.ecr\.(.+)\.amazonaws\.com(.cn)?)(\/([^:]+)(:.+)?)?$/;
|
||||
|
||||
|
@ -53,15 +54,22 @@ export const getRegistriesData = async (registry: string, username?: string, pas
|
|||
authTokenRequest['registryIds'] = accountIDs;
|
||||
}
|
||||
|
||||
const credentials =
|
||||
username && password
|
||||
? {
|
||||
accessKeyId: username,
|
||||
secretAccessKey: password
|
||||
}
|
||||
: undefined;
|
||||
|
||||
if (isPubECR(registry)) {
|
||||
core.info(`AWS Public ECR detected with ${region} region`);
|
||||
const ecrPublic = new aws.ECRPUBLIC({
|
||||
const ecrPublic = new ECRPUBLIC({
|
||||
customUserAgent: 'docker-login-action',
|
||||
accessKeyId: username || process.env.AWS_ACCESS_KEY_ID || '',
|
||||
secretAccessKey: password || process.env.AWS_SECRET_ACCESS_KEY || '',
|
||||
credentials,
|
||||
region: region
|
||||
});
|
||||
const authTokenResponse = await ecrPublic.getAuthorizationToken(authTokenRequest).promise();
|
||||
const authTokenResponse = await ecrPublic.getAuthorizationToken(authTokenRequest);
|
||||
if (!authTokenResponse.authorizationData || !authTokenResponse.authorizationData.authorizationToken) {
|
||||
throw new Error('Could not retrieve an authorization token from AWS Public ECR');
|
||||
}
|
||||
|
@ -76,13 +84,12 @@ export const getRegistriesData = async (registry: string, username?: string, pas
|
|||
];
|
||||
} else {
|
||||
core.info(`AWS ECR detected with ${region} region`);
|
||||
const ecr = new aws.ECR({
|
||||
const ecr = new ECR({
|
||||
customUserAgent: 'docker-login-action',
|
||||
accessKeyId: username || process.env.AWS_ACCESS_KEY_ID || '',
|
||||
secretAccessKey: password || process.env.AWS_SECRET_ACCESS_KEY || '',
|
||||
credentials,
|
||||
region: region
|
||||
});
|
||||
const authTokenResponse = await ecr.getAuthorizationToken(authTokenRequest).promise();
|
||||
const authTokenResponse = await ecr.getAuthorizationToken(authTokenRequest);
|
||||
if (!Array.isArray(authTokenResponse.authorizationData) || !authTokenResponse.authorizationData.length) {
|
||||
throw new Error('Could not retrieve an authorization token from AWS ECR');
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue