Replace the service bearer tokens with [tls] ca_file and cert_dir. Caller identity comes from the verified certificate, not metadata. Without TLS, services listen and dial on loopback only. Task containers get only the CA and keep their grant.
35 lines
1007 B
Go
35 lines
1007 B
Go
package gatewayrpc
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
"github.com/samcharles93/archie-core/internal/domain/presence"
|
|
"github.com/samcharles93/archie-core/internal/infrastructure/rpctls"
|
|
)
|
|
|
|
// Dial returns a Gateway chat client for target, authenticated by id. The
|
|
// cleanup closes the connection.
|
|
func Dial(target string, id *rpctls.Identity, options ...grpc.DialOption) (*Client, func(), error) {
|
|
target = strings.TrimSpace(target)
|
|
if target == "" {
|
|
return nil, nil, fmt.Errorf("gateway target is required")
|
|
}
|
|
creds, err := id.DialOption(target, presence.Gateway)
|
|
if err != nil {
|
|
return nil, nil, fmt.Errorf("gateway: %w", err)
|
|
}
|
|
opts := []grpc.DialOption{
|
|
creds,
|
|
grpc.WithUnaryInterceptor(unaryPrincipal),
|
|
grpc.WithStreamInterceptor(streamPrincipal),
|
|
}
|
|
conn, err := grpc.NewClient(target, append(opts, options...)...)
|
|
if err != nil {
|
|
return nil, nil, fmt.Errorf("create gateway client: %w", err)
|
|
}
|
|
return NewClient(conn), func() { _ = conn.Close() }, nil
|
|
}
|