Skip to content
Closed
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
11 changes: 6 additions & 5 deletions wincred/wincred.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,18 @@ import (
"github.com/docker/docker-credential-helpers/registryurl"
)

var credsLabel = []byte(credentials.CredsLabel)

// Wincred handles secrets using the Windows credential service.
type Wincred struct{}

// Add adds new credentials to the windows credentials manager.
func (h Wincred) Add(creds *credentials.Credentials) error {
credsLabels := []byte(credentials.CredsLabel)
g := winc.NewGenericCredential(creds.ServerURL)
g.UserName = creds.Username
g.CredentialBlob = []byte(creds.Secret)
g.Persist = winc.PersistLocalMachine
g.Attributes = []winc.CredentialAttribute{{Keyword: "label", Value: credsLabels}}
g.Attributes = []winc.CredentialAttribute{{Keyword: "label", Value: credsLabel}}

return g.Write()
}
Expand Down Expand Up @@ -53,7 +54,7 @@ func (h Wincred) Get(serverURL string) (string, string, error) {
}

for _, attr := range g.Attributes {
if attr.Keyword == "label" && bytes.Equal(attr.Value, []byte(credentials.CredsLabel)) {
if attr.Keyword == "label" && bytes.Equal(attr.Value, credsLabel) {
return g.UserName, string(g.CredentialBlob), nil
}
}
Expand All @@ -74,7 +75,7 @@ func getTarget(serverURL string) (string, error) {
var targets []string
for _, cred := range creds {
for _, attr := range cred.Attributes {
if attr.Keyword == "label" && bytes.Equal(attr.Value, []byte(credentials.CredsLabel)) {
if attr.Keyword == "label" && bytes.Equal(attr.Value, credsLabel) {
targets = append(targets, cred.TargetName)
}
}
Expand Down Expand Up @@ -135,7 +136,7 @@ func (h Wincred) List() (map[string]string, error) {

for _, cred := range creds {
for _, attr := range cred.Attributes {
if attr.Keyword == "label" && bytes.Equal(attr.Value, []byte(credentials.CredsLabel)) {
if attr.Keyword == "label" && bytes.Equal(attr.Value, credsLabel) {
resp[cred.TargetName] = cred.UserName
break
}
Expand Down