Skip to content

Commit

Permalink
feat: replace grpc with buf connect
Browse files Browse the repository at this point in the history
  • Loading branch information
jsiebens committed Jun 3, 2022
1 parent 687fcd1 commit da71a43
Show file tree
Hide file tree
Showing 58 changed files with 2,233 additions and 3,154 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
init:
go install github.com/bufbuild/buf/cmd/buf@latest
go install github.com/fullstorydev/grpcurl/cmd/grpcurl@latest
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install github.com/bufbuild/connect-go/cmd/protoc-gen-connect-go@latest

generate:
buf generate proto
9 changes: 3 additions & 6 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
version: v1beta1
version: v1
plugins:
- name: go
out: pkg/gen
opt: paths=source_relative
- name: go-grpc
- name: connect-go
out: pkg/gen
opt: paths=source_relative,require_unimplemented_servers=false
- name: grpc-gateway
out: pkg/gen
opt: paths=source_relative
opt: paths=source_relative
15 changes: 3 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ go 1.18

require (
github.com/apparentlymart/go-cidr v1.1.0
github.com/bufbuild/connect-go v0.1.0
github.com/caddyserver/certmagic v0.16.1
github.com/coreos/go-oidc/v3 v3.2.0
github.com/glebarez/sqlite v1.4.3
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.0.0-rc.2
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/hashicorp/go-bexpr v0.1.11
github.com/hashicorp/go-hclog v1.1.0
github.com/improbable-eng/grpc-web v0.15.0
github.com/klauspost/compress v1.15.3
github.com/labstack/echo-contrib v0.12.0
github.com/labstack/echo/v4 v4.6.3
Expand All @@ -22,15 +20,13 @@ require (
github.com/nleeper/goment v1.4.4
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/rodaine/table v1.0.1
github.com/soheilhy/cmux v0.1.5
github.com/sony/sonyflake v1.0.0
github.com/xhit/go-str2duration/v2 v2.0.0
golang.org/x/crypto v0.0.0-20220427172511-eb4f295cb31f
golang.org/x/net v0.0.0-20220407224826-aac1ed45d8e3
golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
google.golang.org/grpc v1.44.0
google.golang.org/protobuf v1.27.1
google.golang.org/protobuf v1.28.0
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.0
gorm.io/gorm v1.23.5
Expand All @@ -41,15 +37,13 @@ require (
require (
github.com/alexbrainman/sspi v0.0.0-20210105120005-909beea2cc74 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.1.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/glebarez/go-sqlite v1.16.0 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.7 // indirect
github.com/google/go-cmp v0.5.8 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
Expand All @@ -72,7 +66,6 @@ require (
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect
github.com/rs/cors v1.7.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/tkuchiki/go-timezone v0.2.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
Expand All @@ -91,12 +84,10 @@ require (
golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f // indirect
golang.zx2c4.com/wireguard/windows v0.4.10 // indirect
google.golang.org/appengine v1.6.6 // indirect
google.golang.org/genproto v0.0.0-20210126160654-44e461bb6506 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/square/go-jose.v2 v2.5.1 // indirect
modernc.org/libc v1.16.7 // indirect
modernc.org/mathutil v1.4.1 // indirect
modernc.org/memory v1.1.1 // indirect
modernc.org/sqlite v1.17.3 // indirect
nhooyr.io/websocket v1.8.7 // indirect
)
298 changes: 7 additions & 291 deletions go.sum

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions internal/cmd/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/bufbuild/connect-go"
"github.com/jsiebens/ionscale/internal/domain"
"github.com/jsiebens/ionscale/pkg/gen/api"
api "github.com/jsiebens/ionscale/pkg/gen/ionscale/v1"
"github.com/muesli/coral"
"gopkg.in/yaml.v2"
"io/ioutil"
Expand Down Expand Up @@ -40,14 +41,14 @@ func getACLConfig() *coral.Command {
return err
}

resp, err := client.GetACLPolicy(context.Background(), &api.GetACLPolicyRequest{TailnetId: tailnet.Id})
resp, err := client.GetACLPolicy(context.Background(), connect.NewRequest(&api.GetACLPolicyRequest{TailnetId: tailnet.Id}))
if err != nil {
return err
}

var p domain.ACLPolicy

if err := json.Unmarshal(resp.Value, &p); err != nil {
if err := json.Unmarshal(resp.Msg.Value, &p); err != nil {
return err
}

Expand Down Expand Up @@ -109,7 +110,7 @@ func setACLConfig() *coral.Command {
return err
}

_, err = client.SetACLPolicy(context.Background(), &api.SetACLPolicyRequest{TailnetId: tailnet.Id, Value: rawJson})
_, err = client.SetACLPolicy(context.Background(), connect.NewRequest(&api.SetACLPolicyRequest{TailnetId: tailnet.Id, Value: rawJson}))
if err != nil {
return err
}
Expand Down
17 changes: 9 additions & 8 deletions internal/cmd/auth_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package cmd
import (
"context"
"fmt"
"github.com/bufbuild/connect-go"
"github.com/hashicorp/go-bexpr"
"github.com/jsiebens/ionscale/pkg/gen/api"
api "github.com/jsiebens/ionscale/pkg/gen/ionscale/v1"
"github.com/muesli/coral"
"github.com/rodaine/table"
)
Expand Down Expand Up @@ -51,14 +52,14 @@ func listAuthFilterCommand() *coral.Command {
req.AuthMethodId = &authMethodID
}

resp, err := client.ListAuthFilters(context.Background(), req)
resp, err := client.ListAuthFilters(context.Background(), connect.NewRequest(req))

if err != nil {
return err
}

tbl := table.New("ID", "AUTH_METHOD", "TAILNET", "EXPR")
for _, filter := range resp.AuthFilters {
for _, filter := range resp.Msg.AuthFilters {
if filter.Tailnet != nil {
tbl.AddRow(filter.Id, filter.AuthMethod.Name, filter.Tailnet.Name, filter.Expr)
} else {
Expand Down Expand Up @@ -123,17 +124,17 @@ func createAuthFilterCommand() *coral.Command {
Expr: expr,
}

resp, err := client.CreateAuthFilter(context.Background(), req)
resp, err := client.CreateAuthFilter(context.Background(), connect.NewRequest(req))

if err != nil {
return err
}

tbl := table.New("ID", "AUTH_METHOD", "TAILNET", "EXPR")
if resp.AuthFilter.Tailnet != nil {
tbl.AddRow(resp.AuthFilter.Id, resp.AuthFilter.AuthMethod.Name, resp.AuthFilter.Tailnet.Name, resp.AuthFilter.Expr)
if resp.Msg.AuthFilter.Tailnet != nil {
tbl.AddRow(resp.Msg.AuthFilter.Id, resp.Msg.AuthFilter.AuthMethod.Name, resp.Msg.AuthFilter.Tailnet.Name, resp.Msg.AuthFilter.Expr)
} else {
tbl.AddRow(resp.AuthFilter.Id, resp.AuthFilter.AuthMethod.Name, "", resp.AuthFilter.Expr)
tbl.AddRow(resp.Msg.AuthFilter.Id, resp.Msg.AuthFilter.AuthMethod.Name, "", resp.Msg.AuthFilter.Expr)
}
tbl.Print()

Expand Down Expand Up @@ -167,7 +168,7 @@ func deleteAuthFilterCommand() *coral.Command {
AuthFilterId: authFilterID,
}

_, err = client.DeleteAuthFilter(context.Background(), req)
_, err = client.DeleteAuthFilter(context.Background(), connect.NewRequest(req))

if err != nil {
return err
Expand Down
13 changes: 7 additions & 6 deletions internal/cmd/auth_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package cmd
import (
"context"
"fmt"
"github.com/jsiebens/ionscale/pkg/gen/api"
"github.com/bufbuild/connect-go"
api "github.com/jsiebens/ionscale/pkg/gen/ionscale/v1"
"github.com/muesli/coral"
"github.com/rodaine/table"
str2dur "github.com/xhit/go-str2duration/v2"
Expand Down Expand Up @@ -72,7 +73,7 @@ func createAuthkeysCommand() *coral.Command {
Tags: tags,
Expiry: expiryDur,
}
resp, err := client.CreateAuthKey(context.Background(), req)
resp, err := client.CreateAuthKey(context.Background(), connect.NewRequest(req))

if err != nil {
return err
Expand All @@ -82,7 +83,7 @@ func createAuthkeysCommand() *coral.Command {
fmt.Println("Generated new auth key")
fmt.Println("Be sure to copy your new key below. It won't be shown in full again.")
fmt.Println("")
fmt.Printf(" %s\n", resp.Value)
fmt.Printf(" %s\n", resp.Msg.Value)
fmt.Println("")

return nil
Expand Down Expand Up @@ -110,7 +111,7 @@ func deleteAuthKeyCommand() *coral.Command {
defer safeClose(c)

req := api.DeleteAuthKeyRequest{AuthKeyId: authKeyId}
if _, err := grpcClient.DeleteAuthKey(context.Background(), &req); err != nil {
if _, err := grpcClient.DeleteAuthKey(context.Background(), connect.NewRequest(&req)); err != nil {
return err
}

Expand Down Expand Up @@ -149,13 +150,13 @@ func listAuthkeysCommand() *coral.Command {
}

req := &api.ListAuthKeysRequest{TailnetId: tailnet.Id}
resp, err := client.ListAuthKeys(context.Background(), req)
resp, err := client.ListAuthKeys(context.Background(), connect.NewRequest(req))

if err != nil {
return err
}

printAuthKeyTable(resp.AuthKeys...)
printAuthKeyTable(resp.Msg.AuthKeys...)

return nil
}
Expand Down
11 changes: 6 additions & 5 deletions internal/cmd/auth_method.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package cmd

import (
"context"
"github.com/jsiebens/ionscale/pkg/gen/api"
"github.com/bufbuild/connect-go"
api "github.com/jsiebens/ionscale/pkg/gen/ionscale/v1"
"github.com/muesli/coral"
"github.com/rodaine/table"
)
Expand Down Expand Up @@ -39,14 +40,14 @@ func listAuthMethods() *coral.Command {
}
defer safeClose(c)

resp, err := client.ListAuthMethods(context.Background(), &api.ListAuthMethodsRequest{})
resp, err := client.ListAuthMethods(context.Background(), connect.NewRequest(&api.ListAuthMethodsRequest{}))

if err != nil {
return err
}

tbl := table.New("ID", "NAME", "TYPE")
for _, m := range resp.AuthMethods {
for _, m := range resp.Msg.AuthMethods {
tbl.AddRow(m.Id, m.Name, m.Type)
}
tbl.Print()
Expand Down Expand Up @@ -110,14 +111,14 @@ func createOIDCAuthMethodCommand() *coral.Command {
ClientSecret: clientSecret,
}

resp, err := client.CreateAuthMethod(context.Background(), req)
resp, err := client.CreateAuthMethod(context.Background(), connect.NewRequest(req))

if err != nil {
return err
}

tbl := table.New("ID", "NAME", "TYPE")
tbl.AddRow(resp.AuthMethod.Id, resp.AuthMethod.Name, resp.AuthMethod.Type)
tbl.AddRow(resp.Msg.AuthMethod.Id, resp.Msg.AuthMethod.Name, resp.Msg.AuthMethod.Type)
tbl.Print()

return nil
Expand Down
11 changes: 6 additions & 5 deletions internal/cmd/derp_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/jsiebens/ionscale/pkg/gen/api"
"github.com/bufbuild/connect-go"
api "github.com/jsiebens/ionscale/pkg/gen/ionscale/v1"
"github.com/muesli/coral"
"gopkg.in/yaml.v2"
"io/ioutil"
Expand Down Expand Up @@ -43,7 +44,7 @@ func getDERPMap() *coral.Command {
}
defer safeClose(c)

resp, err := client.GetDERPMap(context.Background(), &api.GetDERPMapRequest{})
resp, err := client.GetDERPMap(context.Background(), connect.NewRequest(&api.GetDERPMapRequest{}))

if err != nil {
return err
Expand All @@ -53,7 +54,7 @@ func getDERPMap() *coral.Command {
Regions map[int]*tailcfg.DERPRegion
}

if err := json.Unmarshal(resp.Value, &derpMap); err != nil {
if err := json.Unmarshal(resp.Msg.Value, &derpMap); err != nil {
return err
}

Expand Down Expand Up @@ -105,13 +106,13 @@ func setDERPMap() *coral.Command {
return err
}

resp, err := grpcClient.SetDERPMap(context.Background(), &api.SetDERPMapRequest{Value: rawJson})
resp, err := grpcClient.SetDERPMap(context.Background(), connect.NewRequest(&api.SetDERPMapRequest{Value: rawJson}))
if err != nil {
return err
}

var derpMap tailcfg.DERPMap
if err := json.Unmarshal(resp.Value, &derpMap); err != nil {
if err := json.Unmarshal(resp.Msg.Value, &derpMap); err != nil {
return err
}

Expand Down
11 changes: 6 additions & 5 deletions internal/cmd/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package cmd
import (
"context"
"fmt"
"github.com/jsiebens/ionscale/pkg/gen/api"
"github.com/bufbuild/connect-go"
api "github.com/jsiebens/ionscale/pkg/gen/ionscale/v1"
"github.com/muesli/coral"
"strings"
)
Expand Down Expand Up @@ -36,12 +37,12 @@ func getDNSConfig() *coral.Command {
}

req := api.GetDNSConfigRequest{TailnetId: tailnet.Id}
resp, err := client.GetDNSConfig(context.Background(), &req)
resp, err := client.GetDNSConfig(context.Background(), connect.NewRequest(&req))

if err != nil {
return err
}
config := resp.Config
config := resp.Msg.Config

var allNameservers = config.Nameservers

Expand Down Expand Up @@ -120,13 +121,13 @@ func setDNSConfig() *coral.Command {
Routes: routes,
},
}
resp, err := client.SetDNSConfig(context.Background(), &req)
resp, err := client.SetDNSConfig(context.Background(), connect.NewRequest(&req))

if err != nil {
return err
}

config := resp.Config
config := resp.Msg.Config

var allNameservers = config.Nameservers

Expand Down
Loading

0 comments on commit da71a43

Please sign in to comment.