mirror of
https://github.com/docker/docker-credential-helpers.git
synced 2026-06-13 16:01:28 +05:30
Implement client.List, change list API
[]string, []string -> map[string]string because the other APIs assume a 1:1 correspondence Signed-off-by: Jake Sanders <jsand@google.com>
This commit is contained in:
@@ -17,11 +17,6 @@ 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.
|
||||
@@ -138,22 +133,9 @@ func Erase(helper Helper, reader io.Reader) error {
|
||||
//List returns all the serverURLs of keys in
|
||||
//the OS store as a list of strings
|
||||
func List(helper Helper, writer io.Writer) error {
|
||||
paths, accts, err := helper.List()
|
||||
accts, err := helper.List()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
keyDataList := []KeyData{}
|
||||
for index := 0; index < len(paths); index++ {
|
||||
keyDataObj := KeyData{
|
||||
Path: paths[index],
|
||||
Username: accts[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
|
||||
return json.NewEncoder(writer).Encode(accts)
|
||||
}
|
||||
|
||||
@@ -36,9 +36,9 @@ func (m *memoryStore) Get(serverURL string) (string, string, error) {
|
||||
return c.Username, c.Secret, nil
|
||||
}
|
||||
|
||||
func (m *memoryStore) List() ([]string, []string, error) {
|
||||
func (m *memoryStore) List() (map[string]string, error) {
|
||||
//Simply a placeholder to let memoryStore be a valid implementation of Helper interface
|
||||
return nil, nil, nil
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func TestStore(t *testing.T) {
|
||||
|
||||
@@ -9,8 +9,6 @@ type Helper interface {
|
||||
// Get retrieves credentials from the store.
|
||||
// It returns username and secret as strings.
|
||||
Get(serverURL string) (string, string, error)
|
||||
// List returns the serverURLs of keys and their
|
||||
// associated usernames from the OS store as a
|
||||
// list of strings
|
||||
List() ([]string, []string, error)
|
||||
// List returns the stored serverURLs and their associated usernames.
|
||||
List() (map[string]string, error)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user