Skip to content

Commit

Permalink
chore(spanner): grpc.WithInsecure is deprecated (googleapis#10098)
Browse files Browse the repository at this point in the history
grpc.WithTransportCredentials(insecure.NewCredentials) should be used instead.

Co-authored-by: rahul2393 <[email protected]>
  • Loading branch information
egonelbre and rahul2393 authored Aug 14, 2024
1 parent 6e23810 commit 2b2114f
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 10 deletions.
3 changes: 2 additions & 1 deletion spanner/admin/database/apiv1/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"google.golang.org/genproto/googleapis/spanner/admin/database/v1"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/metadata"
gstatus "google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"
Expand Down Expand Up @@ -121,7 +122,7 @@ func initMockOperations() {
}
go serv.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 {
log.Fatal(err)
}
Expand Down
3 changes: 2 additions & 1 deletion spanner/admin/database/apiv1/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ import (

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

func init() {
newDatabaseAdminClientHook = func(ctx context.Context, p clientHookParams) ([]option.ClientOption, error) {
if emulator := os.Getenv("SPANNER_EMULATOR_HOST"); emulator != "" {
return []option.ClientOption{
option.WithEndpoint(emulator),
option.WithGRPCDialOption(grpc.WithInsecure()),
option.WithGRPCDialOption(grpc.WithTransportCredentials(insecure.NewCredentials())),
option.WithoutAuthentication(),
}, nil
}
Expand Down
3 changes: 2 additions & 1 deletion spanner/admin/instance/apiv1/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ import (

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

func init() {
newInstanceAdminClientHook = func(ctx context.Context, p clientHookParams) ([]option.ClientOption, error) {
if emulator := os.Getenv("SPANNER_EMULATOR_HOST"); emulator != "" {
return []option.ClientOption{
option.WithEndpoint(emulator),
option.WithGRPCDialOption(grpc.WithInsecure()),
option.WithGRPCDialOption(grpc.WithTransportCredentials(insecure.NewCredentials())),
option.WithoutAuthentication(),
}, nil
}
Expand Down
2 changes: 1 addition & 1 deletion spanner/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ func newClientWithConfig(ctx context.Context, database string, config ClientConf
if emulatorAddr := os.Getenv("SPANNER_EMULATOR_HOST"); emulatorAddr != "" {
emulatorOpts := []option.ClientOption{
option.WithEndpoint(emulatorAddr),
option.WithGRPCDialOption(grpc.WithInsecure()),
option.WithGRPCDialOption(grpc.WithTransportCredentials(insecure.NewCredentials())),
option.WithoutAuthentication(),
internaloption.SkipDialSettingsValidation(),
}
Expand Down
3 changes: 2 additions & 1 deletion spanner/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import (
"google.golang.org/api/option/internaloption"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/peer"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"
Expand Down Expand Up @@ -893,7 +894,7 @@ func deleteTestSession(ctx context.Context, t *testing.T, sessionName string) {
if emulatorAddr := os.Getenv("SPANNER_EMULATOR_HOST"); emulatorAddr != "" {
emulatorOpts := []option.ClientOption{
option.WithEndpoint(emulatorAddr),
option.WithGRPCDialOption(grpc.WithInsecure()),
option.WithGRPCDialOption(grpc.WithTransportCredentials(insecure.NewCredentials())),
option.WithoutAuthentication(),
internaloption.SkipDialSettingsValidation(),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"cloud.google.com/go/spanner/internal/testutil"
"google.golang.org/api/option"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/protobuf/proto"
)

Expand All @@ -48,7 +49,7 @@ func setupInstanceAdminServer() {
}
go serv.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 {
log.Fatal(err)
}
Expand Down
3 changes: 2 additions & 1 deletion spanner/internal/testutil/inmem_spanner_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"google.golang.org/api/iterator"
"google.golang.org/api/option"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

gstatus "google.golang.org/grpc/status"
)
Expand Down Expand Up @@ -72,7 +73,7 @@ func TestMain(m *testing.M) {
go serv.Serve(lis)

serverAddress = lis.Addr().String()
conn, err := grpc.Dial(serverAddress, grpc.WithInsecure())
conn, err := grpc.Dial(serverAddress, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
log.Fatal(err)
}
Expand Down
3 changes: 2 additions & 1 deletion spanner/internal/testutil/mocked_inmem_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"cloud.google.com/go/spanner/apiv1/spannerpb"
"google.golang.org/api/option"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
structpb "google.golang.org/protobuf/types/known/structpb"
)

Expand Down Expand Up @@ -103,7 +104,7 @@ func (s *MockedSpannerInMemTestServer) setupMockedServerWithAddr(t *testing.T, a
s.ServerAddress = lis.Addr().String()
opts := []option.ClientOption{
option.WithEndpoint(s.ServerAddress),
option.WithGRPCDialOption(grpc.WithInsecure()),
option.WithGRPCDialOption(grpc.WithTransportCredentials(insecure.NewCredentials())),
option.WithoutAuthentication(),
}
return opts
Expand Down
2 changes: 1 addition & 1 deletion spanner/spannertest/inmem.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ create a Server, and then connect to it with no security:
srv, err := spannertest.NewServer("localhost:0")
...
conn, err := grpc.DialContext(ctx, srv.Addr, grpc.WithInsecure())
conn, err := grpc.DialContext(ctx, srv.Addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
...
client, err := spanner.NewClient(ctx, db, option.WithGRPCConn(conn))
...
Expand Down
2 changes: 1 addition & 1 deletion spanner/spannertest/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func makeClient(t *testing.T) (*spanner.Client, *dbadmin.DatabaseAdminClient, *v
srv.SetLogger(t.Logf)
dialCtx, cancel := context.WithTimeout(ctx, 1*time.Second)
defer cancel()
conn, err := grpc.DialContext(dialCtx, srv.Addr, grpc.WithInsecure())
conn, err := grpc.DialContext(dialCtx, srv.Addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
srv.Close()
t.Fatalf("Dialing in-memory fake: %v", err)
Expand Down

0 comments on commit 2b2114f

Please sign in to comment.