File tree 2 files changed +25
-23
lines changed
2 files changed +25
-23
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ import (
25
25
"net/http"
26
26
"net/url"
27
27
"os"
28
+ "path/filepath"
28
29
"strings"
29
30
"sync"
30
31
"time"
@@ -248,6 +249,30 @@ func (a *OAuth2) SetDirectory(dir string) {
248
249
a .TLSConfig .SetDirectory (dir )
249
250
}
250
251
252
+ // LoadHTTPConfig parses the YAML input s into a HTTPClientConfig.
253
+ func LoadHTTPConfig (s string ) (* HTTPClientConfig , error ) {
254
+ cfg := & HTTPClientConfig {}
255
+ err := yaml .UnmarshalStrict ([]byte (s ), cfg )
256
+ if err != nil {
257
+ return nil , err
258
+ }
259
+ return cfg , nil
260
+ }
261
+
262
+ // LoadHTTPConfigFile parses the given YAML file into a HTTPClientConfig.
263
+ func LoadHTTPConfigFile (filename string ) (* HTTPClientConfig , []byte , error ) {
264
+ content , err := os .ReadFile (filename )
265
+ if err != nil {
266
+ return nil , nil , err
267
+ }
268
+ cfg , err := LoadHTTPConfig (string (content ))
269
+ if err != nil {
270
+ return nil , nil , err
271
+ }
272
+ cfg .SetDirectory (filepath .Dir (filepath .Dir (filename )))
273
+ return cfg , content , nil
274
+ }
275
+
251
276
// HTTPClientConfig configures an HTTP client.
252
277
type HTTPClientConfig struct {
253
278
// The HTTP basic authentication credentials for the targets.
Original file line number Diff line number Diff line change @@ -1125,29 +1125,6 @@ func TestInvalidHTTPConfigs(t *testing.T) {
1125
1125
}
1126
1126
}
1127
1127
1128
- // LoadHTTPConfig parses the YAML input s into a HTTPClientConfig.
1129
- func LoadHTTPConfig (s string ) (* HTTPClientConfig , error ) {
1130
- cfg := & HTTPClientConfig {}
1131
- err := yaml .UnmarshalStrict ([]byte (s ), cfg )
1132
- if err != nil {
1133
- return nil , err
1134
- }
1135
- return cfg , nil
1136
- }
1137
-
1138
- // LoadHTTPConfigFile parses the given YAML file into a HTTPClientConfig.
1139
- func LoadHTTPConfigFile (filename string ) (* HTTPClientConfig , []byte , error ) {
1140
- content , err := os .ReadFile (filename )
1141
- if err != nil {
1142
- return nil , nil , err
1143
- }
1144
- cfg , err := LoadHTTPConfig (string (content ))
1145
- if err != nil {
1146
- return nil , nil , err
1147
- }
1148
- return cfg , content , nil
1149
- }
1150
-
1151
1128
type roundTrip struct {
1152
1129
theResponse * http.Response
1153
1130
theError error
You can’t perform that action at this time.
0 commit comments