This adds an internal fork of [github.com/docker/docker/registry], taken
at commit [moby@f651a5d]. Git history was not preserved in this fork,
but can be found using the URLs provided.
This fork was created to remove the dependency on the "Moby" codebase,
and because the CLI only needs a subset of its features. The original
package was written specifically for use in the daemon code, and includes
functionality that cannot be used in the CLI.
[github.com/docker/docker/registry]: https://pkg.go.dev/github.com/docker/docker@v28.3.2+incompatible/registry
[moby@49306c6]: 49306c607b/registry
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
68 lines
1.3 KiB
Go
68 lines
1.3 KiB
Go
package registry
|
|
|
|
import (
|
|
"net/url"
|
|
|
|
"github.com/docker/distribution/registry/api/errcode"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
func translateV2AuthError(err error) error {
|
|
var e *url.Error
|
|
if errors.As(err, &e) {
|
|
var e2 errcode.Error
|
|
if errors.As(e, &e2) && errors.Is(e2.Code, errcode.ErrorCodeUnauthorized) {
|
|
return unauthorizedErr{err}
|
|
}
|
|
}
|
|
return err
|
|
}
|
|
|
|
func invalidParam(err error) error {
|
|
return invalidParameterErr{err}
|
|
}
|
|
|
|
func invalidParamf(format string, args ...interface{}) error {
|
|
return invalidParameterErr{errors.Errorf(format, args...)}
|
|
}
|
|
|
|
func invalidParamWrapf(err error, format string, args ...interface{}) error {
|
|
return invalidParameterErr{errors.Wrapf(err, format, args...)}
|
|
}
|
|
|
|
type unauthorizedErr struct{ error }
|
|
|
|
func (unauthorizedErr) Unauthorized() {}
|
|
|
|
func (e unauthorizedErr) Cause() error {
|
|
return e.error
|
|
}
|
|
|
|
func (e unauthorizedErr) Unwrap() error {
|
|
return e.error
|
|
}
|
|
|
|
type invalidParameterErr struct{ error }
|
|
|
|
func (invalidParameterErr) InvalidParameter() {}
|
|
|
|
func (e invalidParameterErr) Unwrap() error {
|
|
return e.error
|
|
}
|
|
|
|
type systemErr struct{ error }
|
|
|
|
func (systemErr) System() {}
|
|
|
|
func (e systemErr) Unwrap() error {
|
|
return e.error
|
|
}
|
|
|
|
type errUnknown struct{ error }
|
|
|
|
func (errUnknown) Unknown() {}
|
|
|
|
func (e errUnknown) Unwrap() error {
|
|
return e.error
|
|
}
|