Skip to content

Commit 2a8670e

Browse files
committed
Cleanup original modifications to the exposed APIs
Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com>
1 parent c5fbd3a commit 2a8670e

File tree

10 files changed

+26
-34
lines changed

10 files changed

+26
-34
lines changed

client/client_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ func ExampleStore() {
106106

107107
func TestStore(t *testing.T) {
108108
valid := []credentials.Credentials{
109-
{credentials.CredsLabel, validServerAddress, "foo", "bar"},
110-
{credentials.CredsLabel, validServerAddress2, "<token>", "abcd1234"},
109+
{validServerAddress, "foo", "bar"},
110+
{validServerAddress2, "<token>", "abcd1234"},
111111
}
112112

113113
for _, v := range valid {
@@ -117,7 +117,7 @@ func TestStore(t *testing.T) {
117117
}
118118

119119
invalid := []credentials.Credentials{
120-
{credentials.CredsLabel, invalidServerAddress, "foo", "bar"},
120+
{invalidServerAddress, "foo", "bar"},
121121
}
122122

123123
for _, v := range invalid {
@@ -140,8 +140,8 @@ func ExampleGet() {
140140

141141
func TestGet(t *testing.T) {
142142
valid := []credentials.Credentials{
143-
{credentials.CredsLabel, validServerAddress, "foo", "bar"},
144-
{credentials.CredsLabel, validServerAddress2, "<token>", "abcd1234"},
143+
{validServerAddress, "foo", "bar"},
144+
{validServerAddress2, "<token>", "abcd1234"},
145145
}
146146

147147
for _, v := range valid {

credentials/credentials.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ import (
1212

1313
// Credentials holds the information shared between docker and the credentials store.
1414
type Credentials struct {
15-
Label string
1615
ServerURL string
1716
Username string
1817
Secret string
1918
}
2019

21-
// Docker credentials should be labeled as such in credential stores, this label
22-
// allow us to filter out non-Docker credentials at lookup
20+
// Docker credentials should be labeled as such in credentials stores that allow labelling.
21+
// That label allows to filter out non-Docker credentials too at lookup/search in macOS keychain,
22+
// Windows credentials manager and Linux libsecret.
2323
const CredsLabel = "Docker Credentials"
2424

2525
// Serve initializes the credentials helper and parses the action argument.
@@ -77,8 +77,6 @@ func Store(helper Helper, reader io.Reader) error {
7777
return err
7878
}
7979

80-
creds.Label = CredsLabel
81-
8280
return helper.Add(&creds)
8381
}
8482

@@ -140,7 +138,7 @@ func Erase(helper Helper, reader io.Reader) error {
140138
//List returns all the serverURLs of keys in
141139
//the OS store as a list of strings
142140
func List(helper Helper, writer io.Writer) error {
143-
accts, err := helper.List(CredsLabel)
141+
accts, err := helper.List()
144142
if err != nil {
145143
return err
146144
}

credentials/credentials_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (m *memoryStore) Get(serverURL string) (string, string, error) {
3636
return c.Username, c.Secret, nil
3737
}
3838

39-
func (m *memoryStore) List(credsLabel string) (map[string]string, error) {
39+
func (m *memoryStore) List() (map[string]string, error) {
4040
//Simply a placeholder to let memoryStore be a valid implementation of Helper interface
4141
return nil, nil
4242
}

credentials/helper.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ type Helper interface {
99
// Get retrieves credentials from the store.
1010
// It returns username and secret as strings.
1111
Get(serverURL string) (string, string, error)
12-
// List returns the stored serverURLs and their associated usernames
13-
// for a given credentials label.
14-
List(credsLabel string) (map[string]string, error)
12+
// List returns the stored serverURLs and their associated usernames.
13+
List() (map[string]string, error)
1514
}

osxkeychain/osxkeychain_darwin.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func (h Osxkeychain) Add(creds *credentials.Credentials) error {
3535
}
3636
defer freeServer(s)
3737

38-
label := C.CString(creds.Label)
38+
label := C.CString(credentials.CredsLabel)
3939
defer C.free(unsafe.Pointer(label))
4040
username := C.CString(creds.Username)
4141
defer C.free(unsafe.Pointer(username))
@@ -100,8 +100,8 @@ func (h Osxkeychain) Get(serverURL string) (string, string, error) {
100100
}
101101

102102
// List returns the stored URLs and corresponding usernames.
103-
func (h Osxkeychain) List(credsLabel string) (map[string]string, error) {
104-
credsLabelC := C.CString(credsLabel)
103+
func (h Osxkeychain) List() (map[string]string, error) {
104+
credsLabelC := C.CString(credentials.CredsLabel)
105105
defer C.free(unsafe.Pointer(credsLabelC))
106106

107107
var pathsC **C.char

osxkeychain/osxkeychain_darwin_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@ import (
77

88
func TestOSXKeychainHelper(t *testing.T) {
99
creds := &credentials.Credentials{
10-
Label: credentials.CredsLabel,
1110
ServerURL: "https://foobar.docker.io:2376/v1",
1211
Username: "foobar",
1312
Secret: "foobarbaz",
1413
}
1514
creds1 := &credentials.Credentials{
16-
Label: credentials.CredsLabel,
1715
ServerURL: "https://foobar.docker.io:2376/v2",
1816
Username: "foobarbaz",
1917
Secret: "foobar",
@@ -36,14 +34,14 @@ func TestOSXKeychainHelper(t *testing.T) {
3634
t.Fatalf("expected %s, got %s\n", "foobarbaz", secret)
3735
}
3836

39-
auths, err := helper.List(credentials.CredsLabel)
37+
auths, err := helper.List()
4038
if err != nil || len(auths) == 0 {
4139
t.Fatal(err)
4240
}
4341

4442
helper.Add(creds1)
4543
defer helper.Delete(creds1.ServerURL)
46-
newauths, err := helper.List(credentials.CredsLabel)
44+
newauths, err := helper.List()
4745
if len(newauths)-len(auths) != 1 {
4846
if err == nil {
4947
t.Fatalf("Error: len(newauths): %d, len(auths): %d", len(newauths), len(auths))

secretservice/secretservice_linux.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func (h Secretservice) Add(creds *credentials.Credentials) error {
2222
if creds == nil {
2323
return errors.New("missing credentials")
2424
}
25-
credsLabel := C.CString(creds.Label)
25+
credsLabel := C.CString(credentials.CredsLabel)
2626
defer C.free(unsafe.Pointer(credsLabel))
2727
server := C.CString(creds.ServerURL)
2828
defer C.free(unsafe.Pointer(server))
@@ -82,8 +82,8 @@ func (h Secretservice) Get(serverURL string) (string, string, error) {
8282
}
8383

8484
// List returns the stored URLs and corresponding usernames for a given credentials label
85-
func (h Secretservice) List(credsLabel string) (map[string]string, error) {
86-
credsLabelC := C.CString(credsLabel)
85+
func (h Secretservice) List() (map[string]string, error) {
86+
credsLabelC := C.CString(credentials.CredsLabel)
8787
defer C.free(unsafe.Pointer(credsLabelC))
8888

8989
var pathsC **C.char

secretservice/secretservice_linux_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ func TestSecretServiceHelper(t *testing.T) {
1010
t.Skip("test requires gnome-keyring but travis CI doesn't have it")
1111

1212
creds := &credentials.Credentials{
13-
Label: credentials.CredsLabel,
1413
ServerURL: "https://foobar.docker.io:2376/v1",
1514
Username: "foobar",
1615
Secret: "foobarbaz",
@@ -37,12 +36,12 @@ func TestSecretServiceHelper(t *testing.T) {
3736
if err := helper.Delete(creds.ServerURL); err != nil {
3837
t.Fatal(err)
3938
}
40-
auths, err := helper.List(credentials.CredsLabel)
39+
auths, err := helper.List()
4140
if err != nil || len(auths) == 0 {
4241
t.Fatal(err)
4342
}
4443
helper.Add(creds)
45-
if newauths, err := helper.List(credentials.CredsLabel); (len(newauths) - len(auths)) != 1 {
44+
if newauths, err := helper.List(); (len(newauths) - len(auths)) != 1 {
4645
t.Fatal(err)
4746
}
4847
}

wincred/wincred_windows.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func (h Wincred) Add(creds *credentials.Credentials) error {
1616
g.UserName = creds.Username
1717
g.CredentialBlob = []byte(creds.Secret)
1818
g.Persist = winc.PersistLocalMachine
19-
g.Attributes = []winc.CredentialAttribute{{"label", []byte(creds.Label)}}
19+
g.Attributes = []winc.CredentialAttribute{{"label", []byte(credentials.CredsLabel)}}
2020

2121
return g.Write()
2222
}
@@ -43,7 +43,7 @@ func (h Wincred) Get(serverURL string) (string, string, error) {
4343
}
4444

4545
// List returns the stored URLs and corresponding usernames for a given credentials label.
46-
func (h Wincred) List(credsLabel string) (map[string]string, error) {
46+
func (h Wincred) List() (map[string]string, error) {
4747
creds, err := winc.List()
4848
if err != nil {
4949
return nil, err

wincred/wincred_windows_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@ import (
88

99
func TestWinCredHelper(t *testing.T) {
1010
creds := &credentials.Credentials{
11-
Label: credentials.CredsLabel,
1211
ServerURL: "https://foobar.docker.io:2376/v1",
1312
Username: "foobar",
1413
Secret: "foobarbaz",
1514
}
1615
creds1 := &credentials.Credentials{
17-
Label: credentials.CredsLabel,
1816
ServerURL: "https://foobar.docker.io:2376/v2",
1917
Username: "foobarbaz",
2018
Secret: "foobar",
@@ -38,14 +36,14 @@ func TestWinCredHelper(t *testing.T) {
3836
t.Fatalf("expected %s, got %s\n", "foobarbaz", secret)
3937
}
4038

41-
auths, err := helper.List(credentials.CredsLabel)
39+
auths, err := helper.List()
4240
if err != nil || len(auths) == 0 {
4341
t.Fatal(err)
4442
}
4543

4644
helper.Add(creds1)
4745
defer helper.Delete(creds1.ServerURL)
48-
newauths, err := helper.List(credentials.CredsLabel)
46+
newauths, err := helper.List()
4947
if err != nil {
5048
t.Fatal(err)
5149
}

0 commit comments

Comments
 (0)