From b43a71f07d5b788e2d527ee13d12baae7ba9dcd9 Mon Sep 17 00:00:00 2001 From: Paul Hewlett Date: Tue, 21 May 2024 10:57:11 +0100 Subject: [PATCH] Standard service connection Assets and PublicAssets proto interface has standard service connection AB#8170 --- .../assets/v2/assets/client.go | 35 +++++++++++++++++++ .../assets/v2/assets/logger.go | 7 ++++ .../assets/v2/assets/publicclient.go | 33 +++++++++++++++++ datatrails-common-api/go.mod | 10 +++--- datatrails-common-api/go.sum | 20 +++++------ 5 files changed, 90 insertions(+), 15 deletions(-) create mode 100644 datatrails-common-api/assets/v2/assets/client.go create mode 100644 datatrails-common-api/assets/v2/assets/logger.go create mode 100644 datatrails-common-api/assets/v2/assets/publicclient.go diff --git a/datatrails-common-api/assets/v2/assets/client.go b/datatrails-common-api/assets/v2/assets/client.go new file mode 100644 index 0000000..ab85cb7 --- /dev/null +++ b/datatrails-common-api/assets/v2/assets/client.go @@ -0,0 +1,35 @@ +package assets + +import ( + "github.com/datatrails/go-datatrails-common/grpcclient" +) + +type ClientOption = grpcclient.ClientOption + +type Client struct { + g *grpcclient.Client + Client AssetsClient +} + +func NewClient(log Logger, address string, opts ...ClientOption) *Client { + return &Client{ + g: grpcclient.New(log, "assetsv2", address, opts...), + } +} + +func (c *Client) Open() error { + if c.Client != nil { + return nil + } + err := c.g.Open() + if err != nil { + return err + } + c.Client = NewAssetsClient(c.g.Connector()) + return nil +} + +func (c *Client) Close() { + c.g.Close() +} + diff --git a/datatrails-common-api/assets/v2/assets/logger.go b/datatrails-common-api/assets/v2/assets/logger.go new file mode 100644 index 0000000..2708c11 --- /dev/null +++ b/datatrails-common-api/assets/v2/assets/logger.go @@ -0,0 +1,7 @@ +package assets + +import ( + "github.com/datatrails/go-datatrails-common/logger" +) + +type Logger = logger.Logger diff --git a/datatrails-common-api/assets/v2/assets/publicclient.go b/datatrails-common-api/assets/v2/assets/publicclient.go new file mode 100644 index 0000000..3bfa319 --- /dev/null +++ b/datatrails-common-api/assets/v2/assets/publicclient.go @@ -0,0 +1,33 @@ +package assets + +import ( + "github.com/datatrails/go-datatrails-common/grpcclient" +) + +type PublicClient struct { + g *grpcclient.Client + Client PublicAssetsClient +} + +func NewPublicClient(log Logger, address string, opts ...ClientOption) *Client { + return &Client{ + g: grpcclient.New(log, "publicassetsv2", address, opts...), + } +} + +func (c *PublicClient) Open() error { + if c.Client != nil { + return nil + } + err := c.g.Open() + if err != nil { + return err + } + c.Client = NewPublicAssetsClient(c.g.Connector()) + return nil +} + +func (c *PublicClient) Close() { + c.g.Close() +} + diff --git a/datatrails-common-api/go.mod b/datatrails-common-api/go.mod index 24e3388..330fa0d 100644 --- a/datatrails-common-api/go.mod +++ b/datatrails-common-api/go.mod @@ -11,14 +11,14 @@ go 1.22 // replace github.com/datatrails/go-datatrails-common-api-gen => ./ require ( - github.com/datatrails/go-datatrails-common v0.10.2 + github.com/datatrails/go-datatrails-common v0.15.3 github.com/envoyproxy/protoc-gen-validate v1.0.2 github.com/google/uuid v1.4.0 github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.1 github.com/lyft/protoc-gen-star/v2 v2.0.3 github.com/pseudomuto/protoc-gen-doc v1.5.1 github.com/spf13/afero v1.3.3 - github.com/stretchr/testify v1.8.4 + github.com/stretchr/testify v1.9.0 go.mongodb.org/mongo-driver v1.12.1 google.golang.org/genproto/googleapis/api v0.0.0-20231127180814-3a041ad873d4 google.golang.org/grpc v1.59.0 @@ -54,10 +54,10 @@ require ( go.uber.org/automaxprocs v1.5.3 // indirect go.uber.org/multierr v1.10.0 // indirect go.uber.org/zap v1.25.0 // indirect - golang.org/x/crypto v0.16.0 // indirect + golang.org/x/crypto v0.21.0 // indirect golang.org/x/mod v0.11.0 // indirect - golang.org/x/net v0.17.0 // indirect - golang.org/x/sys v0.15.0 // indirect + golang.org/x/net v0.21.0 // indirect + golang.org/x/sys v0.18.0 // indirect golang.org/x/text v0.14.0 // indirect golang.org/x/tools v0.10.0 // indirect google.golang.org/genproto v0.0.0-20231127180814-3a041ad873d4 // indirect diff --git a/datatrails-common-api/go.sum b/datatrails-common-api/go.sum index 8162097..bedd37e 100644 --- a/datatrails-common-api/go.sum +++ b/datatrails-common-api/go.sum @@ -14,8 +14,8 @@ github.com/containerd/cgroups/v3 v3.0.1 h1:4hfGvu8rfGIwVIDd+nLzn/B9ZXx4BcCjzt5To github.com/containerd/cgroups/v3 v3.0.1/go.mod h1:/vtwk1VXrtoa5AaZLkypuOJgA/6DyPMZHJPGQNtlHnw= github.com/coreos/go-systemd/v22 v22.3.2 h1:D9/bQk5vlXQFZ6Kwuu6zaiXJ9oTPe68++AzAJc1DzSI= github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= -github.com/datatrails/go-datatrails-common v0.10.2 h1:OnvayMGpeia3wHMrj26njuQlpsOvGjYOsHChvj6ErtQ= -github.com/datatrails/go-datatrails-common v0.10.2/go.mod h1:LsPfbYoTEEdPnANm0+seLRX2OO7c5yF7tZw8499prAM= +github.com/datatrails/go-datatrails-common v0.15.3 h1:GM45N4Gje6gWgcHzqYQP9LFRFn6MYma8PnGXvmXlW0o= +github.com/datatrails/go-datatrails-common v0.15.3/go.mod h1:lVLYVw5o+Wj+z8sn8bJBzp9qBCdYQ0DUX91+R5Gn73Q= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -91,8 +91,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= github.com/xdg-go/scram v1.1.2/go.mod h1:RT/sEzTbU5y00aCK8UOx6R7YryM0iF1N2MOmC3kKLN4= github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gijq1dTyGkM= @@ -116,8 +116,8 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY= -golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= +golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA= +golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= @@ -130,8 +130,8 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= -golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= +golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4= +golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -145,8 +145,8 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= -golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= +golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=