diff --git a/example/http-client/main.go b/example/http-client/main.go index 21a7dd8d..0732d407 100644 --- a/example/http-client/main.go +++ b/example/http-client/main.go @@ -10,9 +10,12 @@ import ( ) func newZitiClient() *http.Client { + ziti.DefaultCollection.ForAll(func(ctx ziti.Context) { + ctx.Authenticate() + }) zitiTransport := http.DefaultTransport.(*http.Transport).Clone() // copy default transport zitiTransport.DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) { - dialer := ziti.NewDialerWithFallback(ctx, nil) + dialer := ziti.DefaultCollection.NewDialer() return dialer.Dial(network, addr) } zitiTransport.TLSClientConfig.InsecureSkipVerify = true diff --git a/ziti/collection.go b/ziti/collection.go index 74979687..4e60ce44 100644 --- a/ziti/collection.go +++ b/ziti/collection.go @@ -62,7 +62,7 @@ func NewSdkCollection() *CtxCollection { // NewSdkCollectionFromEnv will create an empty CtxCollection and then attempt to populate it from configuration files // provided in a semicolon separate list of file paths retrieved from an environment variable. -func NewSdkCollectionFromEnv(envVariable string) *CtxCollection { +func NewSdkCollectionFromEnv(envVariable string, configTypes []string) *CtxCollection { collection := NewSdkCollection() envValue := os.Getenv(envVariable) @@ -74,6 +74,7 @@ func NewSdkCollectionFromEnv(envVariable string) *CtxCollection { if identityFile == "" { continue } + cfg, err := NewConfigFromFile(identityFile) if err != nil { @@ -81,6 +82,8 @@ func NewSdkCollectionFromEnv(envVariable string) *CtxCollection { continue } + cfg.ConfigTypes = append(configTypes) + //collection.NewContext stores the new ctx in its internal collection _, err = collection.NewContext(cfg) diff --git a/ziti/default_collection.go b/ziti/default_collection.go index 3d18dfd6..a02fd717 100644 --- a/ziti/default_collection.go +++ b/ziti/default_collection.go @@ -26,8 +26,7 @@ var DefaultCollection *CtxCollection const IdentitiesEnv = "ZITI_IDENTITIES" func init() { - DefaultCollection = NewSdkCollectionFromEnv(IdentitiesEnv) - DefaultCollection.ConfigTypes = []string{InterceptV1, ClientConfigV1} + DefaultCollection = NewSdkCollectionFromEnv(IdentitiesEnv, []string{InterceptV1, ClientConfigV1}) } // Deprecated: ForAllContexts iterates over all Context instances in the DefaultCollection and call the provided function `f`.