From feb9de4845ce72e6b53b5ca38c6733be246ecbe0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Mon, 16 May 2016 18:00:52 +0200 Subject: [PATCH] Add GetManifest and GetSignatures to types.Image No change in behavior. These functions are guaranteed-cached versions of the same method in types.ImageSource. Both will be needed for signature policy evaluation, and the symmetry with ImageSource is nice. Also replaces the equivalent RawManifest method, preferring to keep the same naming convention as types.ImageSource. --- cmd/skopeo/inspect.go | 3 +-- docker/docker_image.go | 23 ++++++++++++++++++----- types/types.go | 5 ++++- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/cmd/skopeo/inspect.go b/cmd/skopeo/inspect.go index 0faec960..6b7035fb 100644 --- a/cmd/skopeo/inspect.go +++ b/cmd/skopeo/inspect.go @@ -23,8 +23,7 @@ var inspectCmd = cli.Command{ logrus.Fatal(err) } if c.Bool("raw") { - // TODO(runcom): hardcoded schema 2 version 1 - b, err := img.RawManifest("2-1") + b, err := img.GetManifest() if err != nil { logrus.Fatal(err) } diff --git a/docker/docker_image.go b/docker/docker_image.go index a2068dfb..ef99c1cc 100644 --- a/docker/docker_image.go +++ b/docker/docker_image.go @@ -19,9 +19,10 @@ var ( ) type dockerImage struct { - src *dockerImageSource - digest string - rawManifest []byte + src *dockerImageSource + digest string + rawManifest []byte + cachedSignatures [][]byte // Private cache for GetSignatures; nil if not yet known. } // NewDockerImage returns a new Image interface type after setting up @@ -34,14 +35,26 @@ func NewDockerImage(img, certPath string, tlsVerify bool) (types.Image, error) { return &dockerImage{src: s}, nil } -func (i *dockerImage) RawManifest(version string) ([]byte, error) { - // TODO(runcom): unused version param for now, default to docker v2-1 +// GetManifest is like ImageSource.GetManifest, but the result is cached; it is OK to call this however often you need. +func (i *dockerImage) GetManifest() ([]byte, error) { if err := i.retrieveRawManifest(); err != nil { return nil, err } return i.rawManifest, nil } +// GetSignatures is like ImageSource.GetSignatures, but the result is cached; it is OK to call this however often you need. +func (i *dockerImage) GetSignatures() ([][]byte, error) { + if i.cachedSignatures == nil { + sigs, err := i.src.GetSignatures() + if err != nil { + return nil, err + } + i.cachedSignatures = sigs + } + return i.cachedSignatures, nil +} + func (i *dockerImage) Manifest() (types.ImageManifest, error) { // TODO(runcom): unused version param for now, default to docker v2-1 m, err := i.getSchema1Manifest() diff --git a/types/types.go b/types/types.go index 2acec587..97699743 100644 --- a/types/types.go +++ b/types/types.go @@ -47,9 +47,12 @@ type ImageDestination interface { // Image is a Docker image in a repository. type Image interface { // ref to repository? + // GetManifest is like ImageSource.GetManifest, but the result is cached; it is OK to call this however often you need. + GetManifest() ([]byte, error) + // GetSignatures is like ImageSource.GetSignatures, but the result is cached; it is OK to call this however often you need. + GetSignatures() ([][]byte, error) Layers(layers ...string) error // configure download directory? Call it DownloadLayers? Manifest() (ImageManifest, error) - RawManifest(version string) ([]byte, error) DockerTar() ([]byte, error) // ??? also, configure output directory }