mirror of
https://github.com/docker/docker-credential-helpers.git
synced 2026-06-13 16:01:28 +05:30
Cleanup original modifications to the exposed APIs
Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com>
This commit is contained in:
@@ -106,8 +106,8 @@ func ExampleStore() {
|
|||||||
|
|
||||||
func TestStore(t *testing.T) {
|
func TestStore(t *testing.T) {
|
||||||
valid := []credentials.Credentials{
|
valid := []credentials.Credentials{
|
||||||
{credentials.CredsLabel, validServerAddress, "foo", "bar"},
|
{validServerAddress, "foo", "bar"},
|
||||||
{credentials.CredsLabel, validServerAddress2, "<token>", "abcd1234"},
|
{validServerAddress2, "<token>", "abcd1234"},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, v := range valid {
|
for _, v := range valid {
|
||||||
@@ -117,7 +117,7 @@ func TestStore(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
invalid := []credentials.Credentials{
|
invalid := []credentials.Credentials{
|
||||||
{credentials.CredsLabel, invalidServerAddress, "foo", "bar"},
|
{invalidServerAddress, "foo", "bar"},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, v := range invalid {
|
for _, v := range invalid {
|
||||||
@@ -140,8 +140,8 @@ func ExampleGet() {
|
|||||||
|
|
||||||
func TestGet(t *testing.T) {
|
func TestGet(t *testing.T) {
|
||||||
valid := []credentials.Credentials{
|
valid := []credentials.Credentials{
|
||||||
{credentials.CredsLabel, validServerAddress, "foo", "bar"},
|
{validServerAddress, "foo", "bar"},
|
||||||
{credentials.CredsLabel, validServerAddress2, "<token>", "abcd1234"},
|
{validServerAddress2, "<token>", "abcd1234"},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, v := range valid {
|
for _, v := range valid {
|
||||||
|
|||||||
@@ -12,14 +12,14 @@ import (
|
|||||||
|
|
||||||
// Credentials holds the information shared between docker and the credentials store.
|
// Credentials holds the information shared between docker and the credentials store.
|
||||||
type Credentials struct {
|
type Credentials struct {
|
||||||
Label string
|
|
||||||
ServerURL string
|
ServerURL string
|
||||||
Username string
|
Username string
|
||||||
Secret string
|
Secret string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Docker credentials should be labeled as such in credential stores, this label
|
// Docker credentials should be labeled as such in credentials stores that allow labelling.
|
||||||
// allow us to filter out non-Docker credentials at lookup
|
// That label allows to filter out non-Docker credentials too at lookup/search in macOS keychain,
|
||||||
|
// Windows credentials manager and Linux libsecret.
|
||||||
const CredsLabel = "Docker Credentials"
|
const CredsLabel = "Docker Credentials"
|
||||||
|
|
||||||
// Serve initializes the credentials helper and parses the action argument.
|
// Serve initializes the credentials helper and parses the action argument.
|
||||||
@@ -77,8 +77,6 @@ func Store(helper Helper, reader io.Reader) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
creds.Label = CredsLabel
|
|
||||||
|
|
||||||
return helper.Add(&creds)
|
return helper.Add(&creds)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,7 +138,7 @@ func Erase(helper Helper, reader io.Reader) error {
|
|||||||
//List returns all the serverURLs of keys in
|
//List returns all the serverURLs of keys in
|
||||||
//the OS store as a list of strings
|
//the OS store as a list of strings
|
||||||
func List(helper Helper, writer io.Writer) error {
|
func List(helper Helper, writer io.Writer) error {
|
||||||
accts, err := helper.List(CredsLabel)
|
accts, err := helper.List()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ func (m *memoryStore) Get(serverURL string) (string, string, error) {
|
|||||||
return c.Username, c.Secret, nil
|
return c.Username, c.Secret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *memoryStore) List(credsLabel string) (map[string]string, error) {
|
func (m *memoryStore) List() (map[string]string, error) {
|
||||||
//Simply a placeholder to let memoryStore be a valid implementation of Helper interface
|
//Simply a placeholder to let memoryStore be a valid implementation of Helper interface
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ type Helper interface {
|
|||||||
// Get retrieves credentials from the store.
|
// Get retrieves credentials from the store.
|
||||||
// It returns username and secret as strings.
|
// It returns username and secret as strings.
|
||||||
Get(serverURL string) (string, string, error)
|
Get(serverURL string) (string, string, error)
|
||||||
// List returns the stored serverURLs and their associated usernames
|
// List returns the stored serverURLs and their associated usernames.
|
||||||
// for a given credentials label.
|
List() (map[string]string, error)
|
||||||
List(credsLabel string) (map[string]string, error)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ func (h Osxkeychain) Add(creds *credentials.Credentials) error {
|
|||||||
}
|
}
|
||||||
defer freeServer(s)
|
defer freeServer(s)
|
||||||
|
|
||||||
label := C.CString(creds.Label)
|
label := C.CString(credentials.CredsLabel)
|
||||||
defer C.free(unsafe.Pointer(label))
|
defer C.free(unsafe.Pointer(label))
|
||||||
username := C.CString(creds.Username)
|
username := C.CString(creds.Username)
|
||||||
defer C.free(unsafe.Pointer(username))
|
defer C.free(unsafe.Pointer(username))
|
||||||
@@ -100,8 +100,8 @@ func (h Osxkeychain) Get(serverURL string) (string, string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// List returns the stored URLs and corresponding usernames.
|
// List returns the stored URLs and corresponding usernames.
|
||||||
func (h Osxkeychain) List(credsLabel string) (map[string]string, error) {
|
func (h Osxkeychain) List() (map[string]string, error) {
|
||||||
credsLabelC := C.CString(credsLabel)
|
credsLabelC := C.CString(credentials.CredsLabel)
|
||||||
defer C.free(unsafe.Pointer(credsLabelC))
|
defer C.free(unsafe.Pointer(credsLabelC))
|
||||||
|
|
||||||
var pathsC **C.char
|
var pathsC **C.char
|
||||||
|
|||||||
@@ -7,13 +7,11 @@ import (
|
|||||||
|
|
||||||
func TestOSXKeychainHelper(t *testing.T) {
|
func TestOSXKeychainHelper(t *testing.T) {
|
||||||
creds := &credentials.Credentials{
|
creds := &credentials.Credentials{
|
||||||
Label: credentials.CredsLabel,
|
|
||||||
ServerURL: "https://foobar.docker.io:2376/v1",
|
ServerURL: "https://foobar.docker.io:2376/v1",
|
||||||
Username: "foobar",
|
Username: "foobar",
|
||||||
Secret: "foobarbaz",
|
Secret: "foobarbaz",
|
||||||
}
|
}
|
||||||
creds1 := &credentials.Credentials{
|
creds1 := &credentials.Credentials{
|
||||||
Label: credentials.CredsLabel,
|
|
||||||
ServerURL: "https://foobar.docker.io:2376/v2",
|
ServerURL: "https://foobar.docker.io:2376/v2",
|
||||||
Username: "foobarbaz",
|
Username: "foobarbaz",
|
||||||
Secret: "foobar",
|
Secret: "foobar",
|
||||||
@@ -36,14 +34,14 @@ func TestOSXKeychainHelper(t *testing.T) {
|
|||||||
t.Fatalf("expected %s, got %s\n", "foobarbaz", secret)
|
t.Fatalf("expected %s, got %s\n", "foobarbaz", secret)
|
||||||
}
|
}
|
||||||
|
|
||||||
auths, err := helper.List(credentials.CredsLabel)
|
auths, err := helper.List()
|
||||||
if err != nil || len(auths) == 0 {
|
if err != nil || len(auths) == 0 {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
helper.Add(creds1)
|
helper.Add(creds1)
|
||||||
defer helper.Delete(creds1.ServerURL)
|
defer helper.Delete(creds1.ServerURL)
|
||||||
newauths, err := helper.List(credentials.CredsLabel)
|
newauths, err := helper.List()
|
||||||
if len(newauths)-len(auths) != 1 {
|
if len(newauths)-len(auths) != 1 {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("Error: len(newauths): %d, len(auths): %d", len(newauths), len(auths))
|
t.Fatalf("Error: len(newauths): %d, len(auths): %d", len(newauths), len(auths))
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ func (h Secretservice) Add(creds *credentials.Credentials) error {
|
|||||||
if creds == nil {
|
if creds == nil {
|
||||||
return errors.New("missing credentials")
|
return errors.New("missing credentials")
|
||||||
}
|
}
|
||||||
credsLabel := C.CString(creds.Label)
|
credsLabel := C.CString(credentials.CredsLabel)
|
||||||
defer C.free(unsafe.Pointer(credsLabel))
|
defer C.free(unsafe.Pointer(credsLabel))
|
||||||
server := C.CString(creds.ServerURL)
|
server := C.CString(creds.ServerURL)
|
||||||
defer C.free(unsafe.Pointer(server))
|
defer C.free(unsafe.Pointer(server))
|
||||||
@@ -82,8 +82,8 @@ func (h Secretservice) Get(serverURL string) (string, string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// List returns the stored URLs and corresponding usernames for a given credentials label
|
// List returns the stored URLs and corresponding usernames for a given credentials label
|
||||||
func (h Secretservice) List(credsLabel string) (map[string]string, error) {
|
func (h Secretservice) List() (map[string]string, error) {
|
||||||
credsLabelC := C.CString(credsLabel)
|
credsLabelC := C.CString(credentials.CredsLabel)
|
||||||
defer C.free(unsafe.Pointer(credsLabelC))
|
defer C.free(unsafe.Pointer(credsLabelC))
|
||||||
|
|
||||||
var pathsC **C.char
|
var pathsC **C.char
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ func TestSecretServiceHelper(t *testing.T) {
|
|||||||
t.Skip("test requires gnome-keyring but travis CI doesn't have it")
|
t.Skip("test requires gnome-keyring but travis CI doesn't have it")
|
||||||
|
|
||||||
creds := &credentials.Credentials{
|
creds := &credentials.Credentials{
|
||||||
Label: credentials.CredsLabel,
|
|
||||||
ServerURL: "https://foobar.docker.io:2376/v1",
|
ServerURL: "https://foobar.docker.io:2376/v1",
|
||||||
Username: "foobar",
|
Username: "foobar",
|
||||||
Secret: "foobarbaz",
|
Secret: "foobarbaz",
|
||||||
@@ -37,12 +36,12 @@ func TestSecretServiceHelper(t *testing.T) {
|
|||||||
if err := helper.Delete(creds.ServerURL); err != nil {
|
if err := helper.Delete(creds.ServerURL); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
auths, err := helper.List(credentials.CredsLabel)
|
auths, err := helper.List()
|
||||||
if err != nil || len(auths) == 0 {
|
if err != nil || len(auths) == 0 {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
helper.Add(creds)
|
helper.Add(creds)
|
||||||
if newauths, err := helper.List(credentials.CredsLabel); (len(newauths) - len(auths)) != 1 {
|
if newauths, err := helper.List(); (len(newauths) - len(auths)) != 1 {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ func (h Wincred) Add(creds *credentials.Credentials) error {
|
|||||||
g.UserName = creds.Username
|
g.UserName = creds.Username
|
||||||
g.CredentialBlob = []byte(creds.Secret)
|
g.CredentialBlob = []byte(creds.Secret)
|
||||||
g.Persist = winc.PersistLocalMachine
|
g.Persist = winc.PersistLocalMachine
|
||||||
g.Attributes = []winc.CredentialAttribute{{"label", []byte(creds.Label)}}
|
g.Attributes = []winc.CredentialAttribute{{"label", []byte(credentials.CredsLabel)}}
|
||||||
|
|
||||||
return g.Write()
|
return g.Write()
|
||||||
}
|
}
|
||||||
@@ -43,7 +43,7 @@ func (h Wincred) Get(serverURL string) (string, string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// List returns the stored URLs and corresponding usernames for a given credentials label.
|
// List returns the stored URLs and corresponding usernames for a given credentials label.
|
||||||
func (h Wincred) List(credsLabel string) (map[string]string, error) {
|
func (h Wincred) List() (map[string]string, error) {
|
||||||
creds, err := winc.List()
|
creds, err := winc.List()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -8,13 +8,11 @@ import (
|
|||||||
|
|
||||||
func TestWinCredHelper(t *testing.T) {
|
func TestWinCredHelper(t *testing.T) {
|
||||||
creds := &credentials.Credentials{
|
creds := &credentials.Credentials{
|
||||||
Label: credentials.CredsLabel,
|
|
||||||
ServerURL: "https://foobar.docker.io:2376/v1",
|
ServerURL: "https://foobar.docker.io:2376/v1",
|
||||||
Username: "foobar",
|
Username: "foobar",
|
||||||
Secret: "foobarbaz",
|
Secret: "foobarbaz",
|
||||||
}
|
}
|
||||||
creds1 := &credentials.Credentials{
|
creds1 := &credentials.Credentials{
|
||||||
Label: credentials.CredsLabel,
|
|
||||||
ServerURL: "https://foobar.docker.io:2376/v2",
|
ServerURL: "https://foobar.docker.io:2376/v2",
|
||||||
Username: "foobarbaz",
|
Username: "foobarbaz",
|
||||||
Secret: "foobar",
|
Secret: "foobar",
|
||||||
@@ -38,14 +36,14 @@ func TestWinCredHelper(t *testing.T) {
|
|||||||
t.Fatalf("expected %s, got %s\n", "foobarbaz", secret)
|
t.Fatalf("expected %s, got %s\n", "foobarbaz", secret)
|
||||||
}
|
}
|
||||||
|
|
||||||
auths, err := helper.List(credentials.CredsLabel)
|
auths, err := helper.List()
|
||||||
if err != nil || len(auths) == 0 {
|
if err != nil || len(auths) == 0 {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
helper.Add(creds1)
|
helper.Add(creds1)
|
||||||
defer helper.Delete(creds1.ServerURL)
|
defer helper.Delete(creds1.ServerURL)
|
||||||
newauths, err := helper.List(credentials.CredsLabel)
|
newauths, err := helper.List()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user