diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-03-31 21:12:49 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-31 21:12:49 +0200 |
commit | 6e8f6cab602b43d05c97c167faa56b3f46f1f73a (patch) | |
tree | c4b4f2ab7e91e4f49d2fe5a9b9d89be455bdd219 /pkg/bindings/images/images.go | |
parent | 56ab9e4cc8a33bb8a791a799753a11c33809dedf (diff) | |
parent | 3bdad6fa2af41be7e783256f3c8a213dc42ca8f6 (diff) | |
download | podman-6e8f6cab602b43d05c97c167faa56b3f46f1f73a.tar.gz podman-6e8f6cab602b43d05c97c167faa56b3f46f1f73a.tar.bz2 podman-6e8f6cab602b43d05c97c167faa56b3f46f1f73a.zip |
Merge pull request #5675 from vrothberg/v2-pull
podmanV2: implement pull
Diffstat (limited to 'pkg/bindings/images/images.go')
-rw-r--r-- | pkg/bindings/images/images.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/pkg/bindings/images/images.go b/pkg/bindings/images/images.go index 5e3af7a60..5f5c4443f 100644 --- a/pkg/bindings/images/images.go +++ b/pkg/bindings/images/images.go @@ -8,6 +8,7 @@ import ( "net/url" "strconv" + "github.com/containers/image/v5/types" "github.com/containers/libpod/pkg/api/handlers" "github.com/containers/libpod/pkg/bindings" "github.com/containers/libpod/pkg/domain/entities" @@ -229,3 +230,41 @@ func Import(ctx context.Context, changes []string, message, reference, u *string } return id.ID, response.Process(&id) } + +// Pull is the binding for libpod's v2 endpoints for pulling images. Note that +// `rawImage` must be a reference to a registry (i.e., of docker transport or be +// normalized to one). Other transports are rejected as they do not make sense +// in a remote context. +func Pull(ctx context.Context, rawImage string, options entities.ImagePullOptions) ([]string, error) { + conn, err := bindings.GetClient(ctx) + if err != nil { + return nil, err + } + params := url.Values{} + params.Set("reference", rawImage) + params.Set("credentials", options.Credentials) + params.Set("overrideArch", options.OverrideArch) + params.Set("overrideOS", options.OverrideOS) + if options.TLSVerify != types.OptionalBoolUndefined { + val := bool(options.TLSVerify == types.OptionalBoolTrue) + params.Set("tlsVerify", strconv.FormatBool(val)) + } + params.Set("allTags", strconv.FormatBool(options.AllTags)) + + response, err := conn.DoRequest(nil, http.MethodPost, "/images/pull", params) + if err != nil { + return nil, err + } + + reports := []handlers.LibpodImagesPullReport{} + if err := response.Process(&reports); err != nil { + return nil, err + } + + pulledImages := []string{} + for _, r := range reports { + pulledImages = append(pulledImages, r.ID) + } + + return pulledImages, nil +} |