mirror of
https://github.com/containers/podman.git
synced 2025-06-26 04:46:57 +08:00
Merge pull request #13274 from jwhonce/wip/manifest_4_main
Fix manifest 4.0 endpoints
This commit is contained in:
@ -401,7 +401,7 @@ func ManifestModify(w http.ResponseWriter, r *http.Request) {
|
||||
case len(report.Errors) > 0 && len(report.Images) > 0:
|
||||
statusCode = http.StatusConflict
|
||||
case len(report.Errors) > 0:
|
||||
statusCode = http.StatusInternalServerError
|
||||
statusCode = http.StatusBadRequest
|
||||
}
|
||||
utils.WriteResponse(w, statusCode, report)
|
||||
}
|
||||
|
@ -2,10 +2,9 @@ package manifests
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@ -14,8 +13,11 @@ import (
|
||||
"github.com/containers/podman/v4/pkg/api/handlers"
|
||||
"github.com/containers/podman/v4/pkg/bindings"
|
||||
"github.com/containers/podman/v4/pkg/bindings/images"
|
||||
"github.com/containers/podman/v4/pkg/domain/entities"
|
||||
"github.com/containers/podman/v4/pkg/errorhandling"
|
||||
"github.com/containers/podman/v4/version"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// Create creates a manifest for the given name. Optional images to be associated with
|
||||
@ -135,30 +137,8 @@ func Add(ctx context.Context, name string, options *AddOptions) (string, error)
|
||||
// Remove deletes a manifest entry from a manifest list. Both name and the digest to be
|
||||
// removed are mandatory inputs. The ID of the new manifest list is returned as a string.
|
||||
func Remove(ctx context.Context, name, digest string, _ *RemoveOptions) (string, error) {
|
||||
if bindings.ServiceVersion(ctx).GTE(semver.MustParse("4.0.0")) {
|
||||
optionsv4 := new(ModifyOptions).WithOperation("remove")
|
||||
return Modify(ctx, name, []string{digest}, optionsv4)
|
||||
}
|
||||
|
||||
// API Version < 4.0.0
|
||||
conn, err := bindings.GetClient(ctx)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
headers := http.Header{}
|
||||
headers.Add("API-Version", "3.4.0")
|
||||
|
||||
params := url.Values{}
|
||||
params.Set("digest", digest)
|
||||
response, err := conn.DoRequest(ctx, nil, http.MethodDelete, "/manifests/%s", params, headers, name)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer response.Body.Close()
|
||||
|
||||
var idr handlers.IDResponse
|
||||
return idr.ID, response.Process(&idr)
|
||||
optionsv4 := new(ModifyOptions).WithOperation("remove")
|
||||
return Modify(ctx, name, []string{digest}, optionsv4)
|
||||
}
|
||||
|
||||
// Push takes a manifest list and pushes to a destination. If the destination is not specified,
|
||||
@ -229,8 +209,36 @@ func Modify(ctx context.Context, name string, images []string, options *ModifyOp
|
||||
}
|
||||
defer response.Body.Close()
|
||||
|
||||
var idr handlers.IDResponse
|
||||
return idr.ID, response.Process(&idr)
|
||||
data, err := ioutil.ReadAll(response.Body)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "unable to process API response")
|
||||
}
|
||||
|
||||
if response.IsSuccess() || response.IsRedirection() {
|
||||
var report entities.ManifestModifyReport
|
||||
if err = jsoniter.Unmarshal(data, &report); err != nil {
|
||||
return "", errors.Wrap(err, "unable to decode API response")
|
||||
}
|
||||
|
||||
err = errorhandling.JoinErrors(report.Errors)
|
||||
if err != nil {
|
||||
errModel := errorhandling.ErrorModel{
|
||||
Because: (errors.Cause(err)).Error(),
|
||||
Message: err.Error(),
|
||||
ResponseCode: response.StatusCode,
|
||||
}
|
||||
return report.ID, &errModel
|
||||
}
|
||||
return report.ID, nil
|
||||
}
|
||||
|
||||
errModel := errorhandling.ErrorModel{
|
||||
ResponseCode: response.StatusCode,
|
||||
}
|
||||
if err = jsoniter.Unmarshal(data, &errModel); err != nil {
|
||||
return "", errors.Wrap(err, "unable to decode API response")
|
||||
}
|
||||
return "", &errModel
|
||||
}
|
||||
|
||||
// Annotate modifies the given manifest list using options and the optional list of images
|
||||
|
Reference in New Issue
Block a user