Skip to content

Commit 5fc496e

Browse files
authored
[client] Add ways to get HTTP clients (#130)
<!-- Copyright (C) 2020-2022 Arm Limited or its affiliates and Contributors. All rights reserved. SPDX-License-Identifier: Proprietary --> ### Description - Added utilities to help creating clients ### Test Coverage <!-- Please put an `x` in the correct box e.g. `[x]` to indicate the testing coverage of this change. --> - [x] This change is covered by existing or additional automated tests. - [ ] Manual testing has been performed (and evidence provided) as automated testing was not feasible. - [ ] Additional tests are not required for this change (e.g. documentation update).
1 parent d4136b2 commit 5fc496e

File tree

4 files changed

+23
-11
lines changed

4 files changed

+23
-11
lines changed

changes/20251027104429.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:sparkles: [client] Add ways to get HTTP clients

utils/client/client.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,25 @@ import (
1212

1313
_client "github.com/ARM-software/embedded-development-services-client/client"
1414
"github.com/ARM-software/golang-utils/utils/commonerrors"
15+
"github.com/ARM-software/golang-utils/utils/field"
1516
"github.com/ARM-software/golang-utils/utils/http"
1617
"github.com/ARM-software/golang-utils/utils/reflection"
1718
)
1819

1920
// NewClient returns a new API client based on request configuration
2021
func NewClient(cfg *http.RequestConfiguration, logger logr.Logger, underlyingHTTPClient *_http.Client) (c *_client.APIClient, err error) {
22+
httpClient, err := NewHTTPClient(cfg, http.DefaultBasicRetryPolicyConfiguration(), logger, underlyingHTTPClient)
23+
if err != nil {
24+
return
25+
}
26+
clientCfg := newClientConfiguration(cfg)
27+
clientCfg.HTTPClient = httpClient.StandardClient()
28+
c = _client.NewAPIClient(clientCfg)
29+
return
30+
}
31+
32+
// NewHTTPClient returns an HTTP retryable client based on request configuration
33+
func NewHTTPClient(cfg *http.RequestConfiguration, retryCfg *http.RetryPolicyConfiguration, logger logr.Logger, underlyingHTTPClient *_http.Client) (httpClient http.IRetryableClient, err error) {
2134
if logger.IsZero() {
2235
err = commonerrors.ErrNoLogger
2336
return
@@ -32,11 +45,9 @@ func NewClient(cfg *http.RequestConfiguration, logger logr.Logger, underlyingHTT
3245
return
3346
}
3447

35-
httpClientCfg := http.DefaultRobustHTTPClientConfiguration()
36-
httpClient := http.NewConfigurableRetryableClientWithLoggerAndCustomClient(httpClientCfg, cfg, logger, underlyingHTTPClient)
37-
clientCfg := newClientConfiguration(cfg)
38-
clientCfg.HTTPClient = httpClient.StandardClient()
39-
c = _client.NewAPIClient(clientCfg)
48+
httpClientCfg := http.DefaultHTTPClientConfiguration()
49+
httpClientCfg.RetryPolicy = field.Optional[http.RetryPolicyConfiguration](retryCfg, *http.DefaultBasicRetryPolicyConfiguration())
50+
httpClient = http.NewConfigurableRetryableClientWithLoggerAndCustomClient(httpClientCfg, cfg, logger, underlyingHTTPClient)
4051
return
4152
}
4253

utils/go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.25
44

55
require (
66
github.com/ARM-software/embedded-development-services-client/client v1.82.0
7-
github.com/ARM-software/golang-utils/utils v1.129.0
7+
github.com/ARM-software/golang-utils/utils v1.130.0
88
github.com/go-faker/faker/v4 v4.7.0
99
github.com/go-logr/logr v1.4.3
1010
github.com/perimeterx/marshmallow v1.1.5
@@ -17,7 +17,7 @@ require (
1717

1818
require (
1919
al.essio.dev/pkg/shellescape v1.5.1 // indirect
20-
github.com/DeRuina/timberjack v1.3.8 // indirect
20+
github.com/DeRuina/timberjack v1.3.9 // indirect
2121
github.com/OneOfOne/xxhash v1.2.8 // indirect
2222
github.com/asaskevich/govalidator v0.0.0-20200108200545-475eaeb16496 // indirect
2323
github.com/avast/retry-go/v4 v4.7.0 // indirect

utils/go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ al.essio.dev/pkg/shellescape v1.5.1/go.mod h1:6sIqp7X2P6mThCQ7twERpZTuigpr6KbZWt
33
bitbucket.org/creachadair/stringset v0.0.9/go.mod h1:t+4WcQ4+PXTa8aQdNKe40ZP6iwesoMFWAxPGd3UGjyY=
44
github.com/ARM-software/embedded-development-services-client/client v1.82.0 h1:in5rwsgAlk7LYQROvU7BmSpoXCn4GA3V85W9/ODE0UM=
55
github.com/ARM-software/embedded-development-services-client/client v1.82.0/go.mod h1:jGywz6vB+i3RkF6J7LXSs0l4g6xHuGfbhW+iWMEODkY=
6-
github.com/ARM-software/golang-utils/utils v1.129.0 h1:dUGro1vQf/T+u95sts3bAHe9oNvk9SNimld29vhnxPM=
7-
github.com/ARM-software/golang-utils/utils v1.129.0/go.mod h1:VmB1bgsNOJ5gF7qqKddjpEpfZKi+nkHX3LGmFoY7VFc=
6+
github.com/ARM-software/golang-utils/utils v1.130.0 h1:1LBLweH1qgJOxynOrcjbPeeoaiaPll8fYCa3ugLyyy4=
7+
github.com/ARM-software/golang-utils/utils v1.130.0/go.mod h1:l1W+4uRhZCVEoDzozfomDG6erB6kZz63Q+DCn6xNGM8=
88
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
9-
github.com/DeRuina/timberjack v1.3.8 h1:lLxmRExvZygKSbb27Vp9hS0Tv8mL0WmFbwfRF29nY0Q=
10-
github.com/DeRuina/timberjack v1.3.8/go.mod h1:RLoeQrwrCGIEF8gO5nV5b/gMD0QIy7bzQhBUgpp1EqE=
9+
github.com/DeRuina/timberjack v1.3.9 h1:6UXZ1I7ExPGTX/1UNYawR58LlOJUHKBPiYC7WQ91eBo=
10+
github.com/DeRuina/timberjack v1.3.9/go.mod h1:RLoeQrwrCGIEF8gO5nV5b/gMD0QIy7bzQhBUgpp1EqE=
1111
github.com/OneOfOne/xxhash v1.2.8 h1:31czK/TI9sNkxIKfaUfGlU47BAxQ0ztGgd9vPyqimf8=
1212
github.com/OneOfOne/xxhash v1.2.8/go.mod h1:eZbhyaAYD41SGSSsnmcpxVoRiQ/MPUTjUdIIOT9Um7Q=
1313
github.com/StackExchange/wmi v1.2.0/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=

0 commit comments

Comments
 (0)