From a23ce1649c2d9b1976b01e738a4011aa9e82c144 Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Wed, 22 Jan 2025 14:21:25 -0500 Subject: [PATCH 1/4] tweak NewSdkCollectionFromEnv and fix the http-client example --- example/http-client/main.go | 5 ++++- ziti/collection.go | 5 ++++- ziti/default_collection.go | 3 +-- 3 files changed, 9 insertions(+), 4 deletions(-) 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`. From bc44b0d802a551be18ef3084a82ed2f92b4af785 Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Wed, 22 Jan 2025 14:35:25 -0500 Subject: [PATCH 2/4] fix append issue --- ziti/collection.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ziti/collection.go b/ziti/collection.go index 4e60ce44..25c85c5e 100644 --- a/ziti/collection.go +++ b/ziti/collection.go @@ -82,7 +82,7 @@ func NewSdkCollectionFromEnv(envVariable string, configTypes []string) *CtxColle continue } - cfg.ConfigTypes = append(configTypes) + cfg.ConfigTypes = append(cfg.ConfigTypes, configTypes...) //collection.NewContext stores the new ctx in its internal collection _, err = collection.NewContext(cfg) From 0babe172900f23153ede1dbeb3861f5859fadfde Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Wed, 22 Jan 2025 14:39:35 -0500 Subject: [PATCH 3/4] forgot the version. does this need a minor bump? meh? --- ziti/sdkinfo/build_info.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ziti/sdkinfo/build_info.go b/ziti/sdkinfo/build_info.go index fd5df8ad..1a1e2d6c 100644 --- a/ziti/sdkinfo/build_info.go +++ b/ziti/sdkinfo/build_info.go @@ -20,5 +20,5 @@ package sdkinfo const ( - Version = "v0.23.45" + Version = "v0.23.46" ) From b5600783e538d8a335090b71b07798dba9ae194f Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Wed, 22 Jan 2025 16:09:18 -0500 Subject: [PATCH 4/4] use variadic arg for config types and preserve the function signature if none are passed --- ziti/collection.go | 2 +- ziti/default_collection.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ziti/collection.go b/ziti/collection.go index 25c85c5e..ed2a3731 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, configTypes []string) *CtxCollection { +func NewSdkCollectionFromEnv(envVariable string, configTypes ...string) *CtxCollection { collection := NewSdkCollection() envValue := os.Getenv(envVariable) diff --git a/ziti/default_collection.go b/ziti/default_collection.go index a02fd717..d8a3330f 100644 --- a/ziti/default_collection.go +++ b/ziti/default_collection.go @@ -26,7 +26,7 @@ var DefaultCollection *CtxCollection const IdentitiesEnv = "ZITI_IDENTITIES" func init() { - DefaultCollection = NewSdkCollectionFromEnv(IdentitiesEnv, []string{InterceptV1, ClientConfigV1}) + DefaultCollection = NewSdkCollectionFromEnv(IdentitiesEnv, InterceptV1, ClientConfigV1) } // Deprecated: ForAllContexts iterates over all Context instances in the DefaultCollection and call the provided function `f`.