diff --git a/README.md b/README.md index 25feef4..3b366a6 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,8 @@ The `docker-credential-env` binary must be installed to `$PATH`, configured via } ``` +By default, attempts to explicitly `docker {login,logout}` will generate an error. To ignore these errors, set the environment variable `IGNORE_DOCKER_LOGIN=1`. + ## Example Usage ### Jenkins diff --git a/env.go b/env.go index 5adde10..e92dec8 100644 --- a/env.go +++ b/env.go @@ -26,6 +26,7 @@ const ( envUsernameSuffix = "USR" envPasswordSuffix = "PSW" envSeparator = "_" + envIgnoreLogin = "IGNORE_DOCKER_LOGIN" ) type NotSupportedError struct{} @@ -39,12 +40,22 @@ type Env struct{} // Add implements the set verb func (*Env) Add(*docker_credentials.Credentials) error { - return fmt.Errorf("add: %w", &NotSupportedError{}) + switch { + case os.Getenv(envIgnoreLogin) != "": + return nil + default: + return fmt.Errorf("add: %w", &NotSupportedError{}) + } } // Delete implements the erase verb func (*Env) Delete(string) error { - return fmt.Errorf("delete: %w", &NotSupportedError{}) + switch { + case os.Getenv(envIgnoreLogin) != "": + return nil + default: + return fmt.Errorf("delete: %w", &NotSupportedError{}) + } } // List implements the list verb diff --git a/env_test.go b/env_test.go index d2d479b..5338fb7 100644 --- a/env_test.go +++ b/env_test.go @@ -213,17 +213,33 @@ func TestEnvNotSupportedMethods(t *testing.T) { } }) + t.Run("Add is ignored with IGNORE_DOCKER_LOGIN", func(t *testing.T) { + t.Setenv(envIgnoreLogin, "1") + actualErr := e.Add(nil) + if actualErr != nil { + t.Errorf("Add() actual = (%v), expected (%v)", actualErr, nil) + } + }) + t.Run("Delete is not supported", func(t *testing.T) { actualErr := e.Delete("") if !errors.Is(actualErr, &NotSupportedError{}) { - t.Errorf("Add() actual = (%v), expected (%v)", actualErr, &NotSupportedError{}) + t.Errorf("Delete() actual = (%v), expected (%v)", actualErr, &NotSupportedError{}) + } + }) + + t.Run("Delete is ignored with IGNORE_DOCKER_LOGIN", func(t *testing.T) { + t.Setenv(envIgnoreLogin, "1") + actualErr := e.Delete("") + if actualErr != nil { + t.Errorf("Delete() actual = (%v), expected (%v)", actualErr, nil) } }) t.Run("List is not supported", func(t *testing.T) { _, actualErr := e.List() if !errors.Is(actualErr, &NotSupportedError{}) { - t.Errorf("Add() actual = (%v), expected (%v)", actualErr, &NotSupportedError{}) + t.Errorf("List() actual = (%v), expected (%v)", actualErr, &NotSupportedError{}) } }) }