credentials/alts: Support UDS addresses in ALTS interop test server (#2763)
* Support UDS addresses in ALTS interop test server * Fix flag description * Fixed comment * Fix comment
This commit is contained in:
@ -22,6 +22,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"net"
|
"net"
|
||||||
|
"strings"
|
||||||
|
|
||||||
grpc "google.golang.org/grpc"
|
grpc "google.golang.org/grpc"
|
||||||
"google.golang.org/grpc/credentials/alts"
|
"google.golang.org/grpc/credentials/alts"
|
||||||
@ -30,17 +31,28 @@ import (
|
|||||||
testpb "google.golang.org/grpc/interop/grpc_testing"
|
testpb "google.golang.org/grpc/interop/grpc_testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
udsAddrPrefix = "unix:"
|
||||||
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
hsAddr = flag.String("alts_handshaker_service_address", "", "ALTS handshaker gRPC service address")
|
hsAddr = flag.String("alts_handshaker_service_address", "", "ALTS handshaker gRPC service address")
|
||||||
serverAddr = flag.String("server_address", ":8080", "The port on which the server is listening")
|
serverAddr = flag.String("server_address", ":8080", "The address on which the server is listening. Only two types of addresses are supported, 'host:port' and 'unix:/path'.")
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
lis, err := net.Listen("tcp", *serverAddr)
|
// If the server address starts with `unix:`, then we have a UDS address.
|
||||||
|
network := "tcp"
|
||||||
|
address := *serverAddr
|
||||||
|
if strings.HasPrefix(address, udsAddrPrefix) {
|
||||||
|
network = "unix"
|
||||||
|
address = strings.TrimPrefix(address, udsAddrPrefix)
|
||||||
|
}
|
||||||
|
lis, err := net.Listen(network, address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
grpclog.Fatalf("gRPC Server: failed to start the server at %v: %v", *serverAddr, err)
|
grpclog.Fatalf("gRPC Server: failed to start the server at %v: %v", address, err)
|
||||||
}
|
}
|
||||||
opts := alts.DefaultServerOptions()
|
opts := alts.DefaultServerOptions()
|
||||||
if *hsAddr != "" {
|
if *hsAddr != "" {
|
||||||
|
Reference in New Issue
Block a user