Skip to content
This repository has been archived by the owner on Jun 18, 2024. It is now read-only.

Commit

Permalink
it compiles again
Browse files Browse the repository at this point in the history
  • Loading branch information
zbindenren committed Jun 14, 2024
1 parent 19f3ec0 commit 0794bc0
Show file tree
Hide file tree
Showing 11 changed files with 277 additions and 257 deletions.
27 changes: 14 additions & 13 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
---
run:
tests: false
skip-dirs:
- .github
- build
- web
- .go
linters-settings:
dupl:
threshold: 100
funlen:
lines: 105
lines: 100
statements: 50
goconst:
min-len: 2
Expand All @@ -21,20 +18,16 @@ linters-settings:
- performance
- style
disabled-checks:
- whyNoLint
- hugeParam
gocyclo:
min-complexity: 16
min-complexity: 15
revive:
min-confidence: 0.8
govet:
check-shadowing: true
confidence: 0.8
lll:
line-length: 140
misspell:
locale: US
nolintlint:
allow-leading-space: false
require-explanation: true
allow-no-explanation:
- gocognit
Expand All @@ -45,8 +38,8 @@ linters:
disable-all: true
enable:
- bodyclose
- depguard
- dogsled
- dupl
- errcheck
- funlen
- nolintlint
Expand All @@ -67,9 +60,12 @@ linters:
- misspell
- nakedret
- prealloc
- protogetter
- rowserrcheck
- exportloopref
- staticcheck
- stylecheck
- sqlclosecheck
- typecheck
- unconvert
- unparam
Expand All @@ -86,3 +82,8 @@ issues:
- 'shadow: declaration of "err" shadows declaration.*'
max-same-issues: 0
exclude-use-default: false
exclude-dirs:
- .github
- build
- web
- .go
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ require (
github.com/golang/protobuf v1.5.2
github.com/google/renameio v1.0.1
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.0
github.com/hashicorp/go-cleanhttp v0.5.1
github.com/pkg/errors v0.9.1
github.com/postfinance/flash v0.5.0
github.com/postfinance/profiler v0.1.1
Expand Down
5 changes: 1 addition & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,6 @@ github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69
github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg=
github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/glog v1.0.0 h1:nfP3RFugxnNRyKgeWd4oI1nYvXpxrx8ck8ZrcizshdQ=
github.com/golang/glog v1.0.0/go.mod h1:EWib/APOK0SL3dFbYqvxE3UYd8E6s1ouQ7iEp/0LWV4=
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
Expand Down Expand Up @@ -225,11 +223,10 @@ github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgf
github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo=
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.0 h1:1JYBfzqrWPcCclBwxFCPAou9n+q86mfnu7NAeHfte7A=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.0/go.mod h1:YDZoGHuwE+ov0c8smSH49WLF3F2LaWnYYuDVd+EWrc0=
github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q=
github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVoDkXMzJM=
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM=
Expand Down
55 changes: 41 additions & 14 deletions internal/cmd/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ package client

import (
"context"
"crypto/tls"
"crypto/x509"
"net/http"
"os"
"path/filepath"
"time"

"github.com/alecthomas/kong"
"github.com/hashicorp/go-cleanhttp"
"github.com/pkg/errors"
"github.com/postfinance/discovery/internal/auth"
discoveryv1 "github.com/postfinance/discovery/pkg/discoverypb/postfinance/discovery/v1"
discoveryv1connect "github.com/postfinance/discovery/pkg/discoverypb/postfinance/discovery/v1/discoveryv1connect"
"github.com/zbindenren/king"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
Expand All @@ -32,7 +35,7 @@ type CLI struct {

// Globals are the global client flags.
type Globals struct {
Address string `short:"a" help:"The address of the discovery grpc endpoint." default:"localhost:3001"`
Address string `short:"a" help:"The address of the discovery grpc endpoint." default:"http://localhost:3001"`
Timeout time.Duration `help:"The request timeout" default:"15s"`
Debug bool `short:"d" help:"Log debug output."`
Insecure bool `help:"use insecure connection without tls." xor:"tls"`
Expand Down Expand Up @@ -83,40 +86,40 @@ func (g Globals) conn() (*grpc.ClientConn, error) {
return grpc.Dial(g.Address, dialOpts...)
}

func (g Globals) serverClient() (discoveryv1.ServerAPIClient, error) {
conn, err := g.conn()
func (g Globals) serverClient() (discoveryv1connect.ServerAPIClient, error) {
c, err := g.httpClient()
if err != nil {
return nil, err
}

return discoveryv1.NewServerAPIClient(conn), nil
return discoveryv1connect.NewServerAPIClient(c, g.Address), nil
}

func (g Globals) serviceClient() (discoveryv1.ServiceAPIClient, error) {
conn, err := g.conn()
func (g Globals) serviceClient() (discoveryv1connect.ServiceAPIClient, error) {
c, err := g.httpClient()
if err != nil {
return nil, err
}

return discoveryv1.NewServiceAPIClient(conn), nil
return discoveryv1connect.NewServiceAPIClient(c, g.Address), nil
}

func (g Globals) namespaceClient() (discoveryv1.NamespaceAPIClient, error) {
conn, err := g.conn()
func (g Globals) namespaceClient() (discoveryv1connect.NamespaceAPIClient, error) {
c, err := g.httpClient()
if err != nil {
return nil, err
}

return discoveryv1.NewNamespaceAPIClient(conn), nil
return discoveryv1connect.NewNamespaceAPIClient(c, g.Address), nil
}

func (g Globals) tokenClient() (discoveryv1.TokenAPIClient, error) {
conn, err := g.conn()
func (g Globals) tokenClient() (discoveryv1connect.TokenAPIClient, error) {
c, err := g.httpClient()
if err != nil {
return nil, err
}

return discoveryv1.NewTokenAPIClient(conn), nil
return discoveryv1connect.NewTokenAPIClient(c, g.Address), nil
}

func buildClientInterceptor(token string) func(context.Context, string, interface{}, interface{}, *grpc.ClientConn, grpc.UnaryInvoker, ...grpc.CallOption) error {
Expand Down Expand Up @@ -211,3 +214,27 @@ func (g Globals) getToken() (string, error) {

return token, nil
}

func (g Globals) httpClient() (*http.Client, error) {
clnt := cleanhttp.DefaultClient()
clnt.Timeout = g.Timeout

tlsConfig := &tls.Config{
InsecureSkipVerify: g.Insecure, //nolint:gosec // configurable
}

if !g.Insecure {
pool, err := x509.SystemCertPool()
if err != nil {
return nil, err
}

tlsConfig.RootCAs = pool
}

clnt.Transport = &http.Transport{
TLSClientConfig: tlsConfig,
}

return clnt, nil
}
18 changes: 10 additions & 8 deletions internal/cmd/client/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"os"

"connectrpc.com/connect"
"github.com/alecthomas/kong"
"github.com/postfinance/discovery"
"github.com/postfinance/discovery/internal/server/convert"
Expand Down Expand Up @@ -33,12 +34,12 @@ func (n namespaceList) Run(g *Globals, l *zap.SugaredLogger, c *kong.Context) er
ctx, cancel := g.ctx()
defer cancel()

r, err := cli.ListNamespace(ctx, &discoveryv1.ListNamespaceRequest{})
r, err := cli.ListNamespace(ctx, connect.NewRequest(&discoveryv1.ListNamespaceRequest{}))
if err != nil {
return err
}

namespaces := convert.NamespacesFromPB(r.GetNamespaces())
namespaces := convert.NamespacesFromPB(r.Msg.GetNamespaces())

sw := sfmt.SliceWriter{
Writer: os.Stdout,
Expand Down Expand Up @@ -78,10 +79,11 @@ func (n namespaceRegister) Run(g *Globals, l *zap.SugaredLogger, c *kong.Context
return errors.New("unsupported export configuration")
}

_, err = cli.RegisterNamespace(ctx, &discoveryv1.RegisterNamespaceRequest{
Name: n.Name,
Export: int32(e),
})
_, err = cli.RegisterNamespace(ctx, connect.NewRequest(
&discoveryv1.RegisterNamespaceRequest{
Name: n.Name,
Export: int32(e),
}))

return err
}
Expand All @@ -99,9 +101,9 @@ func (n namespaceUnRegister) Run(g *Globals, l *zap.SugaredLogger, c *kong.Conte
ctx, cancel := g.ctx()
defer cancel()

_, err = cli.UnregisterNamespace(ctx, &discoveryv1.UnregisterNamespaceRequest{
_, err = cli.UnregisterNamespace(ctx, connect.NewRequest(&discoveryv1.UnregisterNamespaceRequest{
Name: n.Name,
})
}))

return err
}
13 changes: 7 additions & 6 deletions internal/cmd/client/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"time"

"connectrpc.com/connect"
"github.com/alecthomas/kong"
"github.com/postfinance/discovery/internal/server/convert"
discoveryv1 "github.com/postfinance/discovery/pkg/discoverypb/postfinance/discovery/v1"
Expand Down Expand Up @@ -35,12 +36,12 @@ func (s serverList) Run(g *Globals, l *zap.SugaredLogger, c *kong.Context) error
ctx, cancel := g.ctx()
defer cancel()

r, err := cli.ListServer(ctx, &discoveryv1.ListServerRequest{})
r, err := cli.ListServer(ctx, connect.NewRequest(&discoveryv1.ListServerRequest{}))
if err != nil {
return err
}

servers := convert.ServersFromPB(r.GetServers())
servers := convert.ServersFromPB(r.Msg.GetServers())

sw := sfmt.SliceWriter{
Writer: os.Stdout,
Expand Down Expand Up @@ -69,10 +70,10 @@ func (s serverRegister) Run(g *Globals, l *zap.SugaredLogger, c *kong.Context) e
ctx, cancel := context.WithTimeout(context.Background(), registerTimout)
defer cancel()

_, err = cli.RegisterServer(ctx, &discoveryv1.RegisterServerRequest{
_, err = cli.RegisterServer(ctx, connect.NewRequest(&discoveryv1.RegisterServerRequest{
Name: s.Name,
Labels: s.Labels,
})
}))

return err
}
Expand All @@ -92,9 +93,9 @@ func (s serverUnRegister) Run(g *Globals, l *zap.SugaredLogger, c *kong.Context)
ctx, cancel := context.WithTimeout(context.Background(), registerTimout)
defer cancel()

_, err = cli.UnregisterServer(ctx, &discoveryv1.UnregisterServerRequest{
_, err = cli.UnregisterServer(ctx, connect.NewRequest(&discoveryv1.UnregisterServerRequest{
Name: s.Name,
})
}))

return err
}
Loading

0 comments on commit 0794bc0

Please sign in to comment.