mirror of
https://github.com/docker/docker-credential-helpers.git
synced 2026-06-13 16:01:28 +05:30
implementation on client side as well, complete with tests
Signed-off-by: avaid96 <avaid1996@gmail.com>
This commit is contained in:
+13
-2
@@ -55,11 +55,10 @@ func Get(program ProgramFunc, serverURL string) (*credentials.Credentials, error
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// Erase executes a program to remove the server credentails from the native store.
|
||||
// Erase executes a program to remove the server credentials from the native store.
|
||||
func Erase(program ProgramFunc, serverURL string) error {
|
||||
cmd := program("erase")
|
||||
cmd.Input(strings.NewReader(serverURL))
|
||||
|
||||
out, err := cmd.Output()
|
||||
if err != nil {
|
||||
t := strings.TrimSpace(string(out))
|
||||
@@ -68,3 +67,15 @@ func Erase(program ProgramFunc, serverURL string) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// List executes a program to remove the server credentials from the native store.
|
||||
func List(program ProgramFunc) error {
|
||||
cmd := program("list")
|
||||
cmd.Input(strings.NewReader("garbage"))
|
||||
out, err := cmd.Output()
|
||||
if err != nil {
|
||||
t := strings.TrimSpace(string(out))
|
||||
return fmt.Errorf("error listing credentials - err: %v, out: `%s`", err, t)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -70,6 +70,9 @@ func (m *mockProgram) Output() ([]byte, error) {
|
||||
default:
|
||||
return []byte("error storing credentials"), errProgramExited
|
||||
}
|
||||
case "list":
|
||||
return []byte(`{"Path":"e237574ae22fd53ddb9490dc1f72139946fd5372d42ba54d1eeb3ae5068fd22b","Username":"http://example.com/collections\u003cnotary_key\u003eSnapshot"}`), nil
|
||||
|
||||
}
|
||||
|
||||
return []byte(fmt.Sprintf("unknown argument %q with %q", m.arg, inS)), errProgramExited
|
||||
@@ -190,3 +193,9 @@ func TestErase(t *testing.T) {
|
||||
t.Fatalf("Expected error for server %s, got nil", invalidServerAddress)
|
||||
}
|
||||
}
|
||||
|
||||
func TestList(t *testing.T) {
|
||||
if err := List(mockProgramFn); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ type KeyData struct {
|
||||
func Serve(helper Helper) {
|
||||
var err error
|
||||
if len(os.Args) != 2 {
|
||||
err = fmt.Errorf("Usage: %s <store|get|erase>", os.Args[0])
|
||||
err = fmt.Errorf("Usage: %s <store|get|erase|list>", os.Args[0])
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
@@ -52,6 +52,8 @@ func HandleCommand(helper Helper, key string, in io.Reader, out io.Writer) error
|
||||
return Get(helper, in, out)
|
||||
case "erase":
|
||||
return Erase(helper, in)
|
||||
case "list":
|
||||
return List(helper, out)
|
||||
}
|
||||
return fmt.Errorf("Unknown credential action `%s`", key)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user