diff --git a/cue/load/module_test.go b/cue/load/module_test.go index b9f3015c024..4e7e812b82a 100644 --- a/cue/load/module_test.go +++ b/cue/load/module_test.go @@ -22,7 +22,13 @@ func TestModuleFetch(t *testing.T) { t.Fatal(err) } defer r.Close() - t.LoadConfig.Registry = ociclient.New(r.URL(), nil) + reg, err := ociclient.New(r.Host(), &ociclient.Options{ + Insecure: true, + }) + if err != nil { + t.Fatal(err) + } + t.LoadConfig.Registry = reg ctx := cuecontext.New() insts := t.RawInstances() if len(insts) != 1 { diff --git a/cue/load/registry.go b/cue/load/registry.go index 40e37fca81d..2c5f29178ca 100644 --- a/cue/load/registry.go +++ b/cue/load/registry.go @@ -29,7 +29,7 @@ type registryClient struct { // in the registry is immutable, so if it's in the cache, a module // will not be downloaded again. func newRegistryClient(registry ociregistry.Interface, cacheDir string) (*registryClient, error) { - client, err := modregistry.NewClient(registry, "cue/") // TODO configurable prefix + client, err := modregistry.NewClient(registry) if err != nil { return nil, err } diff --git a/go.mod b/go.mod index 838defbbd49..bd8e5f6472d 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module cuelang.org/go go 1.20 require ( - cuelabs.dev/go/oci/ociregistry v0.0.0-20230802165206-d5c26bbb71e9 + cuelabs.dev/go/oci/ociregistry v0.0.0-20230928144906-bef4f4e03886 github.com/cockroachdb/apd/v3 v3.2.1 github.com/emicklei/proto v1.10.0 github.com/go-quicktest/qt v1.101.0 diff --git a/go.sum b/go.sum index 7a22c36f442..6825153f662 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -cuelabs.dev/go/oci/ociregistry v0.0.0-20230802165206-d5c26bbb71e9 h1:csvQm6RHCrV0KcjWiI5ZXCbmbqO9xsfVO6+lEm8Mfxc= -cuelabs.dev/go/oci/ociregistry v0.0.0-20230802165206-d5c26bbb71e9/go.mod h1:TwQm/ek5h72Rl2KOtWOW3EsC+7mKJ05cbGojNxvRwAo= +cuelabs.dev/go/oci/ociregistry v0.0.0-20230928144906-bef4f4e03886 h1:v4I5Vu5DMkQXGaKAYun/2eFWQZ3Yg8IB3CSxyBee5ww= +cuelabs.dev/go/oci/ociregistry v0.0.0-20230928144906-bef4f4e03886/go.mod h1:oqwWmDcccWVB2yC2eCHFNrQR44/AVB7gHOwtBsWMo0g= github.com/cockroachdb/apd/v3 v3.2.1 h1:U+8j7t0axsIgvQUqthuNm82HIrYXodOV2iWLWtEaIwg= github.com/cockroachdb/apd/v3 v3.2.1/go.mod h1:klXJcjp+FffLTHlhIG69tezTDvdP065naDsHzKhYSqc= 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 github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= +github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/lib/pq v1.10.7 h1:p7ZhMD+KsSRozJr34udlUrhboJwWAgCg34+/ZZNvZZw= +github.com/lib/pq v1.10.7/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0= github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0= 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= golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8= golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= +golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= diff --git a/internal/mod/modregistry/client.go b/internal/mod/modregistry/client.go index 56e4e3b8736..145ef1f99d4 100644 --- a/internal/mod/modregistry/client.go +++ b/internal/mod/modregistry/client.go @@ -41,7 +41,6 @@ var ErrNotFound = fmt.Errorf("module not found") // provides a store for CUE modules. type Client struct { registry ociregistry.Interface - prefix string } const ( @@ -51,16 +50,10 @@ const ( ) // NewClient returns a new client that talks to the registry at the given -// hostname. All repositories created or accessed in the registry -// will have the given prefix. -// -// TODO pass in an ociregistry.Interface instead of a URL, -// thus allowing a locally defined composition of registries -// rather than always assuming everything is behind a single host. -func NewClient(registry ociregistry.Interface, prefix string) (*Client, error) { +// hostname. +func NewClient(registry ociregistry.Interface) (*Client, error) { return &Client{ registry: registry, - prefix: prefix, }, nil } @@ -100,7 +93,7 @@ func (c *Client) GetModule(ctx context.Context, m module.Version) (*Module, erro func (c *Client) repoName(modPath string) string { path, _, _ := module.SplitPathVersion(modPath) - return c.prefix + path + return path } // ModuleVersions returns all the versions for the module with the given path. diff --git a/internal/mod/modregistry/client_test.go b/internal/mod/modregistry/client_test.go index 4c7353b45b9..89dbe03363e 100644 --- a/internal/mod/modregistry/client_test.go +++ b/internal/mod/modregistry/client_test.go @@ -34,7 +34,7 @@ import ( ) func newTestClient(t *testing.T) *Client { - c, err := NewClient(ocimem.New(), "") + c, err := NewClient(ocimem.New()) qt.Assert(t, qt.IsNil(err)) return c } diff --git a/internal/registrytest/registry.go b/internal/registrytest/registry.go index 962332579fe..60c1a4e3fba 100644 --- a/internal/registrytest/registry.go +++ b/internal/registrytest/registry.go @@ -8,9 +8,9 @@ import ( "io" "io/fs" "net/http/httptest" + "net/url" "strings" - "cuelabs.dev/go/oci/ociregistry/ociclient" "cuelabs.dev/go/oci/ociregistry/ocimem" "cuelabs.dev/go/oci/ociregistry/ociserver" "golang.org/x/tools/txtar" @@ -32,8 +32,8 @@ import ( // // The Registry should be closed after use. func New(fsys fs.FS) (*Registry, error) { - srv := httptest.NewServer(ociserver.New(ocimem.New(), nil)) - client, err := modregistry.NewClient(ociclient.New(srv.URL, nil), "cue/") + r := ocimem.New() + client, err := modregistry.NewClient(r) if err != nil { return nil, fmt.Errorf("cannot make client: %v", err) } @@ -44,8 +44,14 @@ func New(fsys fs.FS) (*Registry, error) { if err := pushContent(client, mods); err != nil { return nil, fmt.Errorf("cannot push modules: %v", err) } + srv := httptest.NewServer(ociserver.New(r, nil)) + u, err := url.Parse(srv.URL) + if err != nil { + return nil, err + } return &Registry{ - srv: srv, + srv: srv, + host: u.Host, }, nil } @@ -87,16 +93,20 @@ func visitDepthFirst(mods map[module.Version]*moduleContent, v module.Version, f } type Registry struct { - srv *httptest.Server + srv *httptest.Server + host string } func (r *Registry) Close() { r.srv.Close() } -// URL returns the base URL for the registry. -func (r *Registry) URL() string { - return r.srv.URL +// Host returns the hostname for the registry server; +// for example localhost:13455. +// +// The connection can be assumed to be insecure. +func (r *Registry) Host() string { + return r.host } type handler struct { diff --git a/internal/registrytest/registry_test.go b/internal/registrytest/registry_test.go index 5b354abbe25..a7ee023850e 100644 --- a/internal/registrytest/registry_test.go +++ b/internal/registrytest/registry_test.go @@ -39,14 +39,17 @@ func TestRegistry(t *testing.T) { t.Fatal(err) } defer r.Close() - runTest(t, ociclient.New(r.URL(), nil), string(ar.Comment), ar) + client, err := ociclient.New(r.Host(), &ociclient.Options{ + Insecure: true, + }) + runTest(t, client, string(ar.Comment), ar) }) } } func runTest(t *testing.T, registry ociregistry.Interface, script string, ar *txtar.Archive) { ctx := context.Background() - client, err := modregistry.NewClient(registry, "cue/") + client, err := modregistry.NewClient(registry) if err != nil { t.Fatal(err) }