Skip to content

Commit ef171b5

Browse files
committed
Add API for controlling proxy use when connecting to controller. Fixes #663
1 parent a195721 commit ef171b5

File tree

15 files changed

+437
-407
lines changed

15 files changed

+437
-407
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# Release notes 0.24.0
2+
3+
## Issues Fixed and Dependency Updates
4+
5+
* github.com/openziti/sdk-golang: [v0.23.45 -> v0.24.0](https://github.com/openziti/sdk-golang/compare/v0.23.45...v0.24.0)
6+
* [Issue #663](https://github.com/openziti/sdk-golang/issues/663) - Add API to allow controlling proxying connections to controllers and routers.
7+
8+
* github.com/go-resty/resty/v2: v2.15.3 -> v2.16.4
9+
* github.com/openziti/channel/v3: [v3.0.26 -> v3.0.27](https://github.com/openziti/channel/compare/v3.0.26...v3.0.27)
10+
* github.com/openziti/edge-api: [v0.26.36 -> v0.26.38](https://github.com/openziti/edge-api/compare/v0.26.36...v0.26.38)
11+
* github.com/openziti/transport/v2: [v2.0.159 -> v2.0.160](https://github.com/openziti/transport/compare/v2.0.159...v2.0.160)
12+
* golang.org/x/oauth2: v0.23.0 -> v0.25.0
13+
* google.golang.org/protobuf: v1.36.2 -> v1.36.3
14+
115
# Release notes 0.23.45
216

317
## Issues Fixed and Dependency Updates

edge-apis/clients.go

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,12 @@ func (self *BaseClient[A]) Authenticate(credentials Credentials, configTypesOver
123123
}
124124

125125
// initializeComponents assembles the lower level components necessary for the go-swagger/openapi facilities.
126-
func (self *BaseClient[A]) initializeComponents(apiUrls []*url.URL, caPool *x509.CertPool) {
127-
components := NewComponents()
128-
components.HttpTransport.TLSClientConfig.RootCAs = caPool
129-
components.CaPool = caPool
126+
func (self *BaseClient[A]) initializeComponents(config *ApiClientConfig) {
127+
components := NewComponentsWithConfig(&ComponentsConfig{
128+
Proxy: config.Proxy,
129+
})
130+
components.HttpTransport.TLSClientConfig.RootCAs = config.CaPool
131+
components.CaPool = config.CaPool
130132

131133
self.Components = *components
132134
}
@@ -205,6 +207,13 @@ type ManagementApiClient struct {
205207
BaseClient[ZitiEdgeManagement]
206208
}
207209

210+
type ApiClientConfig struct {
211+
ApiUrls []*url.URL
212+
CaPool *x509.CertPool
213+
TotpCallback func(chan string)
214+
Proxy func(r *http.Request) (*url.URL, error)
215+
}
216+
208217
// NewManagementApiClient will assemble an ManagementApiClient. The apiUrl should be the full URL
209218
// to the Edge Management API (e.g. `https://example.com/edge/management/v1`).
210219
//
@@ -217,16 +226,25 @@ type ManagementApiClient struct {
217226
// to obtain and verify the target controllers CAs. Tools should allow users to verify and accept new controllers
218227
// that have not been verified from an outside secret (such as an enrollment token).
219228
func NewManagementApiClient(apiUrls []*url.URL, caPool *x509.CertPool, totpCallback func(chan string)) *ManagementApiClient {
229+
return NewManagementApiClientWithConfig(&ApiClientConfig{
230+
ApiUrls: apiUrls,
231+
CaPool: caPool,
232+
TotpCallback: totpCallback,
233+
Proxy: http.ProxyFromEnvironment,
234+
})
235+
}
236+
237+
func NewManagementApiClientWithConfig(config *ApiClientConfig) *ManagementApiClient {
220238
ret := &ManagementApiClient{}
221239
ret.Schemes = rest_management_api_client.DefaultSchemes
222240
ret.ApiBinding = "edge-management"
223241
ret.ApiVersion = "v1"
224-
ret.ApiUrls = apiUrls
225-
ret.initializeComponents(apiUrls, caPool)
242+
ret.ApiUrls = config.ApiUrls
243+
ret.initializeComponents(config)
226244

227245
transportPool := NewClientTransportPoolRandom()
228246

229-
for _, apiUrl := range apiUrls {
247+
for _, apiUrl := range config.ApiUrls {
230248
newRuntime := NewRuntime(apiUrl, ret.Schemes, ret.Components.HttpClient)
231249
newRuntime.DefaultAuthentication = ret
232250
transportPool.Add(apiUrl, newRuntime)
@@ -235,7 +253,7 @@ func NewManagementApiClient(apiUrls []*url.URL, caPool *x509.CertPool, totpCallb
235253
newApi := rest_management_api_client.New(transportPool, nil)
236254
api := ZitiEdgeManagement{
237255
ZitiEdgeManagement: newApi,
238-
TotpCallback: totpCallback,
256+
TotpCallback: config.TotpCallback,
239257
ClientTransportPool: transportPool,
240258
}
241259

@@ -261,17 +279,26 @@ type ClientApiClient struct {
261279
// to obtain and verify the target controllers CAs. Tools should allow users to verify and accept new controllers
262280
// that have not been verified from an outside secret (such as an enrollment token).
263281
func NewClientApiClient(apiUrls []*url.URL, caPool *x509.CertPool, totpCallback func(chan string)) *ClientApiClient {
282+
return NewClientApiClientWithConfig(&ApiClientConfig{
283+
ApiUrls: apiUrls,
284+
CaPool: caPool,
285+
TotpCallback: totpCallback,
286+
Proxy: http.ProxyFromEnvironment,
287+
})
288+
}
289+
290+
func NewClientApiClientWithConfig(config *ApiClientConfig) *ClientApiClient {
264291
ret := &ClientApiClient{}
265292
ret.ApiBinding = "edge-client"
266293
ret.ApiVersion = "v1"
267294
ret.Schemes = rest_client_api_client.DefaultSchemes
268-
ret.ApiUrls = apiUrls
295+
ret.ApiUrls = config.ApiUrls
269296

270-
ret.initializeComponents(apiUrls, caPool)
297+
ret.initializeComponents(config)
271298

272299
transportPool := NewClientTransportPoolRandom()
273300

274-
for _, apiUrl := range apiUrls {
301+
for _, apiUrl := range config.ApiUrls {
275302
newRuntime := NewRuntime(apiUrl, ret.Schemes, ret.Components.HttpClient)
276303
newRuntime.DefaultAuthentication = ret
277304
transportPool.Add(apiUrl, newRuntime)
@@ -280,7 +307,7 @@ func NewClientApiClient(apiUrls []*url.URL, caPool *x509.CertPool, totpCallback
280307
newApi := rest_client_api_client.New(transportPool, nil)
281308
api := ZitiEdgeClient{
282309
ZitiEdgeClient: newApi,
283-
TotpCallback: totpCallback,
310+
TotpCallback: config.TotpCallback,
284311
ClientTransportPool: transportPool,
285312
}
286313
ret.API = &api

edge-apis/component.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"github.com/openziti/edge-api/rest_util"
66
"net/http"
77
"net/http/cookiejar"
8+
"net/url"
89
"time"
910
)
1011

@@ -17,12 +18,22 @@ type Components struct {
1718
CaPool *x509.CertPool
1819
}
1920

21+
type ComponentsConfig struct {
22+
Proxy func(*http.Request) (*url.URL, error)
23+
}
24+
2025
// NewComponents assembles a new set of components with reasonable production defaults.
2126
func NewComponents() *Components {
27+
return NewComponentsWithConfig(&ComponentsConfig{
28+
Proxy: http.ProxyFromEnvironment,
29+
})
30+
}
31+
32+
// NewComponentsWithConfig assembles a new set of components with reasonable production defaults.
33+
func NewComponentsWithConfig(cfg *ComponentsConfig) *Components {
2234
tlsClientConfig, _ := rest_util.NewTlsConfig()
2335

2436
httpTransport := &http.Transport{
25-
Proxy: http.ProxyFromEnvironment,
2637
TLSClientConfig: tlsClientConfig,
2738
ForceAttemptHTTP2: true,
2839
MaxIdleConns: 10,
@@ -31,6 +42,10 @@ func NewComponents() *Components {
3142
ExpectContinueTimeout: 1 * time.Second,
3243
}
3344

45+
if cfg != nil && cfg.Proxy != nil {
46+
httpTransport.Proxy = cfg.Proxy
47+
}
48+
3449
jar, _ := cookiejar.New(nil)
3550

3651
httpClient := &http.Client{

example/go.mod

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
11
module github.com/openziti/sdk-golang/example
22

3-
go 1.21
3+
go 1.21.0
44

5-
toolchain go1.22.1
5+
toolchain go1.23.1
6+
7+
replace github.com/openziti/sdk-golang => ../
68

79
require (
810
github.com/Jeffail/gabs v1.4.0
911
github.com/google/uuid v1.6.0
1012
github.com/gorilla/mux v1.8.1
1113
github.com/michaelquigley/pfxlog v0.6.10
12-
github.com/openziti/foundation/v2 v2.0.47
13-
github.com/openziti/runzmd v1.0.33
14-
github.com/openziti/sdk-golang v0.23.39
14+
github.com/openziti/foundation/v2 v2.0.56
15+
github.com/openziti/runzmd v1.0.60
16+
github.com/openziti/sdk-golang v0.23.45
17+
github.com/openziti/transport/v2 v2.0.160
1518
github.com/pkg/errors v0.9.1
1619
github.com/sirupsen/logrus v1.9.3
17-
github.com/spf13/cobra v1.8.0
20+
github.com/spf13/cobra v1.8.1
1821
github.com/spf13/viper v1.17.0
1922
github.com/zitadel/oidc v1.13.5
20-
golang.org/x/text v0.16.0
23+
golang.org/x/text v0.21.0
2124
google.golang.org/grpc v1.59.0
2225
google.golang.org/grpc/examples v0.0.0-20231107231549-482de2224942
2326
gopkg.in/resty.v1 v1.12.0
@@ -34,7 +37,7 @@ require (
3437
github.com/disintegration/imaging v1.6.2 // indirect
3538
github.com/dlclark/regexp2 v1.10.0 // indirect
3639
github.com/eliukblau/pixterm/pkg/ansimage v0.0.0-20191210081756-9fb6cf8c2f75 // indirect
37-
github.com/fatih/color v1.16.0 // indirect
40+
github.com/fatih/color v1.18.0 // indirect
3841
github.com/fsnotify/fsnotify v1.7.0 // indirect
3942
github.com/fullsailor/pkcs7 v0.0.0-20190404230743-d7302db945fa // indirect
4043
github.com/go-logr/logr v1.4.2 // indirect
@@ -50,13 +53,13 @@ require (
5053
github.com/go-openapi/strfmt v0.23.0 // indirect
5154
github.com/go-openapi/swag v0.23.0 // indirect
5255
github.com/go-openapi/validate v0.24.0 // indirect
53-
github.com/go-resty/resty/v2 v2.13.1 // indirect
56+
github.com/go-resty/resty/v2 v2.15.3 // indirect
5457
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
5558
github.com/golang/protobuf v1.5.4 // indirect
5659
github.com/gomarkdown/markdown v0.0.0-20230922112808-5421fefb8386 // indirect
5760
github.com/gorilla/schema v1.4.1 // indirect
58-
github.com/gorilla/securecookie v1.1.1 // indirect
59-
github.com/gorilla/websocket v1.5.1 // indirect
61+
github.com/gorilla/securecookie v1.1.2 // indirect
62+
github.com/gorilla/websocket v1.5.3 // indirect
6063
github.com/hashicorp/hcl v1.0.0 // indirect
6164
github.com/inconshreveable/mousetrap v1.1.0 // indirect
6265
github.com/josharian/intern v1.0.0 // indirect
@@ -76,12 +79,11 @@ require (
7679
github.com/muhlemmer/gu v0.3.1 // indirect
7780
github.com/oklog/ulid v1.3.1 // indirect
7881
github.com/opentracing/opentracing-go v1.2.0 // indirect
79-
github.com/openziti/channel/v2 v2.0.136 // indirect
80-
github.com/openziti/edge-api v0.26.21 // indirect
81-
github.com/openziti/identity v1.0.81 // indirect
82-
github.com/openziti/metrics v1.2.56 // indirect
83-
github.com/openziti/secretstream v0.1.21 // indirect
84-
github.com/openziti/transport/v2 v2.0.138 // indirect
82+
github.com/openziti/channel/v3 v3.0.27 // indirect
83+
github.com/openziti/edge-api v0.26.38 // indirect
84+
github.com/openziti/identity v1.0.94 // indirect
85+
github.com/openziti/metrics v1.2.65 // indirect
86+
github.com/openziti/secretstream v0.1.28 // indirect
8587
github.com/orcaman/concurrent-map/v2 v2.0.1 // indirect
8688
github.com/parallaxsecond/parsec-client-go v0.0.0-20221025095442-f0a77d263cf9 // indirect
8789
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
@@ -105,24 +107,25 @@ require (
105107
github.com/valyala/fasttemplate v1.2.2 // indirect
106108
github.com/yusufpapurcu/wmi v1.2.4 // indirect
107109
github.com/zitadel/logging v0.3.4 // indirect
108-
github.com/zitadel/oidc/v2 v2.12.0 // indirect
109-
go.mongodb.org/mongo-driver v1.16.0 // indirect
110-
go.mozilla.org/pkcs7 v0.0.0-20210826202110-33d05740a352 // indirect
111-
go.opentelemetry.io/otel v1.28.0 // indirect
112-
go.opentelemetry.io/otel/metric v1.28.0 // indirect
113-
go.opentelemetry.io/otel/trace v1.28.0 // indirect
110+
github.com/zitadel/oidc/v2 v2.12.2 // indirect
111+
go.mongodb.org/mongo-driver v1.17.0 // indirect
112+
go.mozilla.org/pkcs7 v0.9.0 // indirect
113+
go.opentelemetry.io/otel v1.29.0 // indirect
114+
go.opentelemetry.io/otel/metric v1.29.0 // indirect
115+
go.opentelemetry.io/otel/trace v1.29.0 // indirect
114116
go.uber.org/multierr v1.11.0 // indirect
115-
golang.org/x/crypto v0.25.0 // indirect
117+
golang.org/x/crypto v0.32.0 // indirect
116118
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
117-
golang.org/x/image v0.18.0 // indirect
118-
golang.org/x/net v0.27.0 // indirect
119-
golang.org/x/oauth2 v0.21.0 // indirect
120-
golang.org/x/sync v0.7.0 // indirect
121-
golang.org/x/sys v0.22.0 // indirect
122-
golang.org/x/term v0.22.0 // indirect
119+
golang.org/x/image v0.23.0 // indirect
120+
golang.org/x/net v0.34.0 // indirect
121+
golang.org/x/oauth2 v0.25.0 // indirect
122+
golang.org/x/sync v0.10.0 // indirect
123+
golang.org/x/sys v0.29.0 // indirect
124+
golang.org/x/term v0.28.0 // indirect
123125
google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17 // indirect
124-
google.golang.org/protobuf v1.34.2 // indirect
126+
google.golang.org/protobuf v1.36.2 // indirect
127+
gopkg.in/go-jose/go-jose.v2 v2.6.3 // indirect
125128
gopkg.in/ini.v1 v1.67.0 // indirect
126129
gopkg.in/yaml.v3 v3.0.1 // indirect
127-
nhooyr.io/websocket v1.8.11 // indirect
130+
nhooyr.io/websocket v1.8.17 // indirect
128131
)

0 commit comments

Comments
 (0)