ALTS: Simplify "New" APIs (#1895)
ALTS NewClientALTS and NewServerALTS APIs are in the grpc/credentials/alts package. Having the term ALTS in the API names is redundant. This PR removes it.
This commit is contained in:
@ -100,13 +100,13 @@ type altsTC struct {
|
|||||||
accounts []string
|
accounts []string
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewClientALTS constructs a client-side ALTS TransportCredentials object.
|
// NewClient constructs a client-side ALTS TransportCredentials object.
|
||||||
func NewClientALTS(targetServiceAccounts []string) credentials.TransportCredentials {
|
func NewClient(targetServiceAccounts []string) credentials.TransportCredentials {
|
||||||
return newALTS(core.ClientSide, targetServiceAccounts)
|
return newALTS(core.ClientSide, targetServiceAccounts)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewServerALTS constructs a server-side ALTS TransportCredentials object.
|
// NewServer constructs a server-side ALTS TransportCredentials object.
|
||||||
func NewServerALTS() credentials.TransportCredentials {
|
func NewServer() credentials.TransportCredentials {
|
||||||
return newALTS(core.ServerSide, nil)
|
return newALTS(core.ServerSide, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -27,8 +27,8 @@ import (
|
|||||||
|
|
||||||
func TestInfoServerName(t *testing.T) {
|
func TestInfoServerName(t *testing.T) {
|
||||||
// This is not testing any handshaker functionality, so it's fine to only
|
// This is not testing any handshaker functionality, so it's fine to only
|
||||||
// use NewServerALTS and not NewClientALTS.
|
// use NewServer and not NewClient.
|
||||||
alts := NewServerALTS()
|
alts := NewServer()
|
||||||
if got, want := alts.Info().ServerName, ""; got != want {
|
if got, want := alts.Info().ServerName, ""; got != want {
|
||||||
t.Fatalf("%v.Info().ServerName = %v, want %v", alts, got, want)
|
t.Fatalf("%v.Info().ServerName = %v, want %v", alts, got, want)
|
||||||
}
|
}
|
||||||
@ -37,8 +37,8 @@ func TestInfoServerName(t *testing.T) {
|
|||||||
func TestOverrideServerName(t *testing.T) {
|
func TestOverrideServerName(t *testing.T) {
|
||||||
wantServerName := "server.name"
|
wantServerName := "server.name"
|
||||||
// This is not testing any handshaker functionality, so it's fine to only
|
// This is not testing any handshaker functionality, so it's fine to only
|
||||||
// use NewServerALTS and not NewClientALTS.
|
// use NewServer and not NewClient.
|
||||||
c := NewServerALTS()
|
c := NewServer()
|
||||||
c.OverrideServerName(wantServerName)
|
c.OverrideServerName(wantServerName)
|
||||||
if got, want := c.Info().ServerName, wantServerName; got != want {
|
if got, want := c.Info().ServerName, wantServerName; got != want {
|
||||||
t.Fatalf("c.Info().ServerName = %v, want %v", got, want)
|
t.Fatalf("c.Info().ServerName = %v, want %v", got, want)
|
||||||
@ -48,8 +48,8 @@ func TestOverrideServerName(t *testing.T) {
|
|||||||
func TestClone(t *testing.T) {
|
func TestClone(t *testing.T) {
|
||||||
wantServerName := "server.name"
|
wantServerName := "server.name"
|
||||||
// This is not testing any handshaker functionality, so it's fine to only
|
// This is not testing any handshaker functionality, so it's fine to only
|
||||||
// use NewServerALTS and not NewClientALTS.
|
// use NewServer and not NewClient.
|
||||||
c := NewServerALTS()
|
c := NewServer()
|
||||||
c.OverrideServerName(wantServerName)
|
c.OverrideServerName(wantServerName)
|
||||||
cc := c.Clone()
|
cc := c.Clone()
|
||||||
if got, want := cc.Info().ServerName, wantServerName; got != want {
|
if got, want := cc.Info().ServerName, wantServerName; got != want {
|
||||||
@ -66,8 +66,8 @@ func TestClone(t *testing.T) {
|
|||||||
|
|
||||||
func TestInfo(t *testing.T) {
|
func TestInfo(t *testing.T) {
|
||||||
// This is not testing any handshaker functionality, so it's fine to only
|
// This is not testing any handshaker functionality, so it's fine to only
|
||||||
// use NewServerALTS and not NewClientALTS.
|
// use NewServer and not NewClient.
|
||||||
c := NewServerALTS()
|
c := NewServer()
|
||||||
info := c.Info()
|
info := c.Info()
|
||||||
if got, want := info.ProtocolVersion, ""; got != want {
|
if got, want := info.ProtocolVersion, ""; got != want {
|
||||||
t.Errorf("info.ProtocolVersion=%v, want %v", got, want)
|
t.Errorf("info.ProtocolVersion=%v, want %v", got, want)
|
||||||
|
|||||||
@ -41,7 +41,7 @@ var (
|
|||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
altsTC := alts.NewClientALTS(nil)
|
altsTC := alts.NewClient(nil)
|
||||||
// Block until the server is ready.
|
// Block until the server is ready.
|
||||||
conn, err := grpc.Dial(*serverAddr, grpc.WithTransportCredentials(altsTC), grpc.WithBlock())
|
conn, err := grpc.Dial(*serverAddr, grpc.WithTransportCredentials(altsTC), grpc.WithBlock())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -41,7 +41,7 @@ func main() {
|
|||||||
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", *serverAddr, err)
|
||||||
}
|
}
|
||||||
altsTC := alts.NewServerALTS()
|
altsTC := alts.NewServer()
|
||||||
grpcServer := grpc.NewServer(grpc.Creds(altsTC))
|
grpcServer := grpc.NewServer(grpc.Creds(altsTC))
|
||||||
testpb.RegisterTestServiceServer(grpcServer, interop.NewTestServer())
|
testpb.RegisterTestServiceServer(grpcServer, interop.NewTestServer())
|
||||||
grpcServer.Serve(lis)
|
grpcServer.Serve(lis)
|
||||||
|
|||||||
Reference in New Issue
Block a user