ecr: switch implementation to use the AWS SDK

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2021-12-20 10:43:09 +01:00
parent b776a64ec0
commit faae4d6665
No known key found for this signature in database
GPG key ID: 3248E46B6BB8C7F7
9 changed files with 39554 additions and 3343 deletions

View file

@ -1,5 +1,4 @@
import {loginECR, loginStandard, logout} from '../src/docker';
import * as aws from '../src/aws';
import {loginStandard, logout} from '../src/docker';
import * as path from 'path';
@ -48,78 +47,3 @@ test('logout calls exec', async () => {
ignoreReturnCode: true
});
});
test('loginECR sets AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY if username and password is set', async () => {
const execSpy: jest.SpyInstance = jest.spyOn(aws, 'getDockerLoginCmds');
execSpy.mockImplementation(() => Promise.resolve([]));
jest.spyOn(aws, 'getCLI').mockImplementation(() => Promise.resolve(''));
jest.spyOn(aws, 'getCLIVersion').mockImplementation(() => Promise.resolve(''));
jest.spyOn(aws, 'getRegion').mockImplementation(() => '');
jest.spyOn(aws, 'getAccountIDs').mockImplementation(() => []);
jest.spyOn(aws, 'isPubECR').mockImplementation(() => false);
const username: string = 'dbowie';
const password: string = 'groundcontrol';
const registry: string = 'https://ghcr.io';
await loginECR(registry, username, password);
expect(process.env.AWS_ACCESS_KEY_ID).toEqual(username);
expect(process.env.AWS_SECRET_ACCESS_KEY).toEqual(password);
});
test('loginECR keeps AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY if set', async () => {
const execSpy: jest.SpyInstance = jest.spyOn(aws, 'getDockerLoginCmds');
execSpy.mockImplementation(() => Promise.resolve([]));
jest.spyOn(aws, 'getCLI').mockImplementation(() => Promise.resolve(''));
jest.spyOn(aws, 'getCLIVersion').mockImplementation(() => Promise.resolve(''));
jest.spyOn(aws, 'getRegion').mockImplementation(() => '');
jest.spyOn(aws, 'getAccountIDs').mockImplementation(() => []);
jest.spyOn(aws, 'isPubECR').mockImplementation(() => false);
process.env.AWS_ACCESS_KEY_ID = 'banana';
process.env.AWS_SECRET_ACCESS_KEY = 'supersecret';
await loginECR('ecr.aws', '', '');
expect(process.env.AWS_ACCESS_KEY_ID).toEqual('banana');
expect(process.env.AWS_SECRET_ACCESS_KEY).toEqual('supersecret');
});
test('loginECR overrides AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY if username and password set', async () => {
const execSpy: jest.SpyInstance = jest.spyOn(aws, 'getDockerLoginCmds');
execSpy.mockImplementation(() => Promise.resolve([]));
jest.spyOn(aws, 'getCLI').mockImplementation(() => Promise.resolve(''));
jest.spyOn(aws, 'getCLIVersion').mockImplementation(() => Promise.resolve(''));
jest.spyOn(aws, 'getRegion').mockImplementation(() => '');
jest.spyOn(aws, 'getAccountIDs').mockImplementation(() => []);
jest.spyOn(aws, 'isPubECR').mockImplementation(() => false);
process.env.AWS_ACCESS_KEY_ID = 'banana';
process.env.AWS_SECRET_ACCESS_KEY = 'supersecret';
const username = 'myotheruser';
const password = 'providedpassword';
await loginECR('ecr.aws', username, password);
expect(process.env.AWS_ACCESS_KEY_ID).toEqual(username);
expect(process.env.AWS_SECRET_ACCESS_KEY).toEqual(password);
});
test('loginECR does not set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY if not set', async () => {
const execSpy: jest.SpyInstance = jest.spyOn(aws, 'getDockerLoginCmds');
execSpy.mockImplementation(() => Promise.resolve([]));
jest.spyOn(aws, 'getCLI').mockImplementation(() => Promise.resolve(''));
jest.spyOn(aws, 'getCLIVersion').mockImplementation(() => Promise.resolve(''));
jest.spyOn(aws, 'getRegion').mockImplementation(() => '');
jest.spyOn(aws, 'getAccountIDs').mockImplementation(() => []);
jest.spyOn(aws, 'isPubECR').mockImplementation(() => false);
delete process.env.AWS_ACCESS_KEY_ID;
delete process.env.AWS_SECRET_ACCESS_KEY;
await loginECR('ecr.aws', '', '');
expect('AWS_ACCESS_KEY_ID' in process.env).toEqual(false);
expect('AWS_SECRET_ACCESS_KEY' in process.env).toEqual(false);
});