feat: idempotent fetch (#1289)

* Add functionality to re-use existing credentials

* Finish adding use-existing-credentials logic

* Add testing for use-existing-credentials

* Update README

* feat: finalize use-exisiting-credentials feature

---------

Co-authored-by: Tom Keller <kellertk@amazon.com>
This commit is contained in:
Michael Lehmann
2025-02-07 16:24:45 -08:00
committed by GitHub
parent 3478c15aa1
commit eb70354fb4
6 changed files with 47 additions and 0 deletions

View File

@@ -27,6 +27,7 @@ describe('Configure AWS Credentials', {}, () => {
vi.spyOn(core, 'setOutput').mockImplementation((_n, _v) => {});
vi.spyOn(core, 'debug').mockImplementation((_m) => {});
vi.spyOn(core, 'info').mockImplementation((_m) => {});
vi.spyOn(core, 'notice').mockImplementation((_m) => {});
// Remove any existing environment variables before each test to prevent the
// SDK from picking them up
process.env = { ...mocks.envs };
@@ -299,5 +300,17 @@ describe('Configure AWS Credentials', {}, () => {
await run();
expect(core.setFailed).toHaveBeenCalled();
});
it('gets new creds if told to reuse existing but they\'re invalid', {}, async () => {
vi.spyOn(core, 'getInput').mockImplementation(mocks.getInput(mocks.USE_EXISTING_CREDENTIALS_INPUTS));
mockedSTSClient.on(GetCallerIdentityCommand).rejects();
await run();
expect(core.notice).toHaveBeenCalledWith('No valid credentials exist. Running as normal.')
});
it('doesn\'t get new creds if there are already valid ones and we said use them', {}, async () => {
vi.spyOn(core, 'getInput').mockImplementation(mocks.getInput(mocks.USE_EXISTING_CREDENTIALS_INPUTS));
mockedSTSClient.on(GetCallerIdentityCommand).resolves(mocks.outputs.GET_CALLER_IDENTITY);
await run();
expect(core.setFailed).not.toHaveBeenCalled();
})
});
});

View File

@@ -27,6 +27,11 @@ const inputs = {
'role-chaining': 'true',
'aws-region': 'fake-region-1',
},
USE_EXISTING_CREDENTIALS_INPUTS: {
'aws-region': 'fake-region-1',
'use-existing-credentials': 'true',
'role-to-assume': 'arn:aws:iam::111111111111:role/MY-ROLE',
}
};
const envs = {