Skip to content

Commit 323050d

Browse files
committed
feat(sdk/go): add gateway client options for logger, timeout, and retry
Add WithLogger, WithTimeout, and WithRetryPolicy options to the gateway package's NewClient function. These forward the corresponding Config fields (Logger, Timeout, RetryPolicy) through to the underlying SDK client, giving callers full control over observability, connection timeouts, and retry behavior when constructing clients from on-disk gateway configurations. Also adds RetryPolicy type to types package and extends Config with the three new fields.
1 parent 7a38659 commit 323050d

4 files changed

Lines changed: 55 additions & 8 deletions

File tree

‎sdk/go/openshell/v1/gateway/gateway.go‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ func NewClient(name string, opts ...ClientOption) (*v1.Client, error) {
5353
sdkCfg.TLS = &types.TLSConfig{Insecure: true}
5454
}
5555

56+
if cc.timeout > 0 {
57+
sdkCfg.Timeout = cc.timeout
58+
}
59+
if cc.retryPolicy != nil {
60+
sdkCfg.RetryPolicy = cc.retryPolicy
61+
}
62+
if cc.logger != nil {
63+
sdkCfg.Logger = cc.logger
64+
}
65+
5666
return v1.NewClient(sdkCfg)
5767
}
5868

‎sdk/go/openshell/v1/gateway/options.go‎

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,40 @@
44
package gateway
55

66
import (
7+
"time"
8+
79
"github.com/NVIDIA/OpenShell/sdk/go/openshell/v1/types"
810
)
911

1012
// clientConfig holds resolved options applied after gateway config
1113
// resolution but before the v1.Client is created.
1214
type clientConfig struct {
13-
tls *types.TLSConfig
14-
auth types.AuthProvider
15+
logger types.Logger
16+
timeout time.Duration
17+
tls *types.TLSConfig
18+
auth types.AuthProvider
19+
retryPolicy *types.RetryPolicy
1520
}
1621

1722
// ClientOption configures the behavior of [NewClient]. Options are
1823
// applied after gateway configuration is resolved but before the
1924
// underlying SDK client is created.
2025
type ClientOption func(*clientConfig)
2126

27+
// WithLogger sets the logger on the SDK client configuration.
28+
func WithLogger(l types.Logger) ClientOption {
29+
return func(c *clientConfig) {
30+
c.logger = l
31+
}
32+
}
33+
34+
// WithTimeout sets the connection timeout for the SDK client.
35+
func WithTimeout(d time.Duration) ClientOption {
36+
return func(c *clientConfig) {
37+
c.timeout = d
38+
}
39+
}
40+
2241
// WithTLS overrides the TLS settings derived from the gateway's auth mode.
2342
// Use this to provide custom certificates or force insecure connections.
2443
func WithTLS(cfg *types.TLSConfig) ClientOption {
@@ -35,3 +54,10 @@ func WithAuth(provider types.AuthProvider) ClientOption {
3554
c.auth = provider
3655
}
3756
}
57+
58+
// WithRetryPolicy sets the retry policy on the SDK client configuration.
59+
func WithRetryPolicy(p *types.RetryPolicy) ClientOption {
60+
return func(c *clientConfig) {
61+
c.retryPolicy = p
62+
}
63+
}

‎sdk/go/openshell/v1/types/config.go‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@
33

44
package types
55

6+
import "time"
7+
68
// Config holds all settings needed to create a Client.
79
type Config struct {
8-
Address string
9-
TLS *TLSConfig
10-
Auth AuthProvider
10+
Address string
11+
TLS *TLSConfig
12+
Auth AuthProvider
13+
Timeout time.Duration
14+
RetryPolicy *RetryPolicy
15+
Logger Logger
1116
}

‎sdk/go/openshell/v1/types/types.go‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
package types
55

6+
import "time"
7+
68
// SandboxPhase represents the lifecycle phase of a sandbox.
79
type SandboxPhase string
810

@@ -43,8 +45,12 @@ type TLSConfig struct {
4345
CertFile string
4446
KeyFile string
4547
CAFile string
46-
// Insecure disables TLS certificate verification. This makes the
47-
// connection vulnerable to man-in-the-middle attacks. Only use for
48-
// development gateways with self-signed certificates.
4948
Insecure bool
5049
}
50+
51+
// RetryPolicy configures automatic retry behavior for failed RPCs.
52+
type RetryPolicy struct {
53+
MaxRetries int
54+
InitialWait time.Duration
55+
MaxWait time.Duration
56+
}

0 commit comments

Comments
 (0)