From 4695be055de2cec5198ffe302047ad763d026975 Mon Sep 17 00:00:00 2001 From: Toshimitsu Takahashi Date: Sat, 21 Oct 2023 00:29:47 +0900 Subject: [PATCH] fix load_aws_config --- src/js/lib/load_aws_config.js | 15 ++++++++++++++- src/js/lib/load_aws_config.test.js | 14 +++++++------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/js/lib/load_aws_config.js b/src/js/lib/load_aws_config.js index 99b3514..1ed2bc0 100644 --- a/src/js/lib/load_aws_config.js +++ b/src/js/lib/load_aws_config.js @@ -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; } diff --git a/src/js/lib/load_aws_config.test.js b/src/js/lib/load_aws_config.test.js index d1a2380..72605bc 100644 --- a/src/js/lib/load_aws_config.test.js +++ b/src/js/lib/load_aws_config.test.js @@ -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 }); }) }) @@ -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 }); }) }) @@ -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 }); }) })