1
0
mirror of https://github.com/docker/docker-credential-helpers.git synced 2026-06-13 16:01:28 +05:30

Full implementation for OSX ready

Signed-off-by: avaid96 <avaid1996@gmail.com>
This commit is contained in:
avaid96
2016-07-11 10:50:44 -07:00
parent 5128fa1bad
commit 5a8fb214ed
7 changed files with 170 additions and 3 deletions
+28
View File
@@ -17,6 +17,11 @@ type Credentials struct {
Secret string
}
type KeyData struct{
Path string
Username string
}
// Serve initializes the credentials helper and parses the action argument.
// This function is designed to be called from a command line interface.
// It uses os.Args[1] as the key for the action.
@@ -127,3 +132,26 @@ func Erase(helper Helper, reader io.Reader) error {
return helper.Delete(serverURL)
}
//List returns all the serverURLs of keys in
//the OS store as a list of strings
func List(helper Helper, writer io.Writer) error {
x, y, err := helper.List()
if err != nil {
return err
}
keyDataList := []KeyData{}
for index, _ := range(x) {
keyDataObj := KeyData{
Path:x[index],
Username:y[index],
}
keyDataList = append([]KeyData{keyDataObj}, keyDataList...)
}
buffer := new(bytes.Buffer)
if err := json.NewEncoder(buffer).Encode(keyDataList); err != nil {
return err
}
fmt.Fprint(writer, buffer.String())
return nil
}
+18
View File
@@ -36,6 +36,11 @@ func (m *memoryStore) Get(serverURL string) (string, string, error) {
return c.Username, c.Secret, nil
}
func (m *memoryStore) List() ([]string, []string, error) {
//Simply a placeholder to let memoryStore be a valid implementation of Helper interface
return nil, nil, nil
}
func TestStore(t *testing.T) {
serverURL := "https://index.docker.io/v1/"
creds := &Credentials{
@@ -138,3 +143,16 @@ func TestErase(t *testing.T) {
t.Fatal("expected error getting missing creds, got empty")
}
}
func TestList(t *testing.T) {
//This tests that there is proper input an output into the byte stream
//Individual stores are very OS specific and have been tested in osxkeychain and secretservice respectively
out := new(bytes.Buffer)
h := newMemoryStore()
if err := List(h, out); err != nil {
t.Fatal(err)
}
if out.Len() == 0 {
t.Fatalf("expected output in the writer, got %d", 0)
}
}
+3
View File
@@ -9,4 +9,7 @@ type Helper interface {
// Get retrieves credentials from the store.
// It returns username and secret as strings.
Get(serverURL string) (string, string, error)
// List returns all the serverURLs of keys in
// the OS store as a list of strings
List() ([]string, []string, error)
}