-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support for advanced config with
source_profiles
(#231)
This extension now supports advanced configuration with `source_profile` and `target_role_name`. When using advanced configuration roles that does not match with root accounts alias are not shown anymore in popup. This enhanced the visablility of roles that are actually needed or can be assumed.
- Loading branch information
1 parent
29f1bcb
commit 0757562
Showing
20 changed files
with
537 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
jest.mock('../../common/config/storage'); | ||
jest.mock('../../common/browser/cookies'); | ||
|
||
import { getConfig } from '../../common/config/storage'; | ||
import { mock } from "../../test/helper"; | ||
import { getMappedConfig } from "./getMappedConfig"; | ||
import { getAccountAlias } from '../../common/browser/cookies'; | ||
|
||
const getConfigMock = mock(getConfig); | ||
const getAccountAliasMock = mock(getAccountAlias); | ||
|
||
beforeEach(() => { | ||
getConfigMock.mockClear(); | ||
getAccountAliasMock.mockClear(); | ||
}); | ||
|
||
it('shows all roles when alias not matching any roles', async () => { | ||
getAccountAliasMock.mockImplementationOnce(() => Promise.resolve('invalid')); | ||
getConfigMock.mockImplementationOnce(() => Promise.resolve(` | ||
[org1] | ||
target_role_name = foo | ||
aws_account_id = org1 | ||
[role1] | ||
aws_account_id = bar1 | ||
source_profile = org1 | ||
[role2] | ||
aws_account_id = bar2 | ||
role_name = foo | ||
`)); | ||
expect(await getMappedConfig('')).toMatchInlineSnapshot(` | ||
[ | ||
{ | ||
"aws_account_id": "bar2", | ||
"role_name": "foo", | ||
"title": "role2", | ||
}, | ||
{ | ||
"aws_account_id": "bar1", | ||
"role_name": "foo", | ||
"source_profile_account_id": "org1", | ||
"title": "role1", | ||
}, | ||
] | ||
`); | ||
}); | ||
|
||
it('shows only role associated with source role when alias matching', async () => { | ||
getAccountAliasMock.mockImplementationOnce(() => Promise.resolve('org1')); | ||
getConfigMock.mockImplementationOnce(() => Promise.resolve(` | ||
[org1] | ||
target_role_name = foo | ||
aws_account_id = org1 | ||
[role1] | ||
aws_account_id = bar1 | ||
source_profile = org1 | ||
[role2] | ||
aws_account_id = bar2 | ||
role_name = foo | ||
`)); | ||
expect(await getMappedConfig('')).toMatchInlineSnapshot(` | ||
[ | ||
{ | ||
"aws_account_id": "bar1", | ||
"role_name": "foo", | ||
"source_profile_account_id": "org1", | ||
"title": "role1", | ||
}, | ||
] | ||
`); | ||
}); | ||
|
||
it('shows all roles when getAccountAlias errors', async () => { | ||
getAccountAliasMock.mockImplementationOnce(() => Promise.resolve(undefined)); | ||
getConfigMock.mockImplementationOnce(() => Promise.resolve(` | ||
[org1] | ||
target_role_name = foo | ||
aws_account_id = org1 | ||
[role1] | ||
aws_account_id = bar1 | ||
source_profile = org1 | ||
[role2] | ||
aws_account_id = bar2 | ||
role_name = foo | ||
`)); | ||
expect(await getMappedConfig('')).toMatchInlineSnapshot(` | ||
[ | ||
{ | ||
"aws_account_id": "bar2", | ||
"role_name": "foo", | ||
"title": "role2", | ||
}, | ||
{ | ||
"aws_account_id": "bar1", | ||
"role_name": "foo", | ||
"source_profile_account_id": "org1", | ||
"title": "role1", | ||
}, | ||
] | ||
`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { getAccountAlias } from '../../common/browser/cookies'; | ||
import { | ||
getConfig, | ||
mapConfig, | ||
parseConfig, | ||
filterBySourceAccountAlias, | ||
} from '../../common/config'; | ||
|
||
export const getMappedConfig = async (aliasUrl: string) => { | ||
const alias = await getAccountAlias(aliasUrl) ?? ''; | ||
return await getConfig() | ||
.then(parseConfig) | ||
.then(mapConfig) | ||
.then(filterBySourceAccountAlias(alias)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { browserOrChrome } from "."; | ||
|
||
export const getAccountAlias = async (url: string) => browserOrChrome().cookies.get({url, name: 'aws-account-alias'}) | ||
.then(cookie => cookie?.value) | ||
.catch(() => undefined); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import { filterBySourceAccountAlias } from "./filterBySourceAccountAlias"; | ||
|
||
it('should filter by source_profile_Account_id', () => { | ||
const config = filterBySourceAccountAlias('org1')([ | ||
{ title: 'role1', aws_account_id: '1234', role_name: 'foo', source_profile_account_id: 'org1' }, | ||
{ title: 'role1', aws_account_id: '1234', role_name: 'foo', source_profile_account_id: 'org1' }, | ||
{ title: 'role2', aws_account_id: '1234', role_name: 'foo', source_profile_account_id: 'org2' }, | ||
{ title: 'role3', aws_account_id: '1234', role_name: 'foo' }, | ||
]); | ||
expect(config).toMatchInlineSnapshot(` | ||
[ | ||
{ | ||
"aws_account_id": "1234", | ||
"role_name": "foo", | ||
"source_profile_account_id": "org1", | ||
"title": "role1", | ||
}, | ||
{ | ||
"aws_account_id": "1234", | ||
"role_name": "foo", | ||
"source_profile_account_id": "org1", | ||
"title": "role1", | ||
}, | ||
] | ||
`); | ||
}); | ||
|
||
it('should return all roles when alias empty', () => { | ||
const config = filterBySourceAccountAlias('')([ | ||
{ title: 'role1', aws_account_id: '1234', role_name: 'foo', source_profile_account_id: 'org1' }, | ||
{ title: 'role1', aws_account_id: '1234', role_name: 'foo', source_profile_account_id: 'org1' }, | ||
{ title: 'role2', aws_account_id: '1234', role_name: 'foo', source_profile_account_id: 'org2' }, | ||
{ title: 'role3', aws_account_id: '1234', role_name: 'foo' }, | ||
]); | ||
expect(config).toMatchInlineSnapshot(` | ||
[ | ||
{ | ||
"aws_account_id": "1234", | ||
"role_name": "foo", | ||
"source_profile_account_id": "org1", | ||
"title": "role1", | ||
}, | ||
{ | ||
"aws_account_id": "1234", | ||
"role_name": "foo", | ||
"source_profile_account_id": "org1", | ||
"title": "role1", | ||
}, | ||
{ | ||
"aws_account_id": "1234", | ||
"role_name": "foo", | ||
"source_profile_account_id": "org2", | ||
"title": "role2", | ||
}, | ||
{ | ||
"aws_account_id": "1234", | ||
"role_name": "foo", | ||
"title": "role3", | ||
}, | ||
] | ||
`); | ||
}); | ||
|
||
it('should return all when no alias match source_profile_Account_id', () => { | ||
const config = filterBySourceAccountAlias('')([ | ||
{ title: 'role1', aws_account_id: '1234', role_name: 'foo', source_profile_account_id: 'org1' }, | ||
{ title: 'role1', aws_account_id: '1234', role_name: 'foo', source_profile_account_id: 'org1' }, | ||
{ title: 'role2', aws_account_id: '1234', role_name: 'foo', source_profile_account_id: 'org2' }, | ||
{ title: 'role3', aws_account_id: '1234', role_name: 'foo' }, | ||
]); | ||
expect(config).toMatchInlineSnapshot(` | ||
[ | ||
{ | ||
"aws_account_id": "1234", | ||
"role_name": "foo", | ||
"source_profile_account_id": "org1", | ||
"title": "role1", | ||
}, | ||
{ | ||
"aws_account_id": "1234", | ||
"role_name": "foo", | ||
"source_profile_account_id": "org1", | ||
"title": "role1", | ||
}, | ||
{ | ||
"aws_account_id": "1234", | ||
"role_name": "foo", | ||
"source_profile_account_id": "org2", | ||
"title": "role2", | ||
}, | ||
{ | ||
"aws_account_id": "1234", | ||
"role_name": "foo", | ||
"title": "role3", | ||
}, | ||
] | ||
`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export const filterBySourceAccountAlias = (alias: string) => (config: AWSConfig) => { | ||
const hasSourceAccountAlias = !!config.find((configItem) => configItem.source_profile_account_id === alias); | ||
return config.filter((configItem: AWSConfigItem) => { | ||
return ( | ||
!alias || | ||
!hasSourceAccountAlias || | ||
configItem.source_profile_account_id === alias | ||
); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.