Skip to content

Commit a18fc6e

Browse files
authored
hubclient: use retryablehttp for http retries (#97)
fixes #95 Signed-off-by: Nick Santos <[email protected]>
1 parent d31b518 commit a18fc6e

3 files changed

Lines changed: 14 additions & 6 deletions

File tree

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.23.0
55
toolchain go1.24.1
66

77
require (
8+
github.com/hashicorp/go-retryablehttp v0.7.7
89
github.com/hashicorp/terraform-plugin-docs v0.19.4
910
github.com/hashicorp/terraform-plugin-framework v1.10.0
1011
github.com/hashicorp/terraform-plugin-framework-validators v0.13.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+l
8989
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
9090
github.com/hashicorp/go-plugin v1.6.1 h1:P7MR2UP6gNKGPp+y7EZw2kOiq4IR9WiqLvp0XOsVdwI=
9191
github.com/hashicorp/go-plugin v1.6.1/go.mod h1:XPHFku2tFo3o3QKFgSYo+cghcUhw1NA1hZyMK0PWAw0=
92+
github.com/hashicorp/go-retryablehttp v0.7.7 h1:C8hUCYzor8PIfXHa4UrZkU4VvK8o9ISHxT2Q8+VepXU=
93+
github.com/hashicorp/go-retryablehttp v0.7.7/go.mod h1:pkQpWZeYWskR+D1tR2O5OcBFOxfA7DoAO6xtkuQnHTk=
9294
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
9395
github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8=
9496
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=

internal/hubclient/client.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"time"
2828

2929
"github.com/go-jose/go-jose/v3/jwt"
30+
"github.com/hashicorp/go-retryablehttp"
3031
)
3132

3233
type Auth struct {
@@ -69,18 +70,22 @@ func NewClient(config Config) *Client {
6970
version = "dev"
7071
}
7172

73+
baseClient := &http.Client{
74+
Timeout: time.Minute,
75+
Transport: &roundTripper{
76+
userAgent: fmt.Sprintf("terraform-provider-docker/%s", version),
77+
},
78+
}
79+
retryClient := retryablehttp.NewClient()
80+
retryClient.HTTPClient = baseClient
81+
7282
return &Client{
7383
BaseURL: config.BaseURL,
7484
auth: Auth{
7585
Username: config.Username,
7686
Password: config.Password,
7787
},
78-
HTTPClient: &http.Client{
79-
Timeout: time.Minute,
80-
Transport: &roundTripper{
81-
userAgent: fmt.Sprintf("terraform-provider-docker/%s", version),
82-
},
83-
},
88+
HTTPClient: retryClient.StandardClient(),
8489
}
8590
}
8691

0 commit comments

Comments
 (0)