Skip to content

Commit b2e261a

Browse files
committed
wincred: avoid repeated string->[]byte conversion
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent ca5e83c commit b2e261a

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

wincred/wincred.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,18 @@ import (
1111
"github.com/docker/docker-credential-helpers/registryurl"
1212
)
1313

14+
var credsLabel = []byte(credentials.CredsLabel)
15+
1416
// Wincred handles secrets using the Windows credential service.
1517
type Wincred struct{}
1618

1719
// Add adds new credentials to the windows credentials manager.
1820
func (h Wincred) Add(creds *credentials.Credentials) error {
19-
credsLabels := []byte(credentials.CredsLabel)
2021
g := winc.NewGenericCredential(creds.ServerURL)
2122
g.UserName = creds.Username
2223
g.CredentialBlob = []byte(creds.Secret)
2324
g.Persist = winc.PersistLocalMachine
24-
g.Attributes = []winc.CredentialAttribute{{Keyword: "label", Value: credsLabels}}
25+
g.Attributes = []winc.CredentialAttribute{{Keyword: "label", Value: credsLabel}}
2526

2627
return g.Write()
2728
}
@@ -53,7 +54,7 @@ func (h Wincred) Get(serverURL string) (string, string, error) {
5354
}
5455

5556
for _, attr := range g.Attributes {
56-
if attr.Keyword == "label" && bytes.Equal(attr.Value, []byte(credentials.CredsLabel)) {
57+
if attr.Keyword == "label" && bytes.Equal(attr.Value, credsLabel) {
5758
return g.UserName, string(g.CredentialBlob), nil
5859
}
5960
}
@@ -74,7 +75,7 @@ func getTarget(serverURL string) (string, error) {
7475
var targets []string
7576
for _, cred := range creds {
7677
for _, attr := range cred.Attributes {
77-
if attr.Keyword == "label" && bytes.Equal(attr.Value, []byte(credentials.CredsLabel)) {
78+
if attr.Keyword == "label" && bytes.Equal(attr.Value, credsLabel) {
7879
targets = append(targets, cred.TargetName)
7980
}
8081
}
@@ -135,7 +136,7 @@ func (h Wincred) List() (map[string]string, error) {
135136

136137
for _, cred := range creds {
137138
for _, attr := range cred.Attributes {
138-
if attr.Keyword == "label" && bytes.Equal(attr.Value, []byte(credentials.CredsLabel)) {
139+
if attr.Keyword == "label" && bytes.Equal(attr.Value, credsLabel) {
139140
resp[cred.TargetName] = cred.UserName
140141
break
141142
}

0 commit comments

Comments
 (0)