Skip to content

Commit 7cd6378

Browse files
authored
Merge pull request #428 from thaJeztah/wincred_cleanups
wincred: minor cleanups
2 parents ed71c9e + 390d43e commit 7cd6378

1 file changed

Lines changed: 9 additions & 15 deletions

File tree

wincred/wincred.go

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package wincred
55
import (
66
"bytes"
77
"net/url"
8-
"strings"
98

109
winc "github.com/danieljoos/wincred"
1110
"github.com/docker/docker-credential-helpers/credentials"
@@ -54,9 +53,7 @@ func (h Wincred) Get(serverURL string) (string, string, error) {
5453
}
5554

5655
for _, attr := range g.Attributes {
57-
if strings.Compare(attr.Keyword, "label") == 0 &&
58-
bytes.Compare(attr.Value, []byte(credentials.CredsLabel)) == 0 {
59-
56+
if attr.Keyword == "label" && bytes.Equal(attr.Value, []byte(credentials.CredsLabel)) {
6057
return g.UserName, string(g.CredentialBlob), nil
6158
}
6259
}
@@ -75,11 +72,10 @@ func getTarget(serverURL string) (string, error) {
7572
}
7673

7774
var targets []string
78-
for i := range creds {
79-
attrs := creds[i].Attributes
80-
for _, attr := range attrs {
75+
for _, cred := range creds {
76+
for _, attr := range cred.Attributes {
8177
if attr.Keyword == "label" && bytes.Equal(attr.Value, []byte(credentials.CredsLabel)) {
82-
targets = append(targets, creds[i].TargetName)
78+
targets = append(targets, cred.TargetName)
8379
}
8480
}
8581
}
@@ -136,16 +132,14 @@ func (h Wincred) List() (map[string]string, error) {
136132
}
137133

138134
resp := make(map[string]string)
139-
for i := range creds {
140-
attrs := creds[i].Attributes
141-
for _, attr := range attrs {
142-
if strings.Compare(attr.Keyword, "label") == 0 &&
143-
bytes.Compare(attr.Value, []byte(credentials.CredsLabel)) == 0 {
144135

145-
resp[creds[i].TargetName] = creds[i].UserName
136+
for _, cred := range creds {
137+
for _, attr := range cred.Attributes {
138+
if attr.Keyword == "label" && bytes.Equal(attr.Value, []byte(credentials.CredsLabel)) {
139+
resp[cred.TargetName] = cred.UserName
140+
break
146141
}
147142
}
148-
149143
}
150144

151145
return resp, nil

0 commit comments

Comments
 (0)