This repository has been archived by the owner on Oct 27, 2022. It is now read-only.
forked from regclient/regclient
-
Notifications
You must be signed in to change notification settings - Fork 1
/
manifest.go
79 lines (70 loc) · 2.21 KB
/
manifest.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package regclient
import (
"context"
"github.com/regclient/regclient/scheme"
"github.com/regclient/regclient/types"
"github.com/regclient/regclient/types/manifest"
"github.com/regclient/regclient/types/ref"
)
type manifestOpt struct {
d types.Descriptor
}
// ManifestOpts define options for the Manifest* commands
type ManifestOpts func(*manifestOpt)
// ManifestWithDesc includes the descriptor for ManifestGet.
// This is used to automatically extract a Data field if available.
func ManifestWithDesc(d types.Descriptor) ManifestOpts {
return func(opts *manifestOpt) {
opts.d = d
}
}
// ManifestDelete removes a manifest, including all tags pointing to that registry
// The reference must include the digest to delete (see TagDelete for deleting a tag)
// All tags pointing to the manifest will be deleted
func (rc *RegClient) ManifestDelete(ctx context.Context, r ref.Ref) error {
schemeAPI, err := rc.schemeGet(r.Scheme)
if err != nil {
return err
}
return schemeAPI.ManifestDelete(ctx, r)
}
// ManifestGet retrieves a manifest
func (rc *RegClient) ManifestGet(ctx context.Context, r ref.Ref, opts ...ManifestOpts) (manifest.Manifest, error) {
opt := manifestOpt{}
for _, fn := range opts {
fn(&opt)
}
if opt.d.Digest != "" {
r.Digest = opt.d.Digest.String()
data, err := opt.d.GetData()
if err == nil {
return manifest.New(
manifest.WithDesc(opt.d),
manifest.WithRaw(data),
manifest.WithRef(r),
)
}
}
schemeAPI, err := rc.schemeGet(r.Scheme)
if err != nil {
return nil, err
}
return schemeAPI.ManifestGet(ctx, r)
}
// ManifestHead queries for the existence of a manifest and returns metadata (digest, media-type, size)
func (rc *RegClient) ManifestHead(ctx context.Context, r ref.Ref) (manifest.Manifest, error) {
schemeAPI, err := rc.schemeGet(r.Scheme)
if err != nil {
return nil, err
}
return schemeAPI.ManifestHead(ctx, r)
}
// ManifestPut pushes a manifest
// Any descriptors referenced by the manifest typically need to be pushed first
func (rc *RegClient) ManifestPut(ctx context.Context, r ref.Ref, m manifest.Manifest, opts ...scheme.ManifestOpts) error {
schemeAPI, err := rc.schemeGet(r.Scheme)
if err != nil {
return err
}
return schemeAPI.ManifestPut(ctx, r, m, opts...)
}