Skip to content

Commit

Permalink
Handle DialContext deprecation
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Harding <[email protected]>
  • Loading branch information
azdagron committed Jun 17, 2024
1 parent 5268516 commit 9b9b683
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion v2/examples/spiffe-grpc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ On the other side, the **gRPC client** uses the [workloadapi.X509Source](https:/
serverID := spiffeid.RequireFromString("spiffe://example.org/server")
tlsConfig := tlsconfig.MTLSClientConfig(source, source, tlsconfig.AuthorizeID(serverID))

conn, err := grpc.DialContext(ctx, "localhost:50051", grpc.WithTransportCredentials(credentials.NewTLS(tlsConfig)))
conn, err := grpc.NewClient("dns:///localhost:50051", grpc.WithTransportCredentials(credentials.NewTLS(tlsConfig)))
```

The [tlsconfig.Authorizer](https://pkg.go.dev/github.com/spiffe/go-spiffe/v2/spiffetls/tlsconfig?tab=doc#Authorizer) is used to authorize the mTLS peer. In this example, both the client and server use it to authorize the specific SPIFFE ID of the other side of the connection.
Expand Down
2 changes: 1 addition & 1 deletion v2/examples/spiffe-grpc/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func run(ctx context.Context) error {
serverID := spiffeid.RequireFromString("spiffe://example.org/server")

// Dial the server with credentials that do mTLS and verify that presented certificate has SPIFFE ID `spiffe://example.org/server`
conn, err := grpc.DialContext(ctx, "localhost:50051", grpc.WithTransportCredentials(
conn, err := grpc.NewClient("dns:///localhost:50051", grpc.WithTransportCredentials(
grpccredentials.MTLSClientCredentials(source, source, tlsconfig.AuthorizeID(serverID)),
))
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion v2/spiffegrpc/grpccredentials/credentials_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func testCredentials(t *testing.T, clientCreds, serverCreds credentials.Transpor
_ = server.Serve(listener)
}()

conn, err := grpc.DialContext(ctx, listener.Addr().String(), grpc.WithTransportCredentials(clientCreds))
conn, err := grpc.NewClient(listener.Addr().String(), grpc.WithTransportCredentials(clientCreds))
require.NoError(t, err)
defer conn.Close()

Expand Down
2 changes: 1 addition & 1 deletion v2/workloadapi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ func (c *Client) ValidateJWTSVID(ctx context.Context, token, audience string) (*
func (c *Client) newConn(ctx context.Context) (*grpc.ClientConn, error) {
c.config.dialOptions = append(c.config.dialOptions, grpc.WithTransportCredentials(insecure.NewCredentials()))
c.appendDialOptionsOS()
return grpc.DialContext(ctx, c.config.address, c.config.dialOptions...)
return grpc.DialContext(ctx, c.config.address, c.config.dialOptions...) //nolint:staticcheck // preserve backcompat with WithDialOptions option
}

func (c *Client) handleWatchError(ctx context.Context, err error, backoff *backoff) error {
Expand Down

0 comments on commit 9b9b683

Please sign in to comment.