Skip to content

Commit

Permalink
change interface/struct name
Browse files Browse the repository at this point in the history
  • Loading branch information
lyuxuan committed May 22, 2018
1 parent 7814b52 commit e8b54a4
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 34 deletions.
2 changes: 1 addition & 1 deletion channelz/service/func_nonunix.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ package service

import (
"google.golang.org/grpc/channelz"
channelzpb "google.golang.org/grpc/channelz/service_proto"
channelzpb "google.golang.org/grpc/channelz/grpc_channelz_v1"
)

func sockoptToProto(skopts *channelz.SocketOptionData) []*channelzpb.SocketOption {
Expand Down
6 changes: 3 additions & 3 deletions channelz/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,15 @@ func subChannelMetricToProto(cm *channelz.SubChannelMetric) *channelzpb.Subchann
return sc
}

func securityToProto(se credentials.SecurityValue) *channelzpb.Security {
func securityToProto(se credentials.ChannelzSecurityValue) *channelzpb.Security {
switch v := se.(type) {
case *credentials.TLSSecurityValue:
case *credentials.TLSChannelzSecurityValue:
return &channelzpb.Security{Model: &channelzpb.Security_Tls_{Tls: &channelzpb.Security_Tls{
CipherSuite: &channelzpb.Security_Tls_StandardName{StandardName: v.StandardName},
LocalCertificate: v.LocalCertificate,
RemoteCertificate: v.RemoteCertificate,
}}}
case *credentials.OtherSecurityValue:
case *credentials.OtherChannelzSecurityValue:
otherSecurity := &channelzpb.Security_OtherSecurity{
Name: v.Name,
}
Expand Down
16 changes: 8 additions & 8 deletions channelz/service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ type dummySocket struct {
SocketOptions *channelz.SocketOptionData
localAddr net.Addr
remoteAddr net.Addr
Security credentials.SecurityValue
Security credentials.ChannelzSecurityValue
remoteName string
}

Expand Down Expand Up @@ -196,12 +196,12 @@ func protoToTime(protoTime *channelzpb.SocketOptionTimeout) *unix.Timeval {
return timeout
}

func protoToSecurity(protoSecurity *channelzpb.Security) credentials.SecurityValue {
func protoToSecurity(protoSecurity *channelzpb.Security) credentials.ChannelzSecurityValue {
switch v := protoSecurity.Model.(type) {
case *channelzpb.Security_Tls_:
return &credentials.TLSSecurityValue{StandardName: v.Tls.GetStandardName(), LocalCertificate: v.Tls.GetLocalCertificate(), RemoteCertificate: v.Tls.GetRemoteCertificate()}
return &credentials.TLSChannelzSecurityValue{StandardName: v.Tls.GetStandardName(), LocalCertificate: v.Tls.GetLocalCertificate(), RemoteCertificate: v.Tls.GetRemoteCertificate()}
case *channelzpb.Security_Other:
sv := &credentials.OtherSecurityValue{Name: v.Other.GetName()}
sv := &credentials.OtherChannelzSecurityValue{Name: v.Other.GetName()}
var x ptypes.DynamicAny
if err := ptypes.UnmarshalAny(v.Other.GetValue(), &x); err == nil {
sv.Value = x.Message
Expand Down Expand Up @@ -356,7 +356,7 @@ func (*OtherSecurityValue) ProtoMessage() {}

func init() {
// Ad-hoc registering the proto type here to facilitate UnmarshalAny of OtherSecurityValue.
proto.RegisterType((*OtherSecurityValue)(nil), "grpc.credentials.OtherSecurityValue")
proto.RegisterType((*OtherSecurityValue)(nil), "grpc.credentials.OtherChannelzSecurityValue")
}

func TestGetTopChannels(t *testing.T) {
Expand Down Expand Up @@ -596,18 +596,18 @@ func TestGetSocket(t *testing.T) {
},
},
{
Security: &credentials.TLSSecurityValue{
Security: &credentials.TLSChannelzSecurityValue{
StandardName: "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256",
RemoteCertificate: []byte{48, 130, 2, 156, 48, 130, 2, 5, 160},
},
},
{
Security: &credentials.OtherSecurityValue{
Security: &credentials.OtherChannelzSecurityValue{
Name: "XXXX",
},
},
{
Security: &credentials.OtherSecurityValue{
Security: &credentials.OtherChannelzSecurityValue{
Name: "YYYY",
Value: &OtherSecurityValue{LocalCertificate: []byte{1, 2, 3}, RemoteCertificate: []byte{4, 5, 6}},
},
Expand Down
2 changes: 1 addition & 1 deletion channelz/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ type SocketInternalMetric struct {
// the original target name.
RemoteName string
SocketOptions *SocketOptionData
Security credentials.SecurityValue
Security credentials.ChannelzSecurityValue
}

// Socket is the interface that should be satisfied in order to be tracked by
Expand Down
40 changes: 21 additions & 19 deletions credentials/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ func (t TLSInfo) AuthType() string {
}

// GetSecurityValue returns security info requested by channelz.
func (t TLSInfo) GetSecurityValue() SecurityValue {
v := &TLSSecurityValue{
func (t TLSInfo) GetChannelzSecurityValue() ChannelzSecurityValue {
v := &TLSChannelzSecurityValue{
StandardName: cipherSuiteLookup[t.State.CipherSuite],
}
// Currently there's no way to get LocalCertificate info from tls package.
Expand Down Expand Up @@ -232,34 +232,36 @@ func NewServerTLSFromFile(certFile, keyFile string) (TransportCredentials, error
return NewTLS(&tls.Config{Certificates: []tls.Certificate{cert}}), nil
}

// ExtraSecurityInfo defines the interface that security protocols should implement in order
// to provide security info to channelz.
type ExtraSecurityInfo interface {
GetSecurityValue() SecurityValue
// ChannelzSecurityInfo defines the interface that security protocols should implement
// in order to provide security info to channelz.
type ChannelzSecurityInfo interface {
GetSecurityValue() ChannelzSecurityValue
}

// SecurityValue defines the interface that GetSecurityValue() return value should
// satisfy. This interface should only be satisfied by *TLSSecurityValue and
// *OtherSecurityValue.
type SecurityValue interface {
isSecurityValue()
// ChannelzSecurityValue defines the interface that GetSecurityValue() return value
// should satisfy. This interface should only be satisfied by *TLSChannelzSecurityValue
// and *OtherChannelzSecurityValue.
type ChannelzSecurityValue interface {
isChannelzSecurityValue()
}

// TLSSecurityValue defines the struct that TLS protocol should return from GetSecurityValue(),
// containing security info like cipher and certificate used.
type TLSSecurityValue struct {
// TLSChannelzSecurityValue defines the struct that TLS protocol should return
// from GetSecurityValue(), containing security info like cipher and certificate used.
type TLSChannelzSecurityValue struct {
StandardName string
LocalCertificate []byte
RemoteCertificate []byte
}

func (*TLSSecurityValue) isSecurityValue() {}
func (*TLSChannelzSecurityValue) isChannelzSecurityValue() {}

// OtherSecurityValue defines the struct that non-TLS protocol should return from
// GetSecurityValue(), which contains protocol specific security info.
type OtherSecurityValue struct {
// OtherChannelzSecurityValue defines the struct that non-TLS protocol should return
// from GetSecurityValue(), which contains protocol specific security info. Note
// the Value field will be sent to users of channelz requesting channel info, and
// thus sensitive info should better be avoided.
type OtherChannelzSecurityValue struct {
Name string
Value proto.Message
}

func (*OtherSecurityValue) isSecurityValue() {}
func (*OtherChannelzSecurityValue) isChannelzSecurityValue() {}
2 changes: 1 addition & 1 deletion transport/http2_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1254,7 +1254,7 @@ func (t *http2Client) ChannelzMetric() *channelz.SocketInternalMetric {
RemoteAddr: t.remoteAddr,
// RemoteName :
}
if au, ok := t.authInfo.(credentials.ExtraSecurityInfo); ok {
if au, ok := t.authInfo.(credentials.ChannelzSecurityInfo); ok {
s.Security = au.GetSecurityValue()
}
t.czmu.RUnlock()
Expand Down
2 changes: 1 addition & 1 deletion transport/http2_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,7 @@ func (t *http2Server) ChannelzMetric() *channelz.SocketInternalMetric {
RemoteAddr: t.remoteAddr,
// RemoteName :
}
if au, ok := t.authInfo.(credentials.ExtraSecurityInfo); ok {
if au, ok := t.authInfo.(credentials.ChannelzSecurityInfo); ok {
s.Security = au.GetSecurityValue()
}
t.czmu.RUnlock()
Expand Down

0 comments on commit e8b54a4

Please sign in to comment.