Skip to content

Commit a43792c

Browse files
committed
update ociregistry dependency
Signed-off-by: Roger Peppe <[email protected]> Change-Id: I5ed8026f4faa0b4a3cc8d9fcb4b3694bf4ef99bc Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1170079 Reviewed-by: Daniel Martí <[email protected]> Unity-Result: CUE porcuepine <[email protected]> TryBot-Result: CUEcueckoo <[email protected]>
1 parent b664f0c commit a43792c

File tree

8 files changed

+41
-26
lines changed

8 files changed

+41
-26
lines changed

cue/load/module_test.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@ func TestModuleFetch(t *testing.T) {
2222
t.Fatal(err)
2323
}
2424
defer r.Close()
25-
t.LoadConfig.Registry = ociclient.New(r.URL(), nil)
25+
reg, err := ociclient.New(r.Host(), &ociclient.Options{
26+
Insecure: true,
27+
})
28+
if err != nil {
29+
t.Fatal(err)
30+
}
31+
t.LoadConfig.Registry = reg
2632
ctx := cuecontext.New()
2733
insts := t.RawInstances()
2834
if len(insts) != 1 {

cue/load/registry.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type registryClient struct {
2929
// in the registry is immutable, so if it's in the cache, a module
3030
// will not be downloaded again.
3131
func newRegistryClient(registry ociregistry.Interface, cacheDir string) (*registryClient, error) {
32-
client, err := modregistry.NewClient(registry, "cue/") // TODO configurable prefix
32+
client, err := modregistry.NewClient(registry)
3333
if err != nil {
3434
return nil, err
3535
}

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module cuelang.org/go
33
go 1.20
44

55
require (
6-
cuelabs.dev/go/oci/ociregistry v0.0.0-20230802165206-d5c26bbb71e9
6+
cuelabs.dev/go/oci/ociregistry v0.0.0-20230928144906-bef4f4e03886
77
github.com/cockroachdb/apd/v3 v3.2.1
88
github.com/emicklei/proto v1.10.0
99
github.com/go-quicktest/qt v1.101.0

go.sum

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
cuelabs.dev/go/oci/ociregistry v0.0.0-20230802165206-d5c26bbb71e9 h1:csvQm6RHCrV0KcjWiI5ZXCbmbqO9xsfVO6+lEm8Mfxc=
2-
cuelabs.dev/go/oci/ociregistry v0.0.0-20230802165206-d5c26bbb71e9/go.mod h1:TwQm/ek5h72Rl2KOtWOW3EsC+7mKJ05cbGojNxvRwAo=
1+
cuelabs.dev/go/oci/ociregistry v0.0.0-20230928144906-bef4f4e03886 h1:v4I5Vu5DMkQXGaKAYun/2eFWQZ3Yg8IB3CSxyBee5ww=
2+
cuelabs.dev/go/oci/ociregistry v0.0.0-20230928144906-bef4f4e03886/go.mod h1:oqwWmDcccWVB2yC2eCHFNrQR44/AVB7gHOwtBsWMo0g=
33
github.com/cockroachdb/apd/v3 v3.2.1 h1:U+8j7t0axsIgvQUqthuNm82HIrYXodOV2iWLWtEaIwg=
44
github.com/cockroachdb/apd/v3 v3.2.1/go.mod h1:klXJcjp+FffLTHlhIG69tezTDvdP065naDsHzKhYSqc=
55
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
@@ -21,7 +21,9 @@ github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3x
2121
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
2222
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
2323
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
24+
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
2425
github.com/lib/pq v1.10.7 h1:p7ZhMD+KsSRozJr34udlUrhboJwWAgCg34+/ZZNvZZw=
26+
github.com/lib/pq v1.10.7/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
2527
github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0=
2628
github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0=
2729
github.com/mpvl/unique v0.0.0-20150818121801-cbe035fff7de h1:D5x39vF5KCwKQaw+OC9ZPiLVHXz3UFw2+psEX+gYcto=
@@ -48,6 +50,7 @@ golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
4850
golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8=
4951
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
5052
golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
53+
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
5154
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
5255
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
5356
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=

internal/mod/modregistry/client.go

+3-10
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ var ErrNotFound = fmt.Errorf("module not found")
4141
// provides a store for CUE modules.
4242
type Client struct {
4343
registry ociregistry.Interface
44-
prefix string
4544
}
4645

4746
const (
@@ -51,16 +50,10 @@ const (
5150
)
5251

5352
// NewClient returns a new client that talks to the registry at the given
54-
// hostname. All repositories created or accessed in the registry
55-
// will have the given prefix.
56-
//
57-
// TODO pass in an ociregistry.Interface instead of a URL,
58-
// thus allowing a locally defined composition of registries
59-
// rather than always assuming everything is behind a single host.
60-
func NewClient(registry ociregistry.Interface, prefix string) (*Client, error) {
53+
// hostname.
54+
func NewClient(registry ociregistry.Interface) (*Client, error) {
6155
return &Client{
6256
registry: registry,
63-
prefix: prefix,
6457
}, nil
6558
}
6659

@@ -100,7 +93,7 @@ func (c *Client) GetModule(ctx context.Context, m module.Version) (*Module, erro
10093

10194
func (c *Client) repoName(modPath string) string {
10295
path, _, _ := module.SplitPathVersion(modPath)
103-
return c.prefix + path
96+
return path
10497
}
10598

10699
// ModuleVersions returns all the versions for the module with the given path.

internal/mod/modregistry/client_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import (
3434
)
3535

3636
func newTestClient(t *testing.T) *Client {
37-
c, err := NewClient(ocimem.New(), "")
37+
c, err := NewClient(ocimem.New())
3838
qt.Assert(t, qt.IsNil(err))
3939
return c
4040
}

internal/registrytest/registry.go

+18-8
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import (
88
"io"
99
"io/fs"
1010
"net/http/httptest"
11+
"net/url"
1112
"strings"
1213

13-
"cuelabs.dev/go/oci/ociregistry/ociclient"
1414
"cuelabs.dev/go/oci/ociregistry/ocimem"
1515
"cuelabs.dev/go/oci/ociregistry/ociserver"
1616
"golang.org/x/tools/txtar"
@@ -32,8 +32,8 @@ import (
3232
//
3333
// The Registry should be closed after use.
3434
func New(fsys fs.FS) (*Registry, error) {
35-
srv := httptest.NewServer(ociserver.New(ocimem.New(), nil))
36-
client, err := modregistry.NewClient(ociclient.New(srv.URL, nil), "cue/")
35+
r := ocimem.New()
36+
client, err := modregistry.NewClient(r)
3737
if err != nil {
3838
return nil, fmt.Errorf("cannot make client: %v", err)
3939
}
@@ -44,8 +44,14 @@ func New(fsys fs.FS) (*Registry, error) {
4444
if err := pushContent(client, mods); err != nil {
4545
return nil, fmt.Errorf("cannot push modules: %v", err)
4646
}
47+
srv := httptest.NewServer(ociserver.New(r, nil))
48+
u, err := url.Parse(srv.URL)
49+
if err != nil {
50+
return nil, err
51+
}
4752
return &Registry{
48-
srv: srv,
53+
srv: srv,
54+
host: u.Host,
4955
}, nil
5056
}
5157

@@ -87,16 +93,20 @@ func visitDepthFirst(mods map[module.Version]*moduleContent, v module.Version, f
8793
}
8894

8995
type Registry struct {
90-
srv *httptest.Server
96+
srv *httptest.Server
97+
host string
9198
}
9299

93100
func (r *Registry) Close() {
94101
r.srv.Close()
95102
}
96103

97-
// URL returns the base URL for the registry.
98-
func (r *Registry) URL() string {
99-
return r.srv.URL
104+
// Host returns the hostname for the registry server;
105+
// for example localhost:13455.
106+
//
107+
// The connection can be assumed to be insecure.
108+
func (r *Registry) Host() string {
109+
return r.host
100110
}
101111

102112
type handler struct {

internal/registrytest/registry_test.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,17 @@ func TestRegistry(t *testing.T) {
3939
t.Fatal(err)
4040
}
4141
defer r.Close()
42-
runTest(t, ociclient.New(r.URL(), nil), string(ar.Comment), ar)
42+
client, err := ociclient.New(r.Host(), &ociclient.Options{
43+
Insecure: true,
44+
})
45+
runTest(t, client, string(ar.Comment), ar)
4346
})
4447
}
4548
}
4649

4750
func runTest(t *testing.T, registry ociregistry.Interface, script string, ar *txtar.Archive) {
4851
ctx := context.Background()
49-
client, err := modregistry.NewClient(registry, "cue/")
52+
client, err := modregistry.NewClient(registry)
5053
if err != nil {
5154
t.Fatal(err)
5255
}

0 commit comments

Comments
 (0)