1
0
mirror of https://github.com/docker/docker-credential-helpers.git synced 2026-06-13 16:01:28 +05:30
Files
docker-credential-helpers/vendor/github.com/danieljoos/wincred/wincred.go
T
2016-07-16 11:59:43 -07:00

75 lines
2.2 KiB
Go

package wincred
import (
"syscall"
)
// Get the generic credential with the given name from Windows credential manager
func GetGenericCredential(targetName string) (*GenericCredential, error) {
cred, err := nativeCredRead(targetName, naCRED_TYPE_GENERIC)
if cred != nil {
return &GenericCredential{*cred}, err
}
return nil, err
}
// Create a new generic credential with the given name
func NewGenericCredential(targetName string) (result *GenericCredential) {
result = new(GenericCredential)
result.TargetName = targetName
result.Persist = PersistLocalMachine
return
}
// Persist the credential to Windows credential manager
func (t *GenericCredential) Write() (err error) {
err = nativeCredWrite(&t.Credential, naCRED_TYPE_GENERIC)
return
}
// Delete the credential from Windows credential manager
func (t *GenericCredential) Delete() (err error) {
err = nativeCredDelete(&t.Credential, naCRED_TYPE_GENERIC)
return
}
// Get the domain password credential with the given target host name
func GetDomainPassword(targetName string) (*DomainPassword, error) {
cred, err := nativeCredRead(targetName, naCRED_TYPE_DOMAIN_PASSWORD)
if cred != nil {
return &DomainPassword{*cred}, err
}
return nil, err
}
// Create a new domain password credential used for login to the given target host name
func NewDomainPassword(targetName string) (result *DomainPassword) {
result = new(DomainPassword)
result.TargetName = targetName
result.Persist = PersistLocalMachine
return
}
// Persist the domain password credential to Windows credential manager
func (t *DomainPassword) Write() (err error) {
err = nativeCredWrite(&t.Credential, naCRED_TYPE_DOMAIN_PASSWORD)
return
}
// Delete the domain password credential from Windows credential manager
func (t *DomainPassword) Delete() (err error) {
err = nativeCredDelete(&t.Credential, naCRED_TYPE_DOMAIN_PASSWORD)
return
}
// Set the CredentialBlob field of a domain password credential
// using an UTF16 encoded password string
func (t *DomainPassword) SetPassword(pw string) {
t.CredentialBlob = utf16ToByte(syscall.StringToUTF16(pw))
}
// List the contents of the Credentials store
func List() ([]*Credential, error) {
return nativeCredEnumerate("", true)
}