From 59486d9c172d7b02e0166fce76fd720a88c24914 Mon Sep 17 00:00:00 2001 From: Menghan Li Date: Wed, 8 Jun 2016 11:10:23 -0700 Subject: [PATCH] Rename TransportAuthenticator to TransportCredentials --- clientconn.go | 8 ++++---- credentials/credentials.go | 18 +++++++++--------- examples/route_guide/client/client.go | 2 +- interop/client/client.go | 2 +- server.go | 10 +++++----- transport/http2_client.go | 4 ++-- transport/transport.go | 4 ++-- 7 files changed, 24 insertions(+), 24 deletions(-) diff --git a/clientconn.go b/clientconn.go index bf58dcd86987..41aad58a1eda 100644 --- a/clientconn.go +++ b/clientconn.go @@ -170,9 +170,9 @@ func WithInsecure() DialOption { // WithTransportCredentials returns a DialOption which configures a // connection level security credentials (e.g., TLS/SSL). -func WithTransportCredentials(auth credentials.TransportAuthenticator) DialOption { +func WithTransportCredentials(creds credentials.TransportCredentials) DialOption { return func(o *dialOptions) { - o.copts.Authenticator = auth + o.copts.TransportCredentials = creds } } @@ -369,11 +369,11 @@ func (cc *ClientConn) newAddrConn(addr Address, skipWait bool) error { ac.events = trace.NewEventLog("grpc.ClientConn", ac.addr.Addr) } if !ac.dopts.insecure { - if ac.dopts.copts.Authenticator == nil { + if ac.dopts.copts.TransportCredentials == nil { return errNoTransportSecurity } } else { - if ac.dopts.copts.Authenticator != nil { + if ac.dopts.copts.TransportCredentials != nil { return errCredentialsMisuse } for _, cd := range ac.dopts.copts.PerRPCCredentials { diff --git a/credentials/credentials.go b/credentials/credentials.go index c6a7f029b5d7..bd75f3302d06 100644 --- a/credentials/credentials.go +++ b/credentials/credentials.go @@ -87,9 +87,9 @@ type AuthInfo interface { AuthType() string } -// TransportAuthenticator defines the common interface for all the live gRPC wire +// TransportCredentials defines the common interface for all the live gRPC wire // protocols and supported transport security protocols (e.g., TLS, SSL). -type TransportAuthenticator interface { +type TransportCredentials interface { // ClientHandshake does the authentication handshake specified by the corresponding // authentication protocol on rawConn for clients. It returns the authenticated // connection and the corresponding auth information about the connection. @@ -98,7 +98,7 @@ type TransportAuthenticator interface { // the authenticated connection and the corresponding auth information about // the connection. ServerHandshake(rawConn net.Conn) (net.Conn, AuthInfo, error) - // Info provides the ProtocolInfo of this TransportAuthenticator. + // Info provides the ProtocolInfo of this TransportCredentials. Info() ProtocolInfo } @@ -185,20 +185,20 @@ func (c *tlsCreds) ServerHandshake(rawConn net.Conn) (net.Conn, AuthInfo, error) return conn, TLSInfo{conn.ConnectionState()}, nil } -// NewTLS uses c to construct a TransportAuthenticator based on TLS. -func NewTLS(c *tls.Config) TransportAuthenticator { +// NewTLS uses c to construct a TransportCredentials based on TLS. +func NewTLS(c *tls.Config) TransportCredentials { tc := &tlsCreds{*c} tc.config.NextProtos = alpnProtoStr return tc } // NewClientTLSFromCert constructs a TLS from the input certificate for client. -func NewClientTLSFromCert(cp *x509.CertPool, serverName string) TransportAuthenticator { +func NewClientTLSFromCert(cp *x509.CertPool, serverName string) TransportCredentials { return NewTLS(&tls.Config{ServerName: serverName, RootCAs: cp}) } // NewClientTLSFromFile constructs a TLS from the input certificate file for client. -func NewClientTLSFromFile(certFile, serverName string) (TransportAuthenticator, error) { +func NewClientTLSFromFile(certFile, serverName string) (TransportCredentials, error) { b, err := ioutil.ReadFile(certFile) if err != nil { return nil, err @@ -211,13 +211,13 @@ func NewClientTLSFromFile(certFile, serverName string) (TransportAuthenticator, } // NewServerTLSFromCert constructs a TLS from the input certificate for server. -func NewServerTLSFromCert(cert *tls.Certificate) TransportAuthenticator { +func NewServerTLSFromCert(cert *tls.Certificate) TransportCredentials { return NewTLS(&tls.Config{Certificates: []tls.Certificate{*cert}}) } // NewServerTLSFromFile constructs a TLS from the input certificate file and key // file for server. -func NewServerTLSFromFile(certFile, keyFile string) (TransportAuthenticator, error) { +func NewServerTLSFromFile(certFile, keyFile string) (TransportCredentials, error) { cert, err := tls.LoadX509KeyPair(certFile, keyFile) if err != nil { return nil, err diff --git a/examples/route_guide/client/client.go b/examples/route_guide/client/client.go index a96c0302cedd..f84352c81e37 100644 --- a/examples/route_guide/client/client.go +++ b/examples/route_guide/client/client.go @@ -164,7 +164,7 @@ func main() { if *serverHostOverride != "" { sn = *serverHostOverride } - var creds credentials.TransportAuthenticator + var creds credentials.TransportCredentials if *caFile != "" { var err error creds, err = credentials.NewClientTLSFromFile(*caFile, sn) diff --git a/interop/client/client.go b/interop/client/client.go index e05854c72372..98f6cfec3ae4 100644 --- a/interop/client/client.go +++ b/interop/client/client.go @@ -85,7 +85,7 @@ func main() { if *tlsServerName != "" { sn = *tlsServerName } - var creds credentials.TransportAuthenticator + var creds credentials.TransportCredentials if *testCA { var err error creds, err = credentials.NewClientTLSFromFile(testCAFile, sn) diff --git a/server.go b/server.go index 262f2e41b40e..38352ba30db3 100644 --- a/server.go +++ b/server.go @@ -95,7 +95,7 @@ type Server struct { } type options struct { - auth credentials.TransportAuthenticator + creds credentials.TransportCredentials codec Codec cp Compressor dc Decompressor @@ -138,9 +138,9 @@ func MaxConcurrentStreams(n uint32) ServerOption { } // Creds returns a ServerOption that sets credentials for server connections. -func Creds(c credentials.TransportAuthenticator) ServerOption { +func Creds(c credentials.TransportCredentials) ServerOption { return func(o *options) { - o.auth = c + o.creds = c } } @@ -249,10 +249,10 @@ var ( ) func (s *Server) useTransportAuthenticator(rawConn net.Conn) (net.Conn, credentials.AuthInfo, error) { - if s.opts.auth == nil { + if s.opts.creds == nil { return rawConn, nil, nil } - return s.opts.auth.ServerHandshake(rawConn) + return s.opts.creds.ServerHandshake(rawConn) } // Serve accepts incoming connections on the listener lis, creating a new diff --git a/transport/http2_client.go b/transport/http2_client.go index 7e4d4fd972c0..227686d46889 100644 --- a/transport/http2_client.go +++ b/transport/http2_client.go @@ -117,12 +117,12 @@ func newHTTP2Client(addr string, opts *ConnectOptions) (_ ClientTransport, err e return nil, ConnectionErrorf("transport: %v", connErr) } var authInfo credentials.AuthInfo - if opts.Authenticator != nil { + if opts.TransportCredentials != nil { scheme = "https" if timeout > 0 { timeout -= time.Since(startT) } - conn, authInfo, connErr = opts.Authenticator.ClientHandshake(addr, conn, timeout) + conn, authInfo, connErr = opts.TransportCredentials.ClientHandshake(addr, conn, timeout) } if connErr != nil { return nil, ConnectionErrorf("transport: %v", connErr) diff --git a/transport/transport.go b/transport/transport.go index 4dfd7ab59b93..d4c220a0c4ec 100644 --- a/transport/transport.go +++ b/transport/transport.go @@ -338,8 +338,8 @@ type ConnectOptions struct { Dialer func(string, time.Duration) (net.Conn, error) // PerRPCCredentials stores the PerRPCCredentials required to issue RPCs. PerRPCCredentials []credentials.PerRPCCredentials - // Authenticator stores the Authenticator required to setup a client connection. - Authenticator credentials.TransportAuthenticator + // TransportCredentials stores the Authenticator required to setup a client connection. + TransportCredentials credentials.TransportCredentials // Timeout specifies the timeout for dialing a ClientTransport. Timeout time.Duration }