Skip to content

Commit

Permalink
cleanup: replace grpc.WithInsecure with insecure.NewCredentials (#5177)
Browse files Browse the repository at this point in the history
  • Loading branch information
horizonzy committed Feb 9, 2022
1 parent 9196715 commit c44f627
Show file tree
Hide file tree
Showing 48 changed files with 112 additions and 70 deletions.
3 changes: 2 additions & 1 deletion admin/test/utils.go
Expand Up @@ -33,6 +33,7 @@ import (
"google.golang.org/grpc/admin"
channelzpb "google.golang.org/grpc/channelz/grpc_channelz_v1"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/internal/xds"
"google.golang.org/grpc/status"
)
Expand Down Expand Up @@ -78,7 +79,7 @@ func RunRegisterTests(t *testing.T, ec ExpectedStatusCodes) {
server.Serve(lis)
}()

conn, err := grpc.Dial(lis.Addr().String(), grpc.WithInsecure())
conn, err := grpc.Dial(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("cannot connect to server: %v", err)
}
Expand Down
11 changes: 6 additions & 5 deletions authz/sdk_end2end_test.go
Expand Up @@ -33,6 +33,7 @@ import (
"google.golang.org/grpc/authz"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/internal/grpctest"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"
Expand Down Expand Up @@ -324,7 +325,7 @@ func (s) TestSDKStaticPolicyEnd2End(t *testing.T) {
go s.Serve(lis)

// Establish a connection to the server.
clientConn, err := grpc.Dial(lis.Addr().String(), grpc.WithInsecure())
clientConn, err := grpc.Dial(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("grpc.Dial(%v) failed: %v", lis.Addr().String(), err)
}
Expand Down Expand Up @@ -514,7 +515,7 @@ func (s) TestSDKFileWatcherEnd2End(t *testing.T) {
go s.Serve(lis)

// Establish a connection to the server.
clientConn, err := grpc.Dial(lis.Addr().String(), grpc.WithInsecure())
clientConn, err := grpc.Dial(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("grpc.Dial(%v) failed: %v", lis.Addr().String(), err)
}
Expand Down Expand Up @@ -583,7 +584,7 @@ func (s) TestSDKFileWatcher_ValidPolicyRefresh(t *testing.T) {
go s.Serve(lis)

// Establish a connection to the server.
clientConn, err := grpc.Dial(lis.Addr().String(), grpc.WithInsecure())
clientConn, err := grpc.Dial(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("grpc.Dial(%v) failed: %v", lis.Addr().String(), err)
}
Expand Down Expand Up @@ -631,7 +632,7 @@ func (s) TestSDKFileWatcher_InvalidPolicySkipReload(t *testing.T) {
go s.Serve(lis)

// Establish a connection to the server.
clientConn, err := grpc.Dial(lis.Addr().String(), grpc.WithInsecure())
clientConn, err := grpc.Dial(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("grpc.Dial(%v) failed: %v", lis.Addr().String(), err)
}
Expand Down Expand Up @@ -682,7 +683,7 @@ func (s) TestSDKFileWatcher_RecoversFromReloadFailure(t *testing.T) {
go s.Serve(lis)

// Establish a connection to the server.
clientConn, err := grpc.Dial(lis.Addr().String(), grpc.WithInsecure())
clientConn, err := grpc.Dial(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("grpc.Dial(%v) failed: %v", lis.Addr().String(), err)
}
Expand Down
3 changes: 2 additions & 1 deletion balancer/grpclb/grpclb_remote_balancer.go
Expand Up @@ -33,6 +33,7 @@ import (
"google.golang.org/grpc/balancer"
lbpb "google.golang.org/grpc/balancer/grpclb/grpc_lb_v1"
"google.golang.org/grpc/connectivity"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/internal/backoff"
"google.golang.org/grpc/internal/channelz"
imetadata "google.golang.org/grpc/internal/metadata"
Expand Down Expand Up @@ -228,7 +229,7 @@ func (lb *lbBalancer) newRemoteBalancerCCWrapper() {
} else if bundle := lb.grpclbClientConnCreds; bundle != nil {
dopts = append(dopts, grpc.WithCredentialsBundle(bundle))
} else {
dopts = append(dopts, grpc.WithInsecure())
dopts = append(dopts, grpc.WithTransportCredentials(insecure.NewCredentials()))
}
if lb.opt.Dialer != nil {
dopts = append(dopts, grpc.WithContextDialer(lb.opt.Dialer))
Expand Down
3 changes: 2 additions & 1 deletion balancer/rls/control_channel.go
Expand Up @@ -27,6 +27,7 @@ import (
"google.golang.org/grpc/balancer"
"google.golang.org/grpc/balancer/rls/internal/adaptive"
"google.golang.org/grpc/connectivity"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/internal"
internalgrpclog "google.golang.org/grpc/internal/grpclog"
"google.golang.org/grpc/internal/pretty"
Expand Down Expand Up @@ -115,7 +116,7 @@ func (cc *controlChannel) dialOpts(bOpts balancer.BuildOptions, serviceConfig st
credsOpt = grpc.WithCredentialsBundle(bundle)
default:
cc.logger.Warningf("no credentials available, using Insecure")
credsOpt = grpc.WithInsecure()
credsOpt = grpc.WithTransportCredentials(insecure.NewCredentials())
}
dopts = append(dopts, credsOpt)

Expand Down
3 changes: 2 additions & 1 deletion benchmark/benchmain/main.go
Expand Up @@ -63,6 +63,7 @@ import (
"google.golang.org/grpc/benchmark/flags"
"google.golang.org/grpc/benchmark/latency"
"google.golang.org/grpc/benchmark/stats"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/grpclog"
"google.golang.org/grpc/internal/channelz"
"google.golang.org/grpc/keepalive"
Expand Down Expand Up @@ -305,7 +306,7 @@ func makeClient(bf stats.Features) (testgrpc.BenchmarkServiceClient, func()) {
)
}
sopts = append(sopts, grpc.MaxConcurrentStreams(uint32(bf.MaxConcurrentCalls+1)))
opts = append(opts, grpc.WithInsecure())
opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))

var lis net.Listener
if bf.UseBufConn {
Expand Down
3 changes: 2 additions & 1 deletion benchmark/client/main.go
Expand Up @@ -51,6 +51,7 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/benchmark"
"google.golang.org/grpc/benchmark/stats"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/grpclog"
"google.golang.org/grpc/internal/syscall"

Expand Down Expand Up @@ -135,7 +136,7 @@ func main() {
func buildConnections(ctx context.Context) []*grpc.ClientConn {
ccs := make([]*grpc.ClientConn, *numConn)
for i := range ccs {
ccs[i] = benchmark.NewClientConnWithContext(ctx, "localhost:"+*port, grpc.WithInsecure(), grpc.WithBlock())
ccs[i] = benchmark.NewClientConnWithContext(ctx, "localhost:"+*port, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock())
}
return ccs
}
Expand Down
3 changes: 2 additions & 1 deletion benchmark/worker/benchmark_client.go
Expand Up @@ -31,6 +31,7 @@ import (
"google.golang.org/grpc/benchmark/stats"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/internal/syscall"
"google.golang.org/grpc/status"
"google.golang.org/grpc/testdata"
Expand Down Expand Up @@ -135,7 +136,7 @@ func createConns(config *testpb.ClientConfig) ([]*grpc.ClientConn, func(), error
}
opts = append(opts, grpc.WithTransportCredentials(creds))
} else {
opts = append(opts, grpc.WithInsecure())
opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
}

// Use byteBufCodec if it is required.
Expand Down
3 changes: 2 additions & 1 deletion binarylog/binarylog_end2end_test.go
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/golang/protobuf/proto"
"google.golang.org/grpc"
"google.golang.org/grpc/binarylog"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/grpclog"
iblog "google.golang.org/grpc/internal/binarylog"
"google.golang.org/grpc/internal/grpctest"
Expand Down Expand Up @@ -310,7 +311,7 @@ func (te *test) clientConn() *grpc.ClientConn {
if te.cc != nil {
return te.cc
}
opts := []grpc.DialOption{grpc.WithInsecure(), grpc.WithBlock()}
opts := []grpc.DialOption{grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock()}

var err error
te.cc, err = grpc.Dial(te.srvAddr, opts...)
Expand Down
2 changes: 1 addition & 1 deletion clientconn.go
Expand Up @@ -79,7 +79,7 @@ var (
// errNoTransportSecurity indicates that there is no transport security
// being set for ClientConn. Users should either set one or explicitly
// call WithInsecure DialOption to disable security.
errNoTransportSecurity = errors.New("grpc: no transport security set (use grpc.WithInsecure() explicitly or set credentials)")
errNoTransportSecurity = errors.New("grpc: no transport security set (use grpc.WithTransportCredentials(insecure.NewCredentials()) explicitly or set credentials)")
// errTransportCredsAndBundle indicates that creds bundle is used together
// with other individual Transport Credentials.
errTransportCredsAndBundle = errors.New("grpc: credentials.Bundle may not be used with individual TransportCredentials")
Expand Down
3 changes: 2 additions & 1 deletion credentials/alts/internal/handshaker/service/service.go
Expand Up @@ -24,6 +24,7 @@ import (
"sync"

grpc "google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)

var (
Expand All @@ -49,7 +50,7 @@ func Dial(hsAddress string) (*grpc.ClientConn, error) {
// Create a new connection to the handshaker service. Note that
// this connection stays open until the application is closed.
var err error
hsConn, err = hsDialer(hsAddress, grpc.WithInsecure())
hsConn, err = hsDialer(hsAddress, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
return nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion examples/features/cancellation/client/main.go
Expand Up @@ -28,6 +28,7 @@ import (

"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials/insecure"
pb "google.golang.org/grpc/examples/features/proto/echo"
"google.golang.org/grpc/status"
)
Expand Down Expand Up @@ -55,7 +56,7 @@ func main() {
flag.Parse()

// Set up a connection to the server.
conn, err := grpc.Dial(*addr, grpc.WithInsecure())
conn, err := grpc.Dial(*addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
log.Fatalf("did not connect: %v", err)
}
Expand Down
3 changes: 2 additions & 1 deletion examples/features/compression/client/main.go
Expand Up @@ -27,6 +27,7 @@ import (
"time"

"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/encoding/gzip" // Install the gzip compressor
pb "google.golang.org/grpc/examples/features/proto/echo"
)
Expand All @@ -37,7 +38,7 @@ func main() {
flag.Parse()

// Set up a connection to the server.
conn, err := grpc.Dial(*addr, grpc.WithInsecure())
conn, err := grpc.Dial(*addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
log.Fatalf("did not connect: %v", err)
}
Expand Down
3 changes: 2 additions & 1 deletion examples/features/deadline/client/main.go
Expand Up @@ -28,6 +28,7 @@ import (

"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials/insecure"
pb "google.golang.org/grpc/examples/features/proto/echo"
"google.golang.org/grpc/status"
)
Expand Down Expand Up @@ -72,7 +73,7 @@ func streamingCall(c pb.EchoClient, requestID int, message string, want codes.Co
func main() {
flag.Parse()

conn, err := grpc.Dial(*addr, grpc.WithInsecure())
conn, err := grpc.Dial(*addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
log.Fatalf("did not connect: %v", err)
}
Expand Down
3 changes: 2 additions & 1 deletion examples/features/deadline/server/main.go
Expand Up @@ -31,6 +31,7 @@ import (

"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/status"

pb "google.golang.org/grpc/examples/features/proto/echo"
Expand Down Expand Up @@ -94,7 +95,7 @@ func (s *server) Close() {

func newEchoServer() *server {
target := fmt.Sprintf("localhost:%v", *port)
cc, err := grpc.Dial(target, grpc.WithInsecure())
cc, err := grpc.Dial(target, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
log.Fatalf("did not connect: %v", err)
}
Expand Down
3 changes: 2 additions & 1 deletion examples/features/debugging/client/main.go
Expand Up @@ -28,6 +28,7 @@ import (

"google.golang.org/grpc"
"google.golang.org/grpc/channelz/service"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/resolver"
"google.golang.org/grpc/resolver/manual"

Expand Down Expand Up @@ -59,7 +60,7 @@ func main() {
/***** Initialize manual resolver and Dial *****/
r := manual.NewBuilderWithScheme("whatever")
// Set up a connection to the server.
conn, err := grpc.Dial(r.Scheme()+":///test.server", grpc.WithInsecure(), grpc.WithResolvers(r), grpc.WithDefaultServiceConfig(`{"loadBalancingPolicy":"round_robin"}`))
conn, err := grpc.Dial(r.Scheme()+":///test.server", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(r), grpc.WithDefaultServiceConfig(`{"loadBalancingPolicy":"round_robin"}`))
if err != nil {
log.Fatalf("did not connect: %v", err)
}
Expand Down
3 changes: 2 additions & 1 deletion examples/features/errors/client/main.go
Expand Up @@ -28,6 +28,7 @@ import (

epb "google.golang.org/genproto/googleapis/rpc/errdetails"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
pb "google.golang.org/grpc/examples/helloworld/helloworld"
"google.golang.org/grpc/status"
)
Expand All @@ -38,7 +39,7 @@ func main() {
flag.Parse()

// Set up a connection to the server.
conn, err := grpc.Dial(*addr, grpc.WithInsecure())
conn, err := grpc.Dial(*addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
log.Fatalf("did not connect: %v", err)
}
Expand Down
3 changes: 2 additions & 1 deletion examples/features/health/client/main.go
Expand Up @@ -27,6 +27,7 @@ import (
"time"

"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
pb "google.golang.org/grpc/examples/features/proto/echo"
_ "google.golang.org/grpc/health"
"google.golang.org/grpc/resolver"
Expand Down Expand Up @@ -65,7 +66,7 @@ func main() {
address := fmt.Sprintf("%s:///unused", r.Scheme())

options := []grpc.DialOption{
grpc.WithInsecure(),
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithBlock(),
grpc.WithResolvers(r),
grpc.WithDefaultServiceConfig(serviceConfig),
Expand Down
3 changes: 2 additions & 1 deletion examples/features/keepalive/client/main.go
Expand Up @@ -27,6 +27,7 @@ import (
"time"

"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
pb "google.golang.org/grpc/examples/features/proto/echo"
"google.golang.org/grpc/keepalive"
)
Expand All @@ -42,7 +43,7 @@ var kacp = keepalive.ClientParameters{
func main() {
flag.Parse()

conn, err := grpc.Dial(*addr, grpc.WithInsecure(), grpc.WithKeepaliveParams(kacp))
conn, err := grpc.Dial(*addr, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithKeepaliveParams(kacp))
if err != nil {
log.Fatalf("did not connect: %v", err)
}
Expand Down
5 changes: 3 additions & 2 deletions examples/features/load_balancing/client/main.go
Expand Up @@ -26,6 +26,7 @@ import (
"time"

"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
ecpb "google.golang.org/grpc/examples/features/proto/echo"
"google.golang.org/grpc/resolver"
)
Expand Down Expand Up @@ -58,7 +59,7 @@ func main() {
// "pick_first" is the default, so there's no need to set the load balancing policy.
pickfirstConn, err := grpc.Dial(
fmt.Sprintf("%s:///%s", exampleScheme, exampleServiceName),
grpc.WithInsecure(),
grpc.WithTransportCredentials(insecure.NewCredentials()),
)
if err != nil {
log.Fatalf("did not connect: %v", err)
Expand All @@ -74,7 +75,7 @@ func main() {
roundrobinConn, err := grpc.Dial(
fmt.Sprintf("%s:///%s", exampleScheme, exampleServiceName),
grpc.WithDefaultServiceConfig(`{"loadBalancingConfig": [{"round_robin":{}}]}`), // This sets the initial balancing policy.
grpc.WithInsecure(),
grpc.WithTransportCredentials(insecure.NewCredentials()),
)
if err != nil {
log.Fatalf("did not connect: %v", err)
Expand Down
3 changes: 2 additions & 1 deletion examples/features/metadata/client/main.go
Expand Up @@ -28,6 +28,7 @@ import (
"time"

"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
pb "google.golang.org/grpc/examples/features/proto/echo"
"google.golang.org/grpc/metadata"
)
Expand Down Expand Up @@ -286,7 +287,7 @@ const message = "this is examples/metadata"
func main() {
flag.Parse()
// Set up a connection to the server.
conn, err := grpc.Dial(*addr, grpc.WithInsecure())
conn, err := grpc.Dial(*addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
log.Fatalf("did not connect: %v", err)
}
Expand Down
3 changes: 2 additions & 1 deletion examples/features/multiplex/client/main.go
Expand Up @@ -27,6 +27,7 @@ import (
"time"

"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
ecpb "google.golang.org/grpc/examples/features/proto/echo"
hwpb "google.golang.org/grpc/examples/helloworld/helloworld"
)
Expand Down Expand Up @@ -58,7 +59,7 @@ func callUnaryEcho(client ecpb.EchoClient, message string) {
func main() {
flag.Parse()
// Set up a connection to the server.
conn, err := grpc.Dial(*addr, grpc.WithInsecure())
conn, err := grpc.Dial(*addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
log.Fatalf("did not connect: %v", err)
}
Expand Down

0 comments on commit c44f627

Please sign in to comment.