Rename TransportAuthenticator to TransportCredentials

This commit is contained in:
Menghan Li
2016-06-08 11:10:23 -07:00
parent 3ffbd8e030
commit 59486d9c17
7 changed files with 24 additions and 24 deletions

View File

@ -170,9 +170,9 @@ func WithInsecure() DialOption {
// WithTransportCredentials returns a DialOption which configures a // WithTransportCredentials returns a DialOption which configures a
// connection level security credentials (e.g., TLS/SSL). // connection level security credentials (e.g., TLS/SSL).
func WithTransportCredentials(auth credentials.TransportAuthenticator) DialOption { func WithTransportCredentials(creds credentials.TransportCredentials) DialOption {
return func(o *dialOptions) { 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) ac.events = trace.NewEventLog("grpc.ClientConn", ac.addr.Addr)
} }
if !ac.dopts.insecure { if !ac.dopts.insecure {
if ac.dopts.copts.Authenticator == nil { if ac.dopts.copts.TransportCredentials == nil {
return errNoTransportSecurity return errNoTransportSecurity
} }
} else { } else {
if ac.dopts.copts.Authenticator != nil { if ac.dopts.copts.TransportCredentials != nil {
return errCredentialsMisuse return errCredentialsMisuse
} }
for _, cd := range ac.dopts.copts.PerRPCCredentials { for _, cd := range ac.dopts.copts.PerRPCCredentials {

View File

@ -87,9 +87,9 @@ type AuthInfo interface {
AuthType() string 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). // 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 // ClientHandshake does the authentication handshake specified by the corresponding
// authentication protocol on rawConn for clients. It returns the authenticated // authentication protocol on rawConn for clients. It returns the authenticated
// connection and the corresponding auth information about the connection. // 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 authenticated connection and the corresponding auth information about
// the connection. // the connection.
ServerHandshake(rawConn net.Conn) (net.Conn, AuthInfo, error) ServerHandshake(rawConn net.Conn) (net.Conn, AuthInfo, error)
// Info provides the ProtocolInfo of this TransportAuthenticator. // Info provides the ProtocolInfo of this TransportCredentials.
Info() ProtocolInfo Info() ProtocolInfo
} }
@ -185,20 +185,20 @@ func (c *tlsCreds) ServerHandshake(rawConn net.Conn) (net.Conn, AuthInfo, error)
return conn, TLSInfo{conn.ConnectionState()}, nil return conn, TLSInfo{conn.ConnectionState()}, nil
} }
// NewTLS uses c to construct a TransportAuthenticator based on TLS. // NewTLS uses c to construct a TransportCredentials based on TLS.
func NewTLS(c *tls.Config) TransportAuthenticator { func NewTLS(c *tls.Config) TransportCredentials {
tc := &tlsCreds{*c} tc := &tlsCreds{*c}
tc.config.NextProtos = alpnProtoStr tc.config.NextProtos = alpnProtoStr
return tc return tc
} }
// NewClientTLSFromCert constructs a TLS from the input certificate for client. // 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}) return NewTLS(&tls.Config{ServerName: serverName, RootCAs: cp})
} }
// NewClientTLSFromFile constructs a TLS from the input certificate file for client. // 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) b, err := ioutil.ReadFile(certFile)
if err != nil { if err != nil {
return nil, err return nil, err
@ -211,13 +211,13 @@ func NewClientTLSFromFile(certFile, serverName string) (TransportAuthenticator,
} }
// NewServerTLSFromCert constructs a TLS from the input certificate for server. // 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}}) return NewTLS(&tls.Config{Certificates: []tls.Certificate{*cert}})
} }
// NewServerTLSFromFile constructs a TLS from the input certificate file and key // NewServerTLSFromFile constructs a TLS from the input certificate file and key
// file for server. // file for server.
func NewServerTLSFromFile(certFile, keyFile string) (TransportAuthenticator, error) { func NewServerTLSFromFile(certFile, keyFile string) (TransportCredentials, error) {
cert, err := tls.LoadX509KeyPair(certFile, keyFile) cert, err := tls.LoadX509KeyPair(certFile, keyFile)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -164,7 +164,7 @@ func main() {
if *serverHostOverride != "" { if *serverHostOverride != "" {
sn = *serverHostOverride sn = *serverHostOverride
} }
var creds credentials.TransportAuthenticator var creds credentials.TransportCredentials
if *caFile != "" { if *caFile != "" {
var err error var err error
creds, err = credentials.NewClientTLSFromFile(*caFile, sn) creds, err = credentials.NewClientTLSFromFile(*caFile, sn)

View File

@ -85,7 +85,7 @@ func main() {
if *tlsServerName != "" { if *tlsServerName != "" {
sn = *tlsServerName sn = *tlsServerName
} }
var creds credentials.TransportAuthenticator var creds credentials.TransportCredentials
if *testCA { if *testCA {
var err error var err error
creds, err = credentials.NewClientTLSFromFile(testCAFile, sn) creds, err = credentials.NewClientTLSFromFile(testCAFile, sn)

View File

@ -95,7 +95,7 @@ type Server struct {
} }
type options struct { type options struct {
auth credentials.TransportAuthenticator creds credentials.TransportCredentials
codec Codec codec Codec
cp Compressor cp Compressor
dc Decompressor dc Decompressor
@ -138,9 +138,9 @@ func MaxConcurrentStreams(n uint32) ServerOption {
} }
// Creds returns a ServerOption that sets credentials for server connections. // 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) { 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) { 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 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 // Serve accepts incoming connections on the listener lis, creating a new

View File

@ -117,12 +117,12 @@ func newHTTP2Client(addr string, opts *ConnectOptions) (_ ClientTransport, err e
return nil, ConnectionErrorf("transport: %v", connErr) return nil, ConnectionErrorf("transport: %v", connErr)
} }
var authInfo credentials.AuthInfo var authInfo credentials.AuthInfo
if opts.Authenticator != nil { if opts.TransportCredentials != nil {
scheme = "https" scheme = "https"
if timeout > 0 { if timeout > 0 {
timeout -= time.Since(startT) 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 { if connErr != nil {
return nil, ConnectionErrorf("transport: %v", connErr) return nil, ConnectionErrorf("transport: %v", connErr)

View File

@ -338,8 +338,8 @@ type ConnectOptions struct {
Dialer func(string, time.Duration) (net.Conn, error) Dialer func(string, time.Duration) (net.Conn, error)
// PerRPCCredentials stores the PerRPCCredentials required to issue RPCs. // PerRPCCredentials stores the PerRPCCredentials required to issue RPCs.
PerRPCCredentials []credentials.PerRPCCredentials PerRPCCredentials []credentials.PerRPCCredentials
// Authenticator stores the Authenticator required to setup a client connection. // TransportCredentials stores the Authenticator required to setup a client connection.
Authenticator credentials.TransportAuthenticator TransportCredentials credentials.TransportCredentials
// Timeout specifies the timeout for dialing a ClientTransport. // Timeout specifies the timeout for dialing a ClientTransport.
Timeout time.Duration Timeout time.Duration
} }