forked from simplesurance/baur
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdockerimg.go
45 lines (36 loc) · 981 Bytes
/
dockerimg.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package baur
import (
"fmt"
"github.com/pkg/errors"
"github.com/simplesurance/baur/digest"
)
// RemoteDockerImg represents a docker image in a docker repository
type RemoteDockerImg struct {
repository string
digest string
path string
}
// NewRemoteDockerImg creates a RemoteDockerImg
func NewRemoteDockerImg(repository, digest string) *RemoteDockerImg {
return &RemoteDockerImg{
digest: digest,
repository: repository,
path: fmt.Sprintf("%s@%s", repository, digest),
}
}
// Digest returns the image digest
func (r *RemoteDockerImg) Digest() (digest.Digest, error) {
d, err := digest.FromString(r.digest)
if err != nil {
return digest.Digest{}, errors.Wrap(err, "parsing digest failed")
}
return *d, nil
}
// URI returns <repository>/<path>@:<digest>
func (r *RemoteDockerImg) URI() string {
return r.path
}
// String returns a string representation
func (r *RemoteDockerImg) String() string {
return "docker image: " + r.URI()
}