Fix setup command breaks if .aws/config does not exists

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De Loof 2020-07-08 12:00:25 +02:00
parent 98ec6c173b
commit 6664447d29
No known key found for this signature in database
GPG Key ID: 9858809D6F8F6E7E
1 changed files with 11 additions and 3 deletions

View File

@ -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
}