Skip to content

Commit a23ce16

Browse files
committed
tweak NewSdkCollectionFromEnv and fix the http-client example
1 parent c235d4f commit a23ce16

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

example/http-client/main.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@ import (
1010
)
1111

1212
func newZitiClient() *http.Client {
13+
ziti.DefaultCollection.ForAll(func(ctx ziti.Context) {
14+
ctx.Authenticate()
15+
})
1316
zitiTransport := http.DefaultTransport.(*http.Transport).Clone() // copy default transport
1417
zitiTransport.DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) {
15-
dialer := ziti.NewDialerWithFallback(ctx, nil)
18+
dialer := ziti.DefaultCollection.NewDialer()
1619
return dialer.Dial(network, addr)
1720
}
1821
zitiTransport.TLSClientConfig.InsecureSkipVerify = true

ziti/collection.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func NewSdkCollection() *CtxCollection {
6262

6363
// NewSdkCollectionFromEnv will create an empty CtxCollection and then attempt to populate it from configuration files
6464
// provided in a semicolon separate list of file paths retrieved from an environment variable.
65-
func NewSdkCollectionFromEnv(envVariable string) *CtxCollection {
65+
func NewSdkCollectionFromEnv(envVariable string, configTypes []string) *CtxCollection {
6666
collection := NewSdkCollection()
6767

6868
envValue := os.Getenv(envVariable)
@@ -74,13 +74,16 @@ func NewSdkCollectionFromEnv(envVariable string) *CtxCollection {
7474
if identityFile == "" {
7575
continue
7676
}
77+
7778
cfg, err := NewConfigFromFile(identityFile)
7879

7980
if err != nil {
8081
pfxlog.Logger().Errorf("failed to load config from file '%s'", identityFile)
8182
continue
8283
}
8384

85+
cfg.ConfigTypes = append(configTypes)
86+
8487
//collection.NewContext stores the new ctx in its internal collection
8588
_, err = collection.NewContext(cfg)
8689

ziti/default_collection.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ var DefaultCollection *CtxCollection
2626
const IdentitiesEnv = "ZITI_IDENTITIES"
2727

2828
func init() {
29-
DefaultCollection = NewSdkCollectionFromEnv(IdentitiesEnv)
30-
DefaultCollection.ConfigTypes = []string{InterceptV1, ClientConfigV1}
29+
DefaultCollection = NewSdkCollectionFromEnv(IdentitiesEnv, []string{InterceptV1, ClientConfigV1})
3130
}
3231

3332
// Deprecated: ForAllContexts iterates over all Context instances in the DefaultCollection and call the provided function `f`.

0 commit comments

Comments
 (0)