From cb808dec31836d384153efb123dcd8d77170b2be Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Mon, 16 Nov 2020 14:50:39 +0100 Subject: [PATCH] Don't mess with exiting .aws/credentials Signed-off-by: Nicolas De Loof --- ecs/context.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/ecs/context.go b/ecs/context.go index 5d636ac37..8c76635cd 100644 --- a/ecs/context.go +++ b/ecs/context.go @@ -199,8 +199,15 @@ func (h contextCreateAWSHelper) saveCredentials(profile string, accessKeyID stri return err } - credIni := ini.Empty() - section, err := credIni.NewSection(profile) + credentials, err := ini.Load(file) + if err != nil { + if !os.IsNotExist(err) { + return err + } + credentials = ini.Empty() + } + + section, err := credentials.NewSection(profile) if err != nil { return err } @@ -212,7 +219,7 @@ func (h contextCreateAWSHelper) saveCredentials(profile string, accessKeyID stri if err != nil { return err } - return credIni.SaveTo(file) + return credentials.SaveTo(file) } func (h contextCreateAWSHelper) saveRegion(profile, region string) error {