Skip to content

Commit

Permalink
fix review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
menghanl committed Sep 20, 2018
1 parent f8a6a2d commit b63d244
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion balancer/grpclb/grpclb_remote_balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func (lb *lbBalancer) dialRemoteLB(remoteLBName string) {
dopts = append(dopts, grpc.WithInsecure())
}
} else if bundle := lb.grpclbClientConnCreds; bundle != nil {
dopts = append(dopts, grpc.WithCreds(bundle))
dopts = append(dopts, grpc.WithCredentialsBundle(bundle))
} else {
dopts = append(dopts, grpc.WithInsecure())
}
Expand Down
6 changes: 4 additions & 2 deletions credentials/google/google.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,13 @@ func (c *creds) SwitchMode(mode string) (credentials.Bundle, error) {
newCreds.transportCreds = credentials.NewTLS(nil)
case internal.CredsBundleModeALTS, internal.CredsBundleModeGRPCLB:
if !vmOnGCP {
return nil, errors.New("ALTS, as part of google default credentials, is only supported on GCP")
return nil, errors.New("google default creds: ALTS, as part of google default credentials, is only supported on GCP")
}
// Only the clients can use google default credentials, so we only need
// to create new ALTS client creds here.
newCreds.transportCreds = alts.NewClientCreds(alts.DefaultClientOptions())
default:
return nil, fmt.Errorf("unsupported mode: %v", mode)
return nil, fmt.Errorf("google default creds: unsupported mode: %v", mode)
}

// Create per RPC credentials.
Expand Down
6 changes: 3 additions & 3 deletions dialoptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,12 @@ func WithPerRPCCredentials(creds credentials.PerRPCCredentials) DialOption {
})
}

// WithCreds returns a DialOption to set a credentials bundle for the
// ClientConn.WithCreds. This should not be used together with
// WithCredentialsBundle returns a DialOption to set a credentials bundle for
// the ClientConn.WithCreds. This should not be used together with
// WithTransportCredentials.
//
// This API is experimental.
func WithCreds(b credentials.Bundle) DialOption {
func WithCredentialsBundle(b credentials.Bundle) DialOption {
return newFuncDialOption(func(o *dialOptions) {
o.copts.CredsBundle = b
})
Expand Down
12 changes: 6 additions & 6 deletions internal/transport/http2_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,21 +166,21 @@ func newHTTP2Client(connectCtx, ctx context.Context, addr TargetInfo, opts Conne
isSecure bool
authInfo credentials.AuthInfo
)
var creds credentials.TransportCredentials
var transportCreds credentials.TransportCredentials
perRPCCreds := opts.PerRPCCredentials

if b := opts.CredsBundle; b != nil {
creds = b.TransportCredentials()
transportCreds = b.TransportCredentials()
if t := b.PerRPCCredentials(); t != nil {
perRPCCreds = append(perRPCCreds, t)
}
}
if creds == nil {
creds = opts.TransportCredentials
if transportCreds == nil {
transportCreds = opts.TransportCredentials
}
if creds != nil {
if transportCreds != nil {
scheme = "https"
conn, authInfo, err = creds.ClientHandshake(connectCtx, addr.Authority, conn)
conn, authInfo, err = transportCreds.ClientHandshake(connectCtx, addr.Authority, conn)
if err != nil {
return nil, connectionErrorf(isTemporary(err), err, "transport: authentication handshake failed: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion interop/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func main() {
altsTC := alts.NewClientCreds(altsOpts)
opts = append(opts, grpc.WithTransportCredentials(altsTC))
} else if *useGoogleDefaultCreds {
opts = append(opts, grpc.WithCreds(google.NewDefaultCredentials()))
opts = append(opts, grpc.WithCredentialsBundle(google.NewDefaultCredentials()))
} else {
opts = append(opts, grpc.WithInsecure())
}
Expand Down
6 changes: 3 additions & 3 deletions test/creds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func TestCredsBundleBoth(t *testing.T) {
te := newTest(t, env{name: "creds-bundle", network: "tcp", balancer: "v1", security: "empty"})
te.tapHandle = authHandle
te.customDialOptions = []grpc.DialOption{
grpc.WithCreds(&testCredsBundle{t: t}),
grpc.WithCredentialsBundle(&testCredsBundle{t: t}),
}
creds, err := credentials.NewServerTLSFromFile(testdata.Path("server1.pem"), testdata.Path("server1.key"))
if err != nil {
Expand All @@ -93,7 +93,7 @@ func TestCredsBundleTransportCredentials(t *testing.T) {
defer leakcheck.Check(t)
te := newTest(t, env{name: "creds-bundle", network: "tcp", balancer: "v1", security: "empty"})
te.customDialOptions = []grpc.DialOption{
grpc.WithCreds(&testCredsBundle{t: t, mode: bundleTLSOnly}),
grpc.WithCredentialsBundle(&testCredsBundle{t: t, mode: bundleTLSOnly}),
}
creds, err := credentials.NewServerTLSFromFile(testdata.Path("server1.pem"), testdata.Path("server1.key"))
if err != nil {
Expand All @@ -117,7 +117,7 @@ func TestCredsBundlePerRPCCredentials(t *testing.T) {
te := newTest(t, env{name: "creds-bundle", network: "tcp", balancer: "v1", security: "empty"})
te.tapHandle = authHandle
te.customDialOptions = []grpc.DialOption{
grpc.WithCreds(&testCredsBundle{t: t, mode: bundlePerRPCOnly}),
grpc.WithCredentialsBundle(&testCredsBundle{t: t, mode: bundlePerRPCOnly}),
}
te.startServer(&testServer{})
defer te.tearDown()
Expand Down

0 comments on commit b63d244

Please sign in to comment.