Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix loadAwsConfig #310

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/js/lib/load_aws_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,18 @@ class AwsConfigIniParser {

export function loadAwsConfig(text) {
const parser = new AwsConfigIniParser()
return parser.load(text);
const items = parser.load(text);

// Set single flag to independent profiles
const sourceProfileSet = new Set();
items.forEach(it => {
if (it.source_profile) sourceProfileSet.add(it.source_profile);
});
items.forEach(it => {
if (!it.source_profile && !sourceProfileSet.has(it.profile)) {
it.single = true;
}
});

return items;
}
14 changes: 7 additions & 7 deletions src/js/lib/load_aws_config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ aws_account_id = 987654321988
role_name = athirdrole
image = "https://via.placeholder.com/150"
`);
expect(results[0]).to.deep.equal({ profile: 'marketingadmin', aws_account_id: '123456789012', role_name: 'marketingadmin', color: 'ffaaee' });
expect(results[1]).to.deep.equal({ profile: 'anotheraccount', aws_account_id: '987654321987', role_name: 'anotherrole', region: 'ap-northeast-1' });
expect(results[2]).to.deep.equal({ profile: 'athirdaccount', aws_account_id: '987654321988', role_name: 'athirdrole', image: '"https://via.placeholder.com/150"' });
expect(results[0]).to.deep.equal({ profile: 'marketingadmin', aws_account_id: '123456789012', role_name: 'marketingadmin', color: 'ffaaee', single: true });
expect(results[1]).to.deep.equal({ profile: 'anotheraccount', aws_account_id: '987654321987', role_name: 'anotherrole', region: 'ap-northeast-1', single: true });
expect(results[2]).to.deep.equal({ profile: 'athirdaccount', aws_account_id: '987654321988', role_name: 'athirdrole', image: '"https://via.placeholder.com/150"', single: true });
})
})

Expand Down Expand Up @@ -56,7 +56,7 @@ aws_account_id = account-3-alias
expect(results[2]).to.deep.equal({ profile: 'Org1-Account1-Role2', aws_account_id: '123456789013', role_name: 'Role2', source_profile: 'organization1' });
expect(results[3]).to.deep.equal({ profile: 'baseaccount2', aws_account_id: '000000000000' });
expect(results[4]).to.deep.equal({ profile: 'Base2/Role1', aws_account_id: '234567890123', role_name: 'Role1', source_profile: 'baseaccount2' });
expect(results[5]).to.deep.equal({ profile: 'AnotherRole', aws_account_id: 'account-3-alias', role_name: 'SomeOtherRole' });
expect(results[5]).to.deep.equal({ profile: 'AnotherRole', aws_account_id: 'account-3-alias', role_name: 'SomeOtherRole', single: true });
})
})

Expand All @@ -75,9 +75,9 @@ role_arn = arn:aws:iam::123456789012:role/role-b;
role_arn = arn:aws:iam::123456789012:role/c ;comment
; comment
`);
expect(results[0]).to.deep.equal({ profile: 'a', aws_account_id: '123456789012', role_name: 'roleA' });
expect(results[1]).to.deep.equal({ profile: 'B', aws_account_id: '123456789012', role_name: 'role-b' });
expect(results[2]).to.deep.equal({ profile: 'profileC', aws_account_id: '123456789012', role_name: 'c' });
expect(results[0]).to.deep.equal({ profile: 'a', aws_account_id: '123456789012', role_name: 'roleA', single: true });
expect(results[1]).to.deep.equal({ profile: 'B', aws_account_id: '123456789012', role_name: 'role-b', single: true });
expect(results[2]).to.deep.equal({ profile: 'profileC', aws_account_id: '123456789012', role_name: 'c', single: true });
})
})

Expand Down