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.
This commit is contained in:
Miloslav Trmač 2016-05-16 18:00:52 +02:00
parent a39474c817
commit feb9de4845
3 changed files with 23 additions and 8 deletions

View File

@ -23,8 +23,7 @@ var inspectCmd = cli.Command{
logrus.Fatal(err) logrus.Fatal(err)
} }
if c.Bool("raw") { if c.Bool("raw") {
// TODO(runcom): hardcoded schema 2 version 1 b, err := img.GetManifest()
b, err := img.RawManifest("2-1")
if err != nil { if err != nil {
logrus.Fatal(err) logrus.Fatal(err)
} }

View File

@ -22,6 +22,7 @@ type dockerImage struct {
src *dockerImageSource src *dockerImageSource
digest string digest string
rawManifest []byte rawManifest []byte
cachedSignatures [][]byte // Private cache for GetSignatures; nil if not yet known.
} }
// NewDockerImage returns a new Image interface type after setting up // 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 return &dockerImage{src: s}, nil
} }
func (i *dockerImage) RawManifest(version string) ([]byte, error) { // GetManifest is like ImageSource.GetManifest, but the result is cached; it is OK to call this however often you need.
// TODO(runcom): unused version param for now, default to docker v2-1 func (i *dockerImage) GetManifest() ([]byte, error) {
if err := i.retrieveRawManifest(); err != nil { if err := i.retrieveRawManifest(); err != nil {
return nil, err return nil, err
} }
return i.rawManifest, nil 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) { func (i *dockerImage) Manifest() (types.ImageManifest, error) {
// TODO(runcom): unused version param for now, default to docker v2-1 // TODO(runcom): unused version param for now, default to docker v2-1
m, err := i.getSchema1Manifest() m, err := i.getSchema1Manifest()

View File

@ -47,9 +47,12 @@ type ImageDestination interface {
// Image is a Docker image in a repository. // Image is a Docker image in a repository.
type Image interface { type Image interface {
// ref to repository? // 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? Layers(layers ...string) error // configure download directory? Call it DownloadLayers?
Manifest() (ImageManifest, error) Manifest() (ImageManifest, error)
RawManifest(version string) ([]byte, error)
DockerTar() ([]byte, error) // ??? also, configure output directory DockerTar() ([]byte, error) // ??? also, configure output directory
} }