Skip to content

Commit

Permalink
update ociregistry dependency
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
rogpeppe committed Sep 28, 2023
1 parent b664f0c commit a43792c
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 26 deletions.
8 changes: 7 additions & 1 deletion cue/load/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion cue/load/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand All @@ -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=
Expand All @@ -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=
Expand Down
13 changes: 3 additions & 10 deletions internal/mod/modregistry/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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
}

Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion internal/mod/modregistry/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
26 changes: 18 additions & 8 deletions internal/registrytest/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
}
Expand All @@ -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
}

Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 5 additions & 2 deletions internal/registrytest/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit a43792c

Please sign in to comment.