Skip to content

Commit

Permalink
implement digest
Browse files Browse the repository at this point in the history
  • Loading branch information
Aceralon committed Dec 20, 2021
1 parent 3fb54b0 commit 000d428
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions engine/virt/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"io"
"strings"

Expand Down Expand Up @@ -129,13 +130,34 @@ func (v *Virt) ImageBuildCachePrune(ctx context.Context, all bool) (reclaimed ui
}

// ImageLocalDigests shows local images' digests.
func (v *Virt) ImageLocalDigests(ctx context.Context, image string) (digests []string, err error) {
log.Warnf(ctx, "ImageLocalDigests does not implement")
return
// If local image file not exists return error
// If exists return digests
// Same for remote digest
func (v *Virt) ImageLocalDigests(ctx context.Context, image string) ([]string, error) {
// If not exists return error
// If exists return digests
_, imgName, err := splitUserImage(image)
if err != nil {
return nil, err
}

return v.client.DigestImage(ctx, imgName, true)
}

// ImageRemoteDigest shows remote one's digest.
func (v *Virt) ImageRemoteDigest(ctx context.Context, image string) (digest string, err error) {
log.Warnf(ctx, "ImageRemoteDigest does not implement")
return
func (v *Virt) ImageRemoteDigest(ctx context.Context, image string) (string, error) {
_, imgName, err := splitUserImage(image)
if err != nil {
return "", err
}

digests, err := v.client.DigestImage(ctx, imgName, true)
switch {
case err != nil:
return "", err
case len(digests) < 1:
return "", errors.New("got no digest")
default:
return digests[0], nil
}
}

0 comments on commit 000d428

Please sign in to comment.