Skip to content

Commit f29e0d5

Browse files
committed
feat: output ARN of authenticated prinicpal
Closes #1062 Closes #1191
1 parent b49dc07 commit f29e0d5

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

src/helpers.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,16 @@ export async function exportAccountId(credentialsClient: CredentialsClient, mask
113113
const client = credentialsClient.stsClient;
114114
const identity = await client.send(new GetCallerIdentityCommand({}));
115115
const accountId = identity.Account;
116-
if (!accountId) {
117-
throw new Error('Could not get Account ID from STS. Did you set credentials?');
116+
const arn = identity.Arn;
117+
if (!accountId || !arn) {
118+
throw new Error('Could not get Account ID or ARN from STS. Did you set credentials?');
118119
}
119120
if (maskAccountId) {
120121
core.setSecret(accountId);
122+
core.setSecret(arn);
121123
}
122124
core.setOutput('aws-account-id', accountId);
125+
core.setOutput('authenticated-arn', arn);
123126
return accountId;
124127
}
125128

test/index.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ describe('Configure AWS Credentials', {}, () => {
4747
expect(core.info).toHaveBeenCalledWith('Authenticated as assumedRoleId AROAFAKEASSUMEDROLEID');
4848
expect(core.info).toHaveBeenCalledTimes(2);
4949
expect(core.setOutput).toHaveBeenCalledWith('aws-account-id', '111111111111');
50-
expect(core.setOutput).toHaveBeenCalledOnce();
50+
expect(core.setOutput).toHaveBeenCalledTimes(2);
5151
expect(core.setSecret).toHaveBeenCalledWith('STSAWSACCESSKEYID');
5252
expect(core.setSecret).toHaveBeenCalledWith('STSAWSSECRETACCESSKEY');
5353
expect(core.setSecret).toHaveBeenCalledWith('STSAWSSESSIONTOKEN');
@@ -71,7 +71,7 @@ describe('Configure AWS Credentials', {}, () => {
7171
expect(core.info).toHaveBeenCalledWith('Authenticated as assumedRoleId AROAFAKEASSUMEDROLEID');
7272
expect(core.info).toHaveBeenCalledTimes(3);
7373
expect(core.setOutput).toHaveBeenCalledWith('aws-account-id', '111111111111');
74-
expect(core.setOutput).toHaveBeenCalledOnce();
74+
expect(core.setOutput).toHaveBeenCalledTimes(2);
7575
expect(core.setSecret).toHaveBeenCalledWith('STSAWSACCESSKEYID');
7676
expect(core.setSecret).toHaveBeenCalledWith('STSAWSSECRETACCESSKEY');
7777
expect(core.setSecret).toHaveBeenCalledWith('STSAWSSESSIONTOKEN');
@@ -106,7 +106,7 @@ describe('Configure AWS Credentials', {}, () => {
106106
expect(core.setSecret).toHaveBeenCalledWith('MYAWSSECRETACCESSKEY');
107107
expect(core.setSecret).toHaveBeenCalledTimes(2);
108108
expect(core.setOutput).toHaveBeenCalledWith('aws-account-id', '111111111111');
109-
expect(core.setOutput).toHaveBeenCalledOnce();
109+
expect(core.setOutput).toHaveBeenCalledTimes(2);
110110
expect(core.info).toHaveBeenCalledWith('Proceeding with IAM user credentials');
111111
expect(core.info).toHaveBeenCalledOnce();
112112
expect(core.setFailed).not.toHaveBeenCalled();
@@ -140,7 +140,7 @@ describe('Configure AWS Credentials', {}, () => {
140140
expect(core.setSecret).toHaveBeenCalledWith('MYAWSSECRETACCESSKEY');
141141
expect(core.setSecret).toHaveBeenCalledTimes(5);
142142
expect(core.setOutput).toHaveBeenCalledWith('aws-account-id', '111111111111');
143-
expect(core.setOutput).toHaveBeenCalledTimes(2);
143+
expect(core.setOutput).toHaveBeenCalledTimes(4);
144144
expect(core.info).toHaveBeenCalledWith('Assuming role with user credentials');
145145
expect(core.info).toHaveBeenCalledWith('Authenticated as assumedRoleId AROAFAKEASSUMEDROLEID');
146146
expect(core.info).toHaveBeenCalledTimes(2);
@@ -173,7 +173,7 @@ describe('Configure AWS Credentials', {}, () => {
173173
expect(core.setSecret).toHaveBeenCalledWith('STSAWSSESSIONTOKEN');
174174
expect(core.setSecret).toHaveBeenCalledTimes(3);
175175
expect(core.setOutput).toHaveBeenCalledWith('aws-account-id', '111111111111');
176-
expect(core.setOutput).toHaveBeenCalledTimes(1);
176+
expect(core.setOutput).toHaveBeenCalledTimes(2);
177177
expect(core.setFailed).not.toHaveBeenCalled();
178178
});
179179
});
@@ -204,7 +204,7 @@ describe('Configure AWS Credentials', {}, () => {
204204
expect(core.setSecret).toHaveBeenCalledWith('STSAWSSESSIONTOKEN');
205205
expect(core.setSecret).toHaveBeenCalledTimes(3);
206206
expect(core.setOutput).toHaveBeenCalledWith('aws-account-id', '111111111111');
207-
expect(core.setOutput).toHaveBeenCalledTimes(2);
207+
expect(core.setOutput).toHaveBeenCalledTimes(4);
208208
expect(core.setFailed).not.toHaveBeenCalled();
209209
});
210210
it('exports environment variables from inputs', {}, async () => {
@@ -237,7 +237,7 @@ describe('Configure AWS Credentials', {}, () => {
237237
expect(core.setSecret).toHaveBeenCalledWith('STSAWSSESSIONTOKEN');
238238
expect(core.setSecret).toHaveBeenCalledTimes(6);
239239
expect(core.setOutput).toHaveBeenCalledWith('aws-account-id', '111111111111');
240-
expect(core.setOutput).toHaveBeenCalledTimes(2);
240+
expect(core.setOutput).toHaveBeenCalledTimes(4);
241241
expect(core.setFailed).not.toHaveBeenCalled();
242242
});
243243
});

0 commit comments

Comments
 (0)