@@ -15,6 +15,7 @@ package client
1515
1616import (
1717 "context"
18+ "crypto/tls"
1819 "errors"
1920 "fmt"
2021 "io"
@@ -31,6 +32,7 @@ import (
3132 "github.com/dapr/go-sdk/version"
3233
3334 "google.golang.org/grpc"
35+ "google.golang.org/grpc/credentials"
3436 "google.golang.org/grpc/credentials/insecure"
3537 "google.golang.org/grpc/metadata"
3638 "google.golang.org/protobuf/types/known/emptypb"
@@ -44,6 +46,7 @@ import (
4446const (
4547 daprPortDefault = "50001"
4648 daprPortEnvVarName = "DAPR_GRPC_PORT" /* #nosec */
49+ daprGRPCEndpointEnvVarName = "DAPR_GRPC_ENDPOINT"
4750 traceparentKey = "traceparent"
4851 apiTokenKey = "dapr-api-token" /* #nosec */
4952 apiTokenEnvVarName = "DAPR_API_TOKEN" /* #nosec */
@@ -192,9 +195,6 @@ type Client interface {
192195 // UnregisterActorReminder unregisters an actor reminder.
193196 UnregisterActorReminder (ctx context.Context , req * UnregisterActorReminderRequest ) error
194197
195- // RenameActorReminder rename an actor reminder.
196- RenameActorReminder (ctx context.Context , req * RenameActorReminderRequest ) error
197-
198198 // InvokeActor calls a method on an actor.
199199 InvokeActor (ctx context.Context , req * InvokeActorRequest ) (* InvokeActorResponse , error )
200200
@@ -247,7 +247,13 @@ func NewClientWithPort(port string) (client Client, err error) {
247247 if port == "" {
248248 return nil , errors .New ("nil port" )
249249 }
250- return NewClientWithAddress (net .JoinHostPort ("127.0.0.1" , port ))
250+
251+ address := os .Getenv (daprGRPCEndpointEnvVarName )
252+ if address == "" {
253+ address = "127.0.0.1"
254+ }
255+
256+ return NewClientWithAddress (net .JoinHostPort (address , port ))
251257}
252258
253259// NewClientWithAddress instantiates Dapr using specific address (including port).
@@ -258,7 +264,7 @@ func NewClientWithAddress(address string) (client Client, err error) {
258264
259265// NewClientWithAddressContext instantiates Dapr using specific address (including port).
260266// Uses the provided context to create the connection.
261- func NewClientWithAddressContext (ctx context.Context , address string ) (client Client , err error ) {
267+ func NewClientWithAddressContext (ctx context.Context , address string , opts ... ClientOption ) (client Client , err error ) {
262268 if address == "" {
263269 return nil , errors .New ("empty address" )
264270 }
@@ -268,13 +274,26 @@ func NewClientWithAddressContext(ctx context.Context, address string) (client Cl
268274 if err != nil {
269275 return nil , err
270276 }
277+
278+ var option grpc.DialOption
279+
280+ cOpts := clientOptions {}
281+ for _ , opt := range opts {
282+ opt (& cOpts )
283+ }
284+
285+ if cOpts .useTLS || strings .Contains (address , "https://" ) {
286+ option = grpc .WithTransportCredentials (credentials .NewTLS (& tls.Config {}))
287+ } else {
288+ option = grpc .WithTransportCredentials (insecure .NewCredentials ())
289+ }
290+
271291 ctx , cancel := context .WithTimeout (ctx , time .Duration (timeoutSeconds )* time .Second )
272292 conn , err := grpc .DialContext (
273293 ctx ,
274294 address ,
275- grpc . WithTransportCredentials ( insecure . NewCredentials ()) ,
295+ option ,
276296 grpc .WithUserAgent (userAgent ()),
277- grpc .WithBlock (),
278297 )
279298 cancel ()
280299 if err != nil {
@@ -353,6 +372,19 @@ func (c *GRPCClient) WithAuthToken(token string) {
353372 c .authToken = token
354373}
355374
375+ type clientOptions struct {
376+ useTLS bool
377+ }
378+
379+ type ClientOption func (* clientOptions )
380+
381+ // WithTLS sets gRPC TLS transport credentials on the connection.
382+ func WithTLS () ClientOption {
383+ return func (co * clientOptions ) {
384+ co .useTLS = true
385+ }
386+ }
387+
356388// WithTraceID adds existing trace ID to the outgoing context.
357389func (c * GRPCClient ) WithTraceID (ctx context.Context , id string ) context.Context {
358390 if id == "" {
0 commit comments