Skip to content

Commit 06093c7

Browse files
committed
Defend against nil http.Client in sdk.Config
1 parent e42be94 commit 06093c7

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

sdk/auth/token_adding_interceptor.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/lestrrat-go/jwx/v2/jwk"
1414
"github.com/lestrrat-go/jwx/v2/jws"
1515
"github.com/lestrrat-go/jwx/v2/jwt"
16+
"github.com/opentdf/platform/sdk/httputil"
1617
"google.golang.org/grpc"
1718
"google.golang.org/grpc/codes"
1819
"google.golang.org/grpc/metadata"
@@ -24,6 +25,9 @@ const (
2425
)
2526

2627
func NewTokenAddingInterceptor(t AccessTokenSource, c *http.Client) TokenAddingInterceptor {
28+
if c == nil {
29+
c = httputil.SafeHTTPClient()
30+
}
2731
return TokenAddingInterceptor{
2832
tokenSource: t,
2933
httpClient: c,

sdk/sdk.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/opentdf/platform/protocol/go/wellknownconfiguration"
2828
"github.com/opentdf/platform/sdk/audit"
2929
"github.com/opentdf/platform/sdk/auth"
30+
"github.com/opentdf/platform/sdk/httputil"
3031
"github.com/opentdf/platform/sdk/internal/archive"
3132
"github.com/xeipuuv/gojsonschema"
3233
"google.golang.org/grpc"
@@ -452,7 +453,11 @@ func getTokenEndpoint(c config) (string, error) {
452453
return "", err
453454
}
454455

455-
resp, err := c.httpClient.Do(req)
456+
client := c.httpClient
457+
if client == nil {
458+
client = httputil.SafeHTTPClient()
459+
}
460+
resp, err := client.Do(req)
456461
if err != nil {
457462
return "", err
458463
}

0 commit comments

Comments
 (0)