From 7a3d6cb58ca170809364cf92f54f68ca2ce50f28 Mon Sep 17 00:00:00 2001 From: Jimmy Zelinskie Date: Tue, 6 Jul 2021 14:13:52 -0400 Subject: [PATCH 1/3] reorganize package to support multiple clients Signed-off-by: Jimmy Zelinskie --- README.md | 9 +-- go.mod | 5 +- go.sum | 43 +++++++++-- client.go => v0/client.go | 3 +- {examples => v0/examples}/example.go | 2 +- {examples => v0/examples}/yourtenant.yaml | 0 examples_test.go => v0/examples_test.go | 2 +- filter.go => v0/filter.go | 2 +- filter_test.go => v0/filter_test.go | 0 flatten.go => v0/flatten.go | 0 flatten_test.go => v0/flatten_test.go | 0 integration_test.go => v0/integration_test.go | 2 +- {x => v0/x}/nsbuilder/nsbuilder.go | 0 {x => v0/x}/parallel/parallel.go | 0 v1alpha1/client.go | 30 ++++++++ v1alpha1/client_test.go | 22 ++++++ x/pool/pool.go | 72 ------------------- x/pool/pool_example_test.go | 48 ------------- 18 files changed, 100 insertions(+), 140 deletions(-) rename client.go => v0/client.go (98%) rename {examples => v0/examples}/example.go (99%) rename {examples => v0/examples}/yourtenant.yaml (100%) rename examples_test.go => v0/examples_test.go (95%) rename filter.go => v0/filter.go (98%) rename filter_test.go => v0/filter_test.go (100%) rename flatten.go => v0/flatten.go (100%) rename flatten_test.go => v0/flatten_test.go (100%) rename integration_test.go => v0/integration_test.go (96%) rename {x => v0/x}/nsbuilder/nsbuilder.go (100%) rename {x => v0/x}/parallel/parallel.go (100%) create mode 100644 v1alpha1/client.go create mode 100644 v1alpha1/client_test.go delete mode 100644 x/pool/pool.go delete mode 100644 x/pool/pool_example_test.go diff --git a/README.md b/README.md index 1e8cb98..b079335 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,17 @@ # authzed-go The official Go client library for Authzed. +This repository is a collection of Go packages specialized for each versions of the Authzed API. -## Example +## Example (v0 API) This example demonstrates initializing a client and making a [Check request] to an existing [Namespace]. -A more full example can be found in the [examples directory]. +A more full example can be found in [v0/examples]. [Check request]:https://docs.authzed.com/concept/check [Namespace]: https://docs.authzed.com/concept/namespaces -[examples directory]: examples +[v0/examples]: /v0/examples ```go package main @@ -19,7 +20,7 @@ import ( "context" "log" - "github.com/authzed/authzed-go" + "github.com/authzed/authzed-go/v0" "github.com/authzed/authzed-go/proto/authzed/api/v0" ) diff --git a/go.mod b/go.mod index 80bdbde..03af547 100644 --- a/go.mod +++ b/go.mod @@ -3,11 +3,10 @@ module github.com/authzed/authzed-go go 1.16 require ( + github.com/authzed/grpcutil v0.0.0-20210702215403-5fe6e00b4101 github.com/envoyproxy/protoc-gen-validate v0.6.1 - github.com/golang/protobuf v1.5.2 github.com/jzelinskie/stringz v0.0.0-20210414224931-d6a8ce844a70 - github.com/processout/grpc-go-pool v1.2.1 golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e - google.golang.org/grpc v1.35.0 + google.golang.org/grpc v1.39.0 google.golang.org/protobuf v1.26.0 ) diff --git a/go.sum b/go.sum index de3e91a..c9e212f 100644 --- a/go.sum +++ b/go.sum @@ -1,19 +1,30 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= +github.com/authzed/grpcutil v0.0.0-20210702215403-5fe6e00b4101 h1:z29rHmtuSh2jqwh5AzBXLJ6oGYnW2lEGdDkw0506uqk= +github.com/authzed/grpcutil v0.0.0-20210702215403-5fe6e00b4101/go.mod h1:ZWOuCUQ/qoVIAWUctRy/lWHI37OcahRzt5ylELzumus= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= +github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= +github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.mod h1:hliV/p42l8fGbc6Y9bQ70uLwIvmJyVE5k4iMKlh8wCQ= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/envoyproxy/protoc-gen-validate v0.6.1 h1:4CF52PCseTFt4bE+Yk3dIpdVi7XWuPVMhPtm4FaIJPM= github.com/envoyproxy/protoc-gen-validate v0.6.1/go.mod h1:txg5va2Qkip90uYoSKH+nkAAmXrb2j3iq4FLwdrCbXQ= +github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= @@ -21,6 +32,7 @@ github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:W github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= @@ -32,6 +44,7 @@ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/iancoleman/strcase v0.0.0-20180726023541-3605ed457bf7/go.mod h1:SK73tn/9oHe+/Y0h39VT4UCxmurVJkR5NA7kMEAOgSE= github.com/jzelinskie/stringz v0.0.0-20210414224931-d6a8ce844a70 h1:thTca5Eyouk5CEcJ75Cbw9CSAGE7TAc6rIi+WgHWpOE= github.com/jzelinskie/stringz v0.0.0-20210414224931-d6a8ce844a70/go.mod h1:hHYbgxJuNLRw91CmpuFsYEOyQqpDVFg8pvEh23vy4P0= @@ -39,20 +52,24 @@ github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/lyft/protoc-gen-star v0.5.1/go.mod h1:9toiA3cC7z5uVbODF7kEQ91Xn7XNFkVUl+SrEe+ZORU= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/processout/grpc-go-pool v1.2.1 h1:hbp1BOA02CIxEAoRLHGpUhhPFv77nwfBLBeO3Ya9P7I= -github.com/processout/grpc-go-pool v1.2.1/go.mod h1:F4hiNj96O6VQ87jv4rdz8R9tkHdelQQJ/J2B1a5VSt4= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/spf13/afero v1.3.3/go.mod h1:5KUK8ByomD5Ti5Artl0RtHeI5pTF7MIDuXL3yY520V4= github.com/spf13/afero v1.3.4/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= @@ -62,22 +79,27 @@ golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzB golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200226121028-0de0cce0169b h1:0mm1VjtFUOIlE1SbDlwjYaDxZVDP2S5ou6y0gSgXHu8= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200822124328-c89045814202 h1:VvcQYSHwXgi7W+TpUR6A9g6Up98WAHf3f/ulnJ62IyA= +golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= @@ -91,20 +113,24 @@ golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapK golang.org/x/tools v0.0.0-20200522201501-cb1345f3a375/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 h1:+kGHl1aib/qcwaRi1CbqBZ1rk19r85MNUf8HaBghugY= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/grpc v1.35.0 h1:TwIQcH3es+MojMVojxxfQ3l3OF2KzlRxML2xZq0kRo8= -google.golang.org/grpc v1.35.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= +google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= +google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= +google.golang.org/grpc v1.39.0 h1:Klz8I9kdtkIN6EpHHUOMLCYhTn/2WAe5a0s1hcBkdTI= +google.golang.org/grpc v1.39.0/go.mod h1:PImNr+rS9TWYb2O4/emRugxiyHZ5JyHW5F+RPnDzfrE= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= @@ -117,8 +143,11 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/client.go b/v0/client.go similarity index 98% rename from client.go rename to v0/client.go index 0e41f24..1710c81 100644 --- a/client.go +++ b/v0/client.go @@ -53,8 +53,7 @@ func SystemCerts(v CertVerification) grpc.DialOption { return grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{ RootCAs: certPool, - InsecureSkipVerify: bool(v), - })) + InsecureSkipVerify: bool(v)})) } // NewClient initializes a brand new client for interacting with Authzed. diff --git a/examples/example.go b/v0/examples/example.go similarity index 99% rename from examples/example.go rename to v0/examples/example.go index 94f4502..d4811d3 100644 --- a/examples/example.go +++ b/v0/examples/example.go @@ -4,8 +4,8 @@ import ( "context" "log" - "github.com/authzed/authzed-go" v0 "github.com/authzed/authzed-go/proto/authzed/api/v0" + "github.com/authzed/authzed-go/v0" ) const ( diff --git a/examples/yourtenant.yaml b/v0/examples/yourtenant.yaml similarity index 100% rename from examples/yourtenant.yaml rename to v0/examples/yourtenant.yaml diff --git a/examples_test.go b/v0/examples_test.go similarity index 95% rename from examples_test.go rename to v0/examples_test.go index df43ff4..3882f62 100644 --- a/examples_test.go +++ b/v0/examples_test.go @@ -4,8 +4,8 @@ import ( "context" "log" - "github.com/authzed/authzed-go" v0 "github.com/authzed/authzed-go/proto/authzed/api/v0" + "github.com/authzed/authzed-go/v0" ) func ExampleNewClient() { diff --git a/filter.go b/v0/filter.go similarity index 98% rename from filter.go rename to v0/filter.go index d6f8c24..06b01e0 100644 --- a/filter.go +++ b/v0/filter.go @@ -6,7 +6,7 @@ import ( "reflect" v0 "github.com/authzed/authzed-go/proto/authzed/api/v0" - "github.com/authzed/authzed-go/x/parallel" + "github.com/authzed/authzed-go/v0/x/parallel" ) const ( diff --git a/filter_test.go b/v0/filter_test.go similarity index 100% rename from filter_test.go rename to v0/filter_test.go diff --git a/flatten.go b/v0/flatten.go similarity index 100% rename from flatten.go rename to v0/flatten.go diff --git a/flatten_test.go b/v0/flatten_test.go similarity index 100% rename from flatten_test.go rename to v0/flatten_test.go diff --git a/integration_test.go b/v0/integration_test.go similarity index 96% rename from integration_test.go rename to v0/integration_test.go index 50d1d28..40006e4 100644 --- a/integration_test.go +++ b/v0/integration_test.go @@ -10,7 +10,7 @@ import ( "google.golang.org/grpc" v0 "github.com/authzed/authzed-go/proto/authzed/api/v0" - "github.com/authzed/authzed-go/x/nsbuilder" + "github.com/authzed/authzed-go/v0/x/nsbuilder" ) var setupOnce sync.Once diff --git a/x/nsbuilder/nsbuilder.go b/v0/x/nsbuilder/nsbuilder.go similarity index 100% rename from x/nsbuilder/nsbuilder.go rename to v0/x/nsbuilder/nsbuilder.go diff --git a/x/parallel/parallel.go b/v0/x/parallel/parallel.go similarity index 100% rename from x/parallel/parallel.go rename to v0/x/parallel/parallel.go diff --git a/v1alpha1/client.go b/v1alpha1/client.go new file mode 100644 index 0000000..2f064c4 --- /dev/null +++ b/v1alpha1/client.go @@ -0,0 +1,30 @@ +package authzed + +import ( + "github.com/jzelinskie/stringz" + "google.golang.org/grpc" + + v1alpha1 "github.com/authzed/authzed-go/proto/authzed/api/v1alpha1" +) + +// Client represents an open connection to Authzed. +// +// Clients are backed by a gRPC client and as such are thread-safe. +type Client struct { + v1alpha1.SchemaServiceClient +} + +// NewClient initializes a brand new client for interacting with Authzed. +func NewClient(endpoint string, opts ...grpc.DialOption) (*Client, error) { + conn, err := grpc.Dial( + stringz.DefaultEmpty(endpoint, "grpc.authzed.com:443"), + opts..., + ) + if err != nil { + return nil, err + } + + return &Client{ + v1alpha1.NewSchemaServiceClient(conn), + }, nil +} diff --git a/v1alpha1/client_test.go b/v1alpha1/client_test.go new file mode 100644 index 0000000..bfea095 --- /dev/null +++ b/v1alpha1/client_test.go @@ -0,0 +1,22 @@ +package authzed_test + +import ( + "fmt" + "log" + "testing" + + "github.com/authzed/authzed-go/v1alpha1" + "github.com/authzed/grpcutil" +) + +func ExampleNewClient(t *testing.T) { + client, err := authzed.NewClient( + "grpc.authzed.com:443", + grpcutil.WithBearerToken("tc_my_token_deadbeefdeadbeefdeadbeef"), + grpcutil.WithSystemCerts(false), + ) + if err != nil { + log.Fatalf("failed to connect to authzed: %s", err) + } + fmt.Println(client) +} diff --git a/x/pool/pool.go b/x/pool/pool.go deleted file mode 100644 index dd0af41..0000000 --- a/x/pool/pool.go +++ /dev/null @@ -1,72 +0,0 @@ -// Package pool implements experimental pooling of Authzed clients. -// -// Without pooling, Authzed clients are thread-safe and support concurrent -// requests. Thus, pooling should only be used after instrumentation has proven -// that the application would benefit from the additional throughput. -package pool - -import ( - "context" - "time" - - "github.com/jzelinskie/stringz" - grpcpool "github.com/processout/grpc-go-pool" - "google.golang.org/grpc" - - "github.com/authzed/authzed-go" - v0 "github.com/authzed/authzed-go/proto/authzed/api/v0" -) - -// Client implements an Authzed client with an additional Close() method that -// returns the client connection to a connection pool. -type Client struct { - *authzed.Client - closefn func() error -} - -// Close returns the client connection to its connection pool. -func (c *Client) Close() error { - return c.closefn() -} - -// ClientPool represents a pool of reusable client connections to Authzed. -// -// Without pooling, Authzed clients are thread-safe and support concurrent -// requests. Thus, pooling should only be used after instrumentation has proven -// that the application would benefit from the additional throughput. -type ClientPool struct { - connPool *grpcpool.Pool -} - -// Get fetches a connection from the pool and allocates a new client using it. -// -// The returned client should have its Close() method called to return the -// connection to the pool. -func (p *ClientPool) Get(ctx context.Context) (*Client, error) { - conn, err := p.connPool.Get(ctx) - if err != nil { - return nil, err - } - - return &Client{ - Client: &authzed.Client{ - ACLServiceClient: v0.NewACLServiceClient(conn), - NamespaceServiceClient: v0.NewNamespaceServiceClient(conn), - }, - closefn: conn.Close, - }, nil -} - -// NewClientPool returns a new pool of reusable Authzed clients. -func NewClientPool(endpoint string, poolSize int, opts ...grpc.DialOption) (*ClientPool, error) { - factory := func() (*grpc.ClientConn, error) { - return grpc.Dial(stringz.DefaultEmpty(endpoint, "grpc.authzed.com:443"), opts...) - } - - pool, err := grpcpool.New(factory, poolSize, poolSize, time.Second) - if err != nil { - return nil, err - } - - return &ClientPool{pool}, nil -} diff --git a/x/pool/pool_example_test.go b/x/pool/pool_example_test.go deleted file mode 100644 index 8ff2747..0000000 --- a/x/pool/pool_example_test.go +++ /dev/null @@ -1,48 +0,0 @@ -package pool_test - -import ( - "context" - "log" - - "github.com/authzed/authzed-go" - v0 "github.com/authzed/authzed-go/proto/authzed/api/v0" - "github.com/authzed/authzed-go/x/pool" -) - -func ExampleNewClientPool() { - clientPool, err := pool.NewClientPool( - "grpc.authzed.com:443", - 10, - authzed.Token("my_token_deadbeefdeadbeefdeadbeef"), - authzed.SystemCerts(authzed.VerifyCA), - ) - if err != nil { - log.Fatal(err) - } - - ctx := context.Background() - - client, err := clientPool.Get(ctx) - if err != nil { - log.Fatal(err) - } - defer client.Close() // Returns client to pool; does not disconnect client. - - _, err = client.Check(ctx, &v0.CheckRequest{ - TestUserset: &v0.ObjectAndRelation{ - Namespace: "mytenant/document", - ObjectId: "readme", - Relation: "viewer", - }, - User: &v0.User{UserOneof: &v0.User_Userset{ - Userset: &v0.ObjectAndRelation{ - Namespace: "mytenant/user", - ObjectId: "jimmy", - Relation: "...", - }, - }}, - }) - if err != nil { - log.Fatal(err) - } -} From 53d8bea0c9f88563369106d5ec251fb3cf3f6a97 Mon Sep 17 00:00:00 2001 From: Jimmy Zelinskie Date: Tue, 6 Jul 2021 14:23:25 -0400 Subject: [PATCH 2/3] .github: use revive for linting Signed-off-by: Jimmy Zelinskie --- .github/workflows/build.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index eb169cc..76505e1 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -44,7 +44,10 @@ jobs: echo "${GO_MOD_OUPUT}" exit 1 fi - - uses: golangci/golangci-lint-action@v2 + - name: "go lint" + run: | + go install github.com/mgechev/revive@latest + revive ./... test: name: "Test" From 5ffbfb03613e8375be0427e3345032233f76d1c8 Mon Sep 17 00:00:00 2001 From: Jimmy Zelinskie Date: Tue, 6 Jul 2021 14:41:09 -0400 Subject: [PATCH 3/3] .github: use gofumports Signed-off-by: Jimmy Zelinskie --- .github/workflows/build.yaml | 27 ++++++++------------------- v0/client.go | 3 ++- v0/examples/example.go | 3 ++- v0/integration_test.go | 16 +++++++--------- v1alpha1/client_test.go | 5 +++-- 5 files changed, 22 insertions(+), 32 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 76505e1..fba6336 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -16,26 +16,19 @@ jobs: - uses: "actions/setup-go@v2" with: go-version: ^1.16 - - name: "go fmt" + - name: "go imports" run: | - GOFMT_OUTPUT="$(gofmt -l `find ./ -name '*.go' | grep -v vendor` 2>&1)" - - if [ -n "$GOFMT_OUTPUT" ]; then + go install mvdan.cc/gofumpt/gofumports@latest + GOFUMPT_OUTPUT="$(gofumports -d `find . -name '*.go' | grep -v ./proto/`)" + if [ -n "$GOFUMPT_OUTPUT" ]; then echo "All the following files are not correctly formatted" - echo "${GOFMT_OUTPUT}" + echo "${GOFUMPT_OUTPUT}" exit 1 fi - - name: "go imports" + - name: "go lint" run: | - exec 5>&1 - GOIMPORTS_OUTPUT="$(goimports -l -w `find ./ -name '*.go' | grep -v vendor` | tee /dev/fd/5)" - - if [ -n "$GOIMPORTS_OUTPUT" ]; then - echo "All following has imports not properly ordered" - echo "${GOIMPORTS_OUTPUT}" - - exit 1 - fi + go install github.com/mgechev/revive@latest + revive ./... - name: "go mod tidy" run: | GO_MOD_OUPUT="$(go mod tidy -v 2>&1)" @@ -44,10 +37,6 @@ jobs: echo "${GO_MOD_OUPUT}" exit 1 fi - - name: "go lint" - run: | - go install github.com/mgechev/revive@latest - revive ./... test: name: "Test" diff --git a/v0/client.go b/v0/client.go index 1710c81..0e41f24 100644 --- a/v0/client.go +++ b/v0/client.go @@ -53,7 +53,8 @@ func SystemCerts(v CertVerification) grpc.DialOption { return grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{ RootCAs: certPool, - InsecureSkipVerify: bool(v)})) + InsecureSkipVerify: bool(v), + })) } // NewClient initializes a brand new client for interacting with Authzed. diff --git a/v0/examples/example.go b/v0/examples/example.go index d4811d3..c4ad179 100644 --- a/v0/examples/example.go +++ b/v0/examples/example.go @@ -36,7 +36,8 @@ func main() { createTuple(tuple(aDoc("owner"), anOwner)), createTuple(tuple(aDoc("contributor"), anEditor)), createTuple(tuple(aDoc("viewer"), aViewer)), - }}) + }, + }) if err != nil { log.Fatalf("unable to write tuples: %s", err) } diff --git a/v0/integration_test.go b/v0/integration_test.go index 40006e4..792011c 100644 --- a/v0/integration_test.go +++ b/v0/integration_test.go @@ -23,15 +23,13 @@ var ( ) ) -var ( - fred = &v0.User{UserOneof: &v0.User_Userset{ - Userset: &v0.ObjectAndRelation{ - Namespace: "test/user", - ObjectId: "fred", - Relation: "...", - }, - }} -) +var fred = &v0.User{UserOneof: &v0.User_Userset{ + Userset: &v0.ObjectAndRelation{ + Namespace: "test/user", + ObjectId: "fred", + Relation: "...", + }, +}} func setupTenant(t *testing.T) *Client { client, err := NewClient("localhost:50051", grpc.WithInsecure()) diff --git a/v1alpha1/client_test.go b/v1alpha1/client_test.go index bfea095..4577ccf 100644 --- a/v1alpha1/client_test.go +++ b/v1alpha1/client_test.go @@ -5,11 +5,12 @@ import ( "log" "testing" - "github.com/authzed/authzed-go/v1alpha1" "github.com/authzed/grpcutil" + + authzed "github.com/authzed/authzed-go/v1alpha1" ) -func ExampleNewClient(t *testing.T) { +func ExampleNewClient(_ *testing.T) { client, err := authzed.NewClient( "grpc.authzed.com:443", grpcutil.WithBearerToken("tc_my_token_deadbeefdeadbeefdeadbeef"),