From 6664447d291eb09eb6812203c15847bd3bf9bca9 Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Wed, 8 Jul 2020 12:00:25 +0200 Subject: [PATCH] Fix setup command breaks if .aws/config does not exists Signed-off-by: Nicolas De Loof --- ecs/cmd/commands/setup.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/ecs/cmd/commands/setup.go b/ecs/cmd/commands/setup.go index 6d52664f9..be876d666 100644 --- a/ecs/cmd/commands/setup.go +++ b/ecs/cmd/commands/setup.go @@ -3,6 +3,7 @@ package commands import ( "fmt" "os" + "path/filepath" "reflect" "strings" @@ -101,10 +102,17 @@ func saveCredentials(profile string, accessKeyID string, secretAccessKey string) } if err.(awserr.Error).Code() == "SharedCredsLoad" && err.(awserr.Error).Message() == "failed to load shared credentials file" { - os.Create(p.Filename) + err = os.MkdirAll(filepath.Dir(p.Filename), 0700) + if err != nil { + return err + } + _, err = os.Create(p.Filename) + if err != nil { + return err + } } - credIni, err := ini.Load(p.Filename) + credIni, err := ini.LooseLoad(p.Filename) if err != nil { return err } @@ -122,7 +130,7 @@ func awsProfiles(filename string) (map[string]ini.Section, error) { if filename == "" { filename = defaults.SharedConfigFilename() } - credIni, err := ini.Load(filename) + credIni, err := ini.LooseLoad(filename) if err != nil { return nil, err }