@@ -32,16 +32,18 @@ var (
32
32
DefaultClientUtils ClientUtils = & DefaultClientUtilsImpl {}
33
33
)
34
34
35
- func ( s * DefaultClientUtilsImpl ) MakeRawBackplaneAPIClientWithAccessToken ( base , accessToken string ) ( BackplaneApi.ClientInterface , error ) {
36
- co := func (client * BackplaneApi.Client ) error {
35
+ func makeClientOptions ( accessToken string ) BackplaneApi.ClientOption {
36
+ return func (client * BackplaneApi.Client ) error {
37
37
client .RequestEditors = append (client .RequestEditors , func (ctx context.Context , req * http.Request ) error {
38
38
req .Header .Add ("Authorization" , "Bearer " + accessToken )
39
39
req .Header .Set ("User-Agent" , "backplane-cli" + info .Version )
40
40
return nil
41
41
})
42
42
return nil
43
43
}
44
+ }
44
45
46
+ func (s * DefaultClientUtilsImpl ) MakeRawBackplaneAPIClientWithAccessToken (base , accessToken string ) (BackplaneApi.ClientInterface , error ) {
45
47
// Inject client Proxy Url from config
46
48
if s .clientProxyURL == "" {
47
49
bpConfig , err := config .GetBackplaneConfiguration ()
@@ -53,39 +55,21 @@ func (s *DefaultClientUtilsImpl) MakeRawBackplaneAPIClientWithAccessToken(base,
53
55
}
54
56
}
55
57
56
- // Update http proxy transport
57
- if s .clientProxyURL != "" {
58
- proxyURL , err := url .Parse (s .clientProxyURL )
59
- if err != nil {
60
- return nil , err
61
- }
62
- http .DefaultTransport = & http.Transport {Proxy : http .ProxyURL (proxyURL )}
63
-
64
- logger .Debugf ("Using backplane Proxy URL: %s\n " , s .clientProxyURL )
65
- }
66
-
67
- return BackplaneApi .NewClient (base , co )
58
+ return makeRawBackplaneAPIClientWithAccessTokenCustomProxy (base , accessToken , s .clientProxyURL )
68
59
}
69
60
70
61
// makeRawBackplaneAPIClientWithAccessTokenCustomProxy creates a BackplaneApi.ClientInterface with a custom proxy url
71
62
// proxyURL is optional, the default behavior is no proxy.
72
- func makeRawBackplaneAPIClientWithAccessTokenCustomProxy (server string , accessToken string , proxyURL * string ) (BackplaneApi.ClientInterface , error ) {
73
- co := func (client * BackplaneApi.Client ) error {
74
- client .RequestEditors = append (client .RequestEditors , func (ctx context.Context , req * http.Request ) error {
75
- req .Header .Add ("Authorization" , "Bearer " + accessToken )
76
- req .Header .Set ("User-Agent" , "backplane-cli" + info .Version )
77
- return nil
78
- })
79
- return nil
80
- }
63
+ func makeRawBackplaneAPIClientWithAccessTokenCustomProxy (server string , accessToken string , proxyURL string ) (BackplaneApi.ClientInterface , error ) {
64
+ co := makeClientOptions (accessToken )
81
65
82
- if proxyURL != nil {
83
- proxy , err := url .Parse (* proxyURL )
66
+ if proxyURL != "" {
67
+ proxy , err := url .Parse (proxyURL )
84
68
if err != nil {
85
69
return nil , err
86
70
}
87
71
http .DefaultTransport = & http.Transport {Proxy : http .ProxyURL (proxy )}
88
- logger .Debugf ("Using backplane Proxy URL: %s\n " , * proxyURL )
72
+ logger .Debugf ("Using backplane Proxy URL: %s\n " , proxyURL )
89
73
}
90
74
91
75
return BackplaneApi .NewClient (server , co )
@@ -100,14 +84,7 @@ func (s *DefaultClientUtilsImpl) MakeRawBackplaneAPIClient(base string) (Backpla
100
84
}
101
85
102
86
func (* DefaultClientUtilsImpl ) MakeBackplaneAPIClientWithAccessToken (base , accessToken string ) (BackplaneApi.ClientWithResponsesInterface , error ) {
103
- co := func (client * BackplaneApi.Client ) error {
104
- client .RequestEditors = append (client .RequestEditors , func (ctx context.Context , req * http.Request ) error {
105
- req .Header .Add ("Authorization" , "Bearer " + accessToken )
106
- req .Header .Set ("User-Agent" , "backplane-cli" + info .Version )
107
- return nil
108
- })
109
- return nil
110
- }
87
+ co := makeClientOptions (accessToken )
111
88
112
89
return BackplaneApi .NewClientWithResponses (base , co )
113
90
}
@@ -133,7 +110,15 @@ func (s *DefaultClientUtilsImpl) GetBackplaneClient(backplaneURL string, ocmToke
133
110
}
134
111
135
112
logger .Debugln ("Getting client" )
136
- backplaneClient , err := makeRawBackplaneAPIClientWithAccessTokenCustomProxy (backplaneURL , ocmToken , proxyURL )
113
+
114
+ var proxyString string
115
+ if proxyURL == nil {
116
+ proxyString = ""
117
+ } else {
118
+ proxyString = * proxyURL
119
+ }
120
+
121
+ backplaneClient , err := makeRawBackplaneAPIClientWithAccessTokenCustomProxy (backplaneURL , ocmToken , proxyString )
137
122
if err != nil {
138
123
return client , fmt .Errorf ("unable to create backplane api client: %w" , err )
139
124
}
0 commit comments