Skip to content

Commit

Permalink
Merge pull request #310 from tilfinltd/fix/load-aws-config
Browse files Browse the repository at this point in the history
Fix loadAwsConfig
  • Loading branch information
tilfin authored Oct 20, 2023
2 parents 07c418f + 4695be0 commit d8c897d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
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

0 comments on commit d8c897d

Please sign in to comment.