From 6c2d0edfa9017d732ac5b6521da18c9afb980492 Mon Sep 17 00:00:00 2001 From: Evan Simkowitz Date: Tue, 18 Feb 2025 12:12:38 -0800 Subject: [PATCH] Gracefully handle missing AWS config files in ParseProfiles --- pkg/remote/awsconn/awsconn.go | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/pkg/remote/awsconn/awsconn.go b/pkg/remote/awsconn/awsconn.go index 5c84532b7f..69e4cab5ed 100644 --- a/pkg/remote/awsconn/awsconn.go +++ b/pkg/remote/awsconn/awsconn.go @@ -96,17 +96,18 @@ func getTempFileFromConfig(config waveobj.MetaMapType, key string, profile strin func ParseProfiles() map[string]struct{} { profiles := make(map[string]struct{}) - fname := config.DefaultSharedConfigFilename() // Get aws.config default shared configuration file name - f, err := ini.Load(fname) // Load ini file + fname := config.DefaultSharedConfigFilename() + errs := []error{} + f, err := ini.Load(fname) // Load ini file if err != nil { - log.Printf("error reading aws config file: %v", err) - return nil - } - for _, v := range f.Sections() { - if len(v.Keys()) != 0 { // Get only the sections having Keys - parts := strings.Split(v.Name(), " ") - if len(parts) == 2 && parts[0] == "profile" { // skip default - profiles[ProfilePrefix+parts[1]] = struct{}{} + errs = append(errs, err) + } else { + for _, v := range f.Sections() { + if len(v.Keys()) != 0 { // Get only the sections having Keys + parts := strings.Split(v.Name(), " ") + if len(parts) == 2 && parts[0] == "profile" { // skip default + profiles[ProfilePrefix+parts[1]] = struct{}{} + } } } } @@ -114,11 +115,14 @@ func ParseProfiles() map[string]struct{} { fname = config.DefaultSharedCredentialsFilename() f, err = ini.Load(fname) if err != nil { - log.Printf("error reading aws credentials file: %v", err) - return nil + errs = append(errs, err) + } else { + for _, v := range f.Sections() { + profiles[ProfilePrefix+v.Name()] = struct{}{} + } } - for _, v := range f.Sections() { - profiles[ProfilePrefix+v.Name()] = struct{}{} + if len(errs) > 0 { + log.Printf("error reading aws config/credentials file: %v", errs) } return profiles }