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)
}
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)
}

View File

@ -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()

View File

@ -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
}