Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: error type for not finding basic auth creds and export config path #674

Merged
merged 15 commits into from
Jan 17, 2024
1 change: 1 addition & 0 deletions errdef/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ var (
ErrSizeExceedsLimit = errors.New("size exceeds limit")
ErrUnsupported = errors.New("unsupported")
ErrUnsupportedVersion = errors.New("unsupported version")
ErrBasicCredNotFound = errors.New("basic credential not found")
qweeah marked this conversation as resolved.
Show resolved Hide resolved
)
5 changes: 3 additions & 2 deletions registry/remote/auth/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"net/url"
"strings"

"oras.land/oras-go/v2/errdef"
"oras.land/oras-go/v2/registry/remote/internal/errutil"
"oras.land/oras-go/v2/registry/remote/retry"
)
Expand Down Expand Up @@ -215,7 +216,7 @@
return c.fetchBasicAuth(ctx, host)
})
if err != nil {
return nil, fmt.Errorf("%s %q: %w", resp.Request.Method, resp.Request.URL, err)
return nil, err

Check warning on line 219 in registry/remote/auth/client.go

View check run for this annotation

Codecov / codecov/patch

registry/remote/auth/client.go#L219

Added line #L219 was not covered by tests
}

req = originalReq.Clone(ctx)
Expand Down Expand Up @@ -280,7 +281,7 @@
return "", fmt.Errorf("failed to resolve credential: %w", err)
}
if cred == EmptyCredential {
return "", errors.New("credential required for basic auth")
return "", errdef.ErrBasicCredNotFound

Check warning on line 284 in registry/remote/auth/client.go

View check run for this annotation

Codecov / codecov/patch

registry/remote/auth/client.go#L284

Added line #L284 was not covered by tests
}
if cred.Username == "" || cred.Password == "" {
return "", errors.New("missing username or password for basic auth")
Expand Down
6 changes: 3 additions & 3 deletions registry/remote/credentials/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func NewStore(configPath string, opts StoreOptions) (*DynamicStore, error) {
// - https://docs.docker.com/engine/reference/commandline/cli/#configuration-files
// - https://docs.docker.com/engine/reference/commandline/cli/#change-the-docker-directory
func NewStoreFromDocker(opt StoreOptions) (*DynamicStore, error) {
configPath, err := getDockerConfigPath()
configPath, err := GetDockerConfigPath()
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -193,8 +193,8 @@ func (ds *DynamicStore) getStore(serverAddress string) Store {
return fs
}

// getDockerConfigPath returns the path to the default docker config file.
func getDockerConfigPath() (string, error) {
// GetDockerConfigPath returns the path to the default docker config file.
func GetDockerConfigPath() (string, error) {
qweeah marked this conversation as resolved.
Show resolved Hide resolved
// first try the environment variable
configDir := os.Getenv(dockerConfigDirEnv)
if configDir == "" {
Expand Down
4 changes: 2 additions & 2 deletions registry/remote/credentials/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ func Test_getDockerConfigPath_env(t *testing.T) {
}
t.Setenv("DOCKER_CONFIG", dir)

got, err := getDockerConfigPath()
got, err := GetDockerConfigPath()
if err != nil {
t.Fatal("getDockerConfigPath() error =", err)
}
Expand All @@ -890,7 +890,7 @@ func Test_getDockerConfigPath_env(t *testing.T) {
func Test_getDockerConfigPath_homeDir(t *testing.T) {
t.Setenv("DOCKER_CONFIG", "")

got, err := getDockerConfigPath()
got, err := GetDockerConfigPath()
if err != nil {
t.Fatal("getDockerConfigPath() error =", err)
}
Expand Down
Loading