Skip to content

Commit

Permalink
Rename TransportAuthenticator to TransportCredentials
Browse files Browse the repository at this point in the history
  • Loading branch information
menghanl committed Jun 8, 2016
1 parent 3ffbd8e commit 59486d9
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 24 deletions.
8 changes: 4 additions & 4 deletions clientconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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 {
Expand Down
18 changes: 9 additions & 9 deletions credentials/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
}

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/route_guide/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion interop/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ type Server struct {
}

type options struct {
auth credentials.TransportAuthenticator
creds credentials.TransportCredentials
codec Codec
cp Compressor
dc Decompressor
Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions transport/http2_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions transport/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 59486d9

Please sign in to comment.