Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions pkg/remote/awsconn/awsconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,29 +96,33 @@ 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{}{}
}
}
}
}

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{}{}
}
Comment on lines +120 to +122
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Apply consistent empty section handling for credentials file.

The config file checks for non-empty sections (len(v.Keys()) != 0), but the credentials file doesn't. This could lead to including invalid/empty profiles.

Apply this diff to make the handling consistent:

-		for _, v := range f.Sections() {
-			profiles[ProfilePrefix+v.Name()] = struct{}{}
-		}
+		for _, v := range f.Sections() {
+			if len(v.Keys()) != 0 {
+				profiles[ProfilePrefix+v.Name()] = struct{}{}
+			}
+		}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
for _, v := range f.Sections() {
profiles[ProfilePrefix+v.Name()] = struct{}{}
}
for _, v := range f.Sections() {
if len(v.Keys()) != 0 {
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
}
Expand Down
Loading