config: multiple endpoints for authorize and databroker (#1957)

* wip

* update docs

* remove dead code
This commit is contained in:
Caleb Doxsey 2021-03-03 09:53:19 -07:00 committed by GitHub
parent 0f0a50be40
commit 664358dfad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 440 additions and 405 deletions

View file

@ -7,6 +7,7 @@ import (
"net"
"net/url"
"strconv"
"strings"
"sync"
"time"
@ -28,8 +29,8 @@ const (
// Options contains options for connecting to a pomerium rpc service.
type Options struct {
// Addr is the location of the service. e.g. "service.corp.example:8443"
Addr *url.URL
// Addrs is the location of the service. e.g. "service.corp.example:8443"
Addrs []*url.URL
// OverrideCertificateName overrides the server name used to verify the hostname on the
// returned certificates from the server. gRPC internals also use it to override the virtual
// hosting name if it is set.
@ -56,21 +57,25 @@ type Options struct {
// NewGRPCClientConn returns a new gRPC pomerium service client connection.
func NewGRPCClientConn(opts *Options) (*grpc.ClientConn, error) {
if opts.Addr == nil {
if len(opts.Addrs) == 0 {
return nil, errors.New("internal/grpc: connection address required")
}
connAddr := opts.Addr.Host
// no colon exists in the connection string, assume one must be added manually
if _, _, err := net.SplitHostPort(connAddr); err != nil {
if opts.Addr.Scheme == "https" {
connAddr = net.JoinHostPort(connAddr, strconv.Itoa(defaultGRPCSecurePort))
} else {
connAddr = net.JoinHostPort(connAddr, strconv.Itoa(defaultGRPCInsecurePort))
var addrs []string
for _, u := range opts.Addrs {
hostport := u.Host
// no colon exists in the connection string, assume one must be added manually
if _, _, err := net.SplitHostPort(hostport); err != nil {
if u.Scheme == "https" {
hostport = net.JoinHostPort(hostport, strconv.Itoa(defaultGRPCSecurePort))
} else {
hostport = net.JoinHostPort(hostport, strconv.Itoa(defaultGRPCInsecurePort))
}
}
addrs = append(addrs, hostport)
}
connAddr = "pomerium:///" + connAddr
connAddr := "pomerium:///" + strings.Join(addrs, ",")
clientStatsHandler := telemetry.NewGRPCClientStatsHandler(opts.ServiceName)