Skip to content

Commit

Permalink
Merge pull request coreos#1105 from jlebon/pr/aliyun-profile-fix
Browse files Browse the repository at this point in the history
auth/aliyun: fix parsing config file
  • Loading branch information
jlebon authored Oct 23, 2019
2 parents 91f5902 + 4da3c9a commit 1b604c3
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions auth/aliyun.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ type AliyunProfile struct {
Region string `json:"region_id"`
}

type AliyunConfig struct {
Profiles []AliyunProfile `json:"profiles"`
}

// ReadAliyunConfig decodes an aliyun config file
//
// If path is empty, $HOME/.aliyun/config.json is read.
Expand All @@ -49,16 +53,16 @@ func ReadAliyunConfig(path string) (map[string]AliyunProfile, error) {
}
defer f.Close()

var profiles []AliyunProfile
if err := json.NewDecoder(f).Decode(&profiles); err != nil {
var config AliyunConfig
if err := json.NewDecoder(f).Decode(&config); err != nil {
return nil, err
}
if len(profiles) == 0 {
if len(config.Profiles) == 0 {
return nil, fmt.Errorf("aliyun config %q contains no profiles", path)
}

retProfiles := make(map[string]AliyunProfile)
for _, p := range profiles {
for _, p := range config.Profiles {
retProfiles[p.Name] = p
}

Expand Down

0 comments on commit 1b604c3

Please sign in to comment.