Skip to content

Commit 47310ef

Browse files
committed
feat: registry api
1 parent c1a720e commit 47310ef

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.16
55
require (
66
github.com/chaitin/libveinmind v1.1.1
77
github.com/containerd/containerd v1.6.6
8+
github.com/distribution/distribution v2.8.1+incompatible // indirect
89
github.com/docker/cli v20.10.17+incompatible
910
github.com/docker/distribution v2.8.1+incompatible
1011
github.com/docker/docker v20.10.17+incompatible

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,8 @@ github.com/dgrijalva/jwt-go v0.0.0-20170104182250-a601269ab70c/go.mod h1:E3ru+11
397397
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
398398
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
399399
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
400+
github.com/distribution/distribution v2.8.1+incompatible h1:8iXUoOqRPx30bhzIEPUmNIqlmBlWdrieW1bqr6LrX30=
401+
github.com/distribution/distribution v2.8.1+incompatible/go.mod h1:EgLm2NgWtdKgzF9NpMzUKgzmR7AMmb0VQi2B+ZzDRjc=
400402
github.com/dnaeon/go-vcr v1.0.1/go.mod h1:aBB1+wY4s93YsC3HHjMBMrwTj2R9FHDzUr9KyGc8n1E=
401403
github.com/docker/cli v0.0.0-20191017083524-a8ff7f821017/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
402404
github.com/docker/cli v20.10.16+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=

registry/registry.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package registry
2+
3+
import (
4+
"encoding/json"
5+
"github.com/distribution/distribution/manifest/schema2"
6+
"github.com/google/go-containerregistry/pkg/name"
7+
"github.com/google/go-containerregistry/pkg/v1/remote"
8+
)
9+
10+
type Client struct {
11+
}
12+
13+
func NewClient() (*Client, error) {
14+
c := new(Client)
15+
return c, nil
16+
}
17+
18+
func (client *Client) GetRepoTags(repo string, options ...remote.Option) ([]string, error) {
19+
repoR, err := name.NewRepository(repo)
20+
if err != nil {
21+
return nil, err
22+
}
23+
return remote.List(repoR, options...)
24+
}
25+
26+
func (client *Client) GetRepoManifest(repo string, options ...remote.Option) (*schema2.Manifest, error) {
27+
ref, err := name.ParseReference(repo)
28+
if err != nil {
29+
return nil, err
30+
}
31+
32+
desc, err := remote.Get(ref, options...)
33+
if err != nil {
34+
return nil, err
35+
}
36+
37+
manifest := &schema2.Manifest{}
38+
err = json.Unmarshal(desc.Manifest, manifest)
39+
if err != nil {
40+
return nil, err
41+
}
42+
43+
return manifest, nil
44+
}

0 commit comments

Comments
 (0)