Skip to content

Commit 7d02ef7

Browse files
committed
Merge pull request #8 from calavera/secret_name
Move away from password as a name. We store secrets.
2 parents bcc242e + 2275377 commit 7d02ef7

14 files changed

+59
-59
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Set the `credsStore` option in your `.docker/config.json` file with the suffix o
4545

4646
A credential helper can be any program that can read values from the standard input. We use the first argument in the command line to differentiate the kind of command to execute. There are three valid values:
4747

48-
- `store`: Adds credentials to the keychain. The payload in the standard input is a JSON document with `ServerURL`, `Username` and `Password`.
48+
- `store`: Adds credentials to the keychain. The payload in the standard input is a JSON document with `ServerURL`, `Username` and `Secret`.
4949
- `get`: Retrieves credentials from the keychain. The payload in the standard input is the raw value for the `ServerURL`.
5050
- `erase`: Removes credentials from the keychain. The payload in the standard input is the raw value for the `ServerURL`.
5151

credentials/credentials.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
type credentialsGetResponse struct {
1414
Username string
15-
Password string
15+
Secret string
1616
}
1717

1818
// Serve initializes the credentials helper and parses the action argument.
@@ -73,14 +73,14 @@ func get(helper Helper, reader io.Reader, writer io.Writer) error {
7373

7474
serverURL := strings.TrimSpace(buffer.String())
7575

76-
username, password, err := helper.Get(serverURL)
76+
username, secret, err := helper.Get(serverURL)
7777
if err != nil {
7878
return err
7979
}
8080

8181
resp := credentialsGetResponse{
8282
Username: username,
83-
Password: password,
83+
Secret: secret,
8484
}
8585

8686
buffer.Reset()

credentials/credentials_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ func (m *memoryStore) Get(serverURL string) (string, string, error) {
3333
if !ok {
3434
return "", "", fmt.Errorf("creds not found for %s", serverURL)
3535
}
36-
return c.Username, c.Password, nil
36+
return c.Username, c.Secret, nil
3737
}
3838

3939
func TestStore(t *testing.T) {
4040
serverURL := "https://index.docker.io/v1/"
4141
creds := &Credentials{
4242
ServerURL: serverURL,
4343
Username: "foo",
44-
Password: "bar",
44+
Secret: "bar",
4545
}
4646
b, err := json.Marshal(creds)
4747
if err != nil {
@@ -63,8 +63,8 @@ func TestStore(t *testing.T) {
6363
t.Fatalf("expected username foo, got %s\n", c.Username)
6464
}
6565

66-
if c.Password != "bar" {
67-
t.Fatalf("expected username bar, got %s\n", c.Password)
66+
if c.Secret != "bar" {
67+
t.Fatalf("expected username bar, got %s\n", c.Secret)
6868
}
6969
}
7070

@@ -73,7 +73,7 @@ func TestGet(t *testing.T) {
7373
creds := &Credentials{
7474
ServerURL: serverURL,
7575
Username: "foo",
76-
Password: "bar",
76+
Secret: "bar",
7777
}
7878
b, err := json.Marshal(creds)
7979
if err != nil {
@@ -105,8 +105,8 @@ func TestGet(t *testing.T) {
105105
t.Fatalf("expected username foo, got %s\n", c.Username)
106106
}
107107

108-
if c.Password != "bar" {
109-
t.Fatalf("expected username bar, got %s\n", c.Password)
108+
if c.Secret != "bar" {
109+
t.Fatalf("expected username bar, got %s\n", c.Secret)
110110
}
111111
}
112112

@@ -115,7 +115,7 @@ func TestErase(t *testing.T) {
115115
creds := &Credentials{
116116
ServerURL: serverURL,
117117
Username: "foo",
118-
Password: "bar",
118+
Secret: "bar",
119119
}
120120
b, err := json.Marshal(creds)
121121
if err != nil {

credentials/helper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import "errors"
66
type Credentials struct {
77
ServerURL string
88
Username string
9-
Password string
9+
Secret string
1010
}
1111

1212
// Helper is the interface a credentials store helper must implement.

osxkeychain/osxkeychain_darwin.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ char *get_error(OSStatus status) {
1010
return buf;
1111
}
1212

13-
char *keychain_add(struct Server *server, char *username, char *password) {
13+
char *keychain_add(struct Server *server, char *username, char *secret) {
1414
OSStatus status = SecKeychainAddInternetPassword(
1515
NULL,
1616
strlen(server->host), server->host,
@@ -20,7 +20,7 @@ char *keychain_add(struct Server *server, char *username, char *password) {
2020
server->port,
2121
server->proto,
2222
kSecAuthenticationTypeDefault,
23-
strlen(password), password,
23+
strlen(secret), secret,
2424
NULL
2525
);
2626
if (status) {
@@ -29,7 +29,7 @@ char *keychain_add(struct Server *server, char *username, char *password) {
2929
return NULL;
3030
}
3131

32-
char *keychain_get(struct Server *server, unsigned int *username_l, char **username, unsigned int *password_l, char **password) {
32+
char *keychain_get(struct Server *server, unsigned int *username_l, char **username, unsigned int *secret_l, char **secret) {
3333
char *tmp;
3434
SecKeychainItemRef item;
3535

@@ -42,14 +42,14 @@ char *keychain_get(struct Server *server, unsigned int *username_l, char **usern
4242
server->port,
4343
server->proto,
4444
kSecAuthenticationTypeDefault,
45-
password_l, (void **)&tmp,
45+
secret_l, (void **)&tmp,
4646
&item);
4747

4848
if (status) {
4949
return get_error(status);
5050
}
5151

52-
*password = strdup(tmp);
52+
*secret = strdup(tmp);
5353
SecKeychainItemFreeContent(NULL, tmp);
5454

5555
SecKeychainAttributeList list;

osxkeychain/osxkeychain_darwin.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ func (h osxkeychain) Add(creds *credentials.Credentials) error {
3939

4040
username := C.CString(creds.Username)
4141
defer C.free(unsafe.Pointer(username))
42-
password := C.CString(creds.Password)
43-
defer C.free(unsafe.Pointer(password))
42+
secret := C.CString(creds.Secret)
43+
defer C.free(unsafe.Pointer(secret))
4444

45-
errMsg := C.keychain_add(s, username, password)
45+
errMsg := C.keychain_add(s, username, secret)
4646
if errMsg != nil {
4747
defer C.free(unsafe.Pointer(errMsg))
4848
return errors.New(C.GoString(errMsg))
@@ -68,7 +68,7 @@ func (h osxkeychain) Delete(serverURL string) error {
6868
return nil
6969
}
7070

71-
// Get returns the username and password to use for a given registry server URL.
71+
// Get returns the username and secret to use for a given registry server URL.
7272
func (h osxkeychain) Get(serverURL string) (string, string, error) {
7373
s, err := splitServer(serverURL)
7474
if err != nil {
@@ -78,12 +78,12 @@ func (h osxkeychain) Get(serverURL string) (string, string, error) {
7878

7979
var usernameLen C.uint
8080
var username *C.char
81-
var passwordLen C.uint
82-
var password *C.char
81+
var secretLen C.uint
82+
var secret *C.char
8383
defer C.free(unsafe.Pointer(username))
84-
defer C.free(unsafe.Pointer(password))
84+
defer C.free(unsafe.Pointer(secret))
8585

86-
errMsg := C.keychain_get(s, &usernameLen, &username, &passwordLen, &password)
86+
errMsg := C.keychain_get(s, &usernameLen, &username, &secretLen, &secret)
8787
if errMsg != nil {
8888
defer C.free(unsafe.Pointer(errMsg))
8989
goMsg := C.GoString(errMsg)
@@ -96,7 +96,7 @@ func (h osxkeychain) Get(serverURL string) (string, string, error) {
9696
}
9797

9898
user := C.GoStringN(username, C.int(usernameLen))
99-
pass := C.GoStringN(password, C.int(passwordLen))
99+
pass := C.GoStringN(secret, C.int(secretLen))
100100
return user, pass, nil
101101
}
102102

osxkeychain/osxkeychain_darwin.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ struct Server {
77
unsigned int port;
88
};
99

10-
char *keychain_add(struct Server *server, char *username, char *password);
11-
char *keychain_get(struct Server *server, unsigned int *username_l, char **username, unsigned int *password_l, char **password);
10+
char *keychain_add(struct Server *server, char *username, char *secret);
11+
char *keychain_get(struct Server *server, unsigned int *username_l, char **username, unsigned int *secret_l, char **secret);
1212
char *keychain_delete(struct Server *server);

osxkeychain/osxkeychain_darwin_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ func TestOSXKeychainHelper(t *testing.T) {
1010
creds := &credentials.Credentials{
1111
ServerURL: "https://foobar.docker.io:2376/v1",
1212
Username: "foobar",
13-
Password: "foobarbaz",
13+
Secret: "foobarbaz",
1414
}
1515

1616
helper := New()
1717
if err := helper.Add(creds); err != nil {
1818
t.Fatal(err)
1919
}
2020

21-
username, password, err := helper.Get(creds.ServerURL)
21+
username, secret, err := helper.Get(creds.ServerURL)
2222
if err != nil {
2323
t.Fatal(err)
2424
}
@@ -27,8 +27,8 @@ func TestOSXKeychainHelper(t *testing.T) {
2727
t.Fatalf("expected %s, got %s\n", "foobar", username)
2828
}
2929

30-
if password != "foobarbaz" {
31-
t.Fatalf("expected %s, got %s\n", "foobarbaz", password)
30+
if secret != "foobarbaz" {
31+
t.Fatalf("expected %s, got %s\n", "foobarbaz", secret)
3232
}
3333

3434
if err := helper.Delete(creds.ServerURL); err != nil {

secretservice/secretservice_linux.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ const SecretSchema *docker_get_schema(void)
1515
return &docker_schema;
1616
}
1717

18-
GError *add(char *server, char *username, char *password) {
18+
GError *add(char *server, char *username, char *secret) {
1919
GError *err = NULL;
2020

2121
secret_password_store_sync (DOCKER_SCHEMA, SECRET_COLLECTION_DEFAULT,
22-
server, password, NULL, &err,
22+
server, secret, NULL, &err,
2323
"server", server,
2424
"username", username,
2525
"docker_cli", "1",
@@ -54,13 +54,13 @@ char *get_username(SecretItem *item) {
5454
return NULL;
5555
}
5656

57-
GError *get(char *server, char **username, char **password) {
57+
GError *get(char *server, char **username, char **secret) {
5858
GError *err = NULL;
5959
GHashTable *attributes;
6060
SecretService *service;
6161
GList *items, *l;
6262
SecretSearchFlags flags = SECRET_SEARCH_LOAD_SECRETS | SECRET_SEARCH_ALL | SECRET_SEARCH_UNLOCK;
63-
SecretValue *secret;
63+
SecretValue *secretValue;
6464
gsize length;
6565
gchar *value;
6666

@@ -79,10 +79,10 @@ GError *get(char *server, char **username, char **password) {
7979
continue;
8080
}
8181
g_free(value);
82-
secret = secret_item_get_secret(l->data);
82+
secretValue = secret_item_get_secret(l->data);
8383
if (secret != NULL) {
84-
*password = strdup(secret_value_get(secret, &length));
85-
secret_value_unref(secret);
84+
*secret = strdup(secret_value_get(secretValue, &length));
85+
secret_value_unref(secretValue);
8686
}
8787
*username = get_username(l->data);
8888
}

secretservice/secretservice_linux.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ func (h secretservice) Add(creds *credentials.Credentials) error {
3030
defer C.free(unsafe.Pointer(server))
3131
username := C.CString(creds.Username)
3232
defer C.free(unsafe.Pointer(username))
33-
password := C.CString(creds.Password)
34-
defer C.free(unsafe.Pointer(password))
33+
secret := C.CString(creds.Secret)
34+
defer C.free(unsafe.Pointer(secret))
3535

36-
if err := C.add(server, username, password); err != nil {
36+
if err := C.add(server, username, secret); err != nil {
3737
defer C.g_error_free(err)
3838
errMsg := (*C.char)(unsafe.Pointer(err.message))
3939
return errors.New(C.GoString(errMsg))
@@ -57,26 +57,26 @@ func (h secretservice) Delete(serverURL string) error {
5757
return nil
5858
}
5959

60-
// Get returns the username and password to use for a given registry server URL.
60+
// Get returns the username and secret to use for a given registry server URL.
6161
func (h secretservice) Get(serverURL string) (string, string, error) {
6262
if serverURL == "" {
6363
return "", "", errors.New("missing server url")
6464
}
6565
var username *C.char
6666
defer C.free(unsafe.Pointer(username))
67-
var password *C.char
68-
defer C.free(unsafe.Pointer(password))
67+
var secret *C.char
68+
defer C.free(unsafe.Pointer(secret))
6969
server := C.CString(serverURL)
7070
defer C.free(unsafe.Pointer(server))
7171

72-
err := C.get(server, &username, &password)
72+
err := C.get(server, &username, &secret)
7373
if err != nil {
7474
defer C.g_error_free(err)
7575
errMsg := (*C.char)(unsafe.Pointer(err.message))
7676
return "", "", errors.New(C.GoString(errMsg))
7777
}
7878
user := C.GoString(username)
79-
pass := C.GoString(password)
79+
pass := C.GoString(secret)
8080
if pass == "" {
8181
return "", "", credentials.ErrCredentialsNotFound
8282
}

0 commit comments

Comments
 (0)