Add CanonicalDockerReference to ImageDestination

This is necessary to resolve the canonical form of a reference for
signing it.
This commit is contained in:
Miloslav Trmač 2016-05-02 20:59:20 +02:00
parent 2e48975b8b
commit da24e319af
4 changed files with 14 additions and 0 deletions

View File

@ -36,6 +36,10 @@ func NewDirImageDestination(dir string) types.ImageDestination {
return &dirImageDestination{dir}
}
func (d *dirImageDestination) CanonicalDockerReference() (string, error) {
return "", fmt.Errorf("Can not determine canonical Docker reference for a local directory")
}
func (d *dirImageDestination) PutManifest(manifest []byte) error {
return ioutil.WriteFile(manifestPath(d.dir), manifest, 0644)
}

View File

@ -752,6 +752,10 @@ func NewDockerImageDestination(img, certPath string, tlsVerify bool) (types.Imag
}, nil
}
func (d *dockerImageDestination) CanonicalDockerReference() (string, error) {
return fmt.Sprintf("%s:%s", d.ref.Name(), d.tag), nil
}
func (d *dockerImageDestination) PutManifest(manifest []byte) error {
// FIXME: This only allows upload by digest, not creating a tag. See the
// corresponding comment in NewOpenshiftImageDestination.

View File

@ -268,6 +268,10 @@ func NewOpenshiftImageDestination(imageName, certPath string, tlsVerify bool) (t
}, nil
}
func (d *openshiftImageDestination) CanonicalDockerReference() (string, error) {
return fmt.Sprintf("%s/%s/%s:%s", d.client.baseURL.Host, d.client.namespace, d.client.stream, d.client.tag), nil
}
func (d *openshiftImageDestination) PutManifest(manifest []byte) error {
// Note: This does absolutely no kind/version checking or conversions.
manifestDigest, err := dockerutils.ManifestDigest(manifest)

View File

@ -37,6 +37,8 @@ type ImageSource interface {
// ImageDestination is a service, possibly remote (= slow), to store components of a single image.
type ImageDestination interface {
// CanonicalDockerReference returns the full, unambiguous, Docker reference for this image (even if the user referred to the image using some shorthand notation).
CanonicalDockerReference() (string, error)
PutManifest([]byte) error
PutLayer(digest string, stream io.Reader) error
PutSignatures(signatures [][]byte) error