mirror of
https://github.com/containers/podman.git
synced 2025-12-05 21:10:35 +08:00
Support loading and saving tarballs with more than one image. Add a new `/libpod/images/export` endpoint to the rest API to allow for exporting/saving multiple images into an archive. Note that a non-release version of containers/image is vendored. A release version must be vendored before cutting a new Podman release. We force the containers/image version via a replace in the go.mod file; this way go won't try to match the versions. Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
61 lines
2.0 KiB
Go
61 lines
2.0 KiB
Go
package docker
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/docker/distribution/registry/client"
|
|
perrors "github.com/pkg/errors"
|
|
)
|
|
|
|
var (
|
|
// ErrV1NotSupported is returned when we're trying to talk to a
|
|
// docker V1 registry.
|
|
ErrV1NotSupported = errors.New("can't talk to a V1 docker registry")
|
|
// ErrTooManyRequests is returned when the status code returned is 429
|
|
ErrTooManyRequests = errors.New("too many requests to registry")
|
|
)
|
|
|
|
// ErrUnauthorizedForCredentials is returned when the status code returned is 401
|
|
type ErrUnauthorizedForCredentials struct { // We only use a struct to allow a type assertion, without limiting the contents of the error otherwise.
|
|
Err error
|
|
}
|
|
|
|
func (e ErrUnauthorizedForCredentials) Error() string {
|
|
return fmt.Sprintf("unable to retrieve auth token: invalid username/password: %s", e.Err.Error())
|
|
}
|
|
|
|
// httpResponseToError translates the https.Response into an error, possibly prefixing it with the supplied context. It returns
|
|
// nil if the response is not considered an error.
|
|
func httpResponseToError(res *http.Response, context string) error {
|
|
switch res.StatusCode {
|
|
case http.StatusOK:
|
|
return nil
|
|
case http.StatusTooManyRequests:
|
|
return ErrTooManyRequests
|
|
case http.StatusUnauthorized:
|
|
err := client.HandleErrorResponse(res)
|
|
return ErrUnauthorizedForCredentials{Err: err}
|
|
default:
|
|
if context != "" {
|
|
context = context + ": "
|
|
}
|
|
return perrors.Errorf("%sinvalid status code from registry %d (%s)", context, res.StatusCode, http.StatusText(res.StatusCode))
|
|
}
|
|
}
|
|
|
|
// registryHTTPResponseToError creates a Go error from an HTTP error response of a docker/distribution
|
|
// registry
|
|
func registryHTTPResponseToError(res *http.Response) error {
|
|
errResponse := client.HandleErrorResponse(res)
|
|
if e, ok := perrors.Cause(errResponse).(*client.UnexpectedHTTPResponseError); ok {
|
|
response := string(e.Response)
|
|
if len(response) > 50 {
|
|
response = response[:50] + "..."
|
|
}
|
|
errResponse = fmt.Errorf("StatusCode: %d, %s", e.StatusCode, response)
|
|
}
|
|
return errResponse
|
|
}
|