Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add FromEnv provider #14

Merged
merged 1 commit into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/go-git/go-git/v5 v5.11.0
github.com/open-feature/go-sdk v1.9.0
github.com/open-feature/go-sdk-contrib/providers/flagsmith v0.1.4
github.com/open-feature/go-sdk-contrib/providers/from-env v0.1.4
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.18.2
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ github.com/open-feature/go-sdk v1.9.0 h1:1Nyj+XNHfL0rRGZgGCbZ29CHDD57PQJL7Q/2ZbW
github.com/open-feature/go-sdk v1.9.0/go.mod h1:n5BM4DfvIiKaWWquZnL/yVihcGM5aLsz7rNYE3BkXAM=
github.com/open-feature/go-sdk-contrib/providers/flagsmith v0.1.4 h1:YfKBV2j43WtlgjFZfL0tizHD6MiL/wgcv2rC3HwRDh4=
github.com/open-feature/go-sdk-contrib/providers/flagsmith v0.1.4/go.mod h1:m/VoKIYDWaFuPqEW1A/9z/ecps+J8/LZXYpZ6z1yfB8=
github.com/open-feature/go-sdk-contrib/providers/from-env v0.1.4 h1:zB2nWO6lwSEIeLBQSwjVFA4tnBtRjni+Ylfj/Mjz5Ew=
github.com/open-feature/go-sdk-contrib/providers/from-env v0.1.4/go.mod h1:bgnc2nFZKNiGRBeQ86MyA5kbiSLYykWtH9AYhT/Y8QY=
github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4=
github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4=
Expand Down
1 change: 1 addition & 0 deletions lib/config/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ type ProviderType string

const (
Flagsmith ProviderType = "flagsmith"
FromEnv ProviderType = "env"
)

type DestinationType string
Expand Down
9 changes: 8 additions & 1 deletion lib/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import (
"github.com/go-logr/logr"
"github.com/graytonio/flagops/lib/config"
flagsmith "github.com/open-feature/go-sdk-contrib/providers/flagsmith/pkg"
fromEnv "github.com/open-feature/go-sdk-contrib/providers/from-env/pkg"
"github.com/open-feature/go-sdk/openfeature"
)

var providerConfigMap = map[config.ProviderType]providerConfig{
config.Flagsmith: configureFlagsmithProvider,
config.FromEnv: configureFromEnvProvider,
}

func ConfigureProviders(envs map[string]config.Environment) (map[string]*openfeature.Client, error) {
Expand All @@ -38,4 +40,9 @@ func configureFlagsmithProvider(name string, env config.Environment) (*openfeatu
provider := flagsmith.NewProvider(client, flagsmith.WithUsingBooleanConfigValue())
openfeature.SetNamedProvider(fmt.Sprintf("%s-%s", name, env.Provider), provider)
return openfeature.NewClient(fmt.Sprintf("%s-%s", name, env.Provider)).WithLogger(logr.Discard()), nil
}
}

func configureFromEnvProvider(name string, env config.Environment) (*openfeature.Client, error) {
openfeature.SetNamedProvider(fmt.Sprintf("%s-%s", name, env.Provider), &fromEnv.FromEnvProvider{})
return openfeature.NewClient(fmt.Sprintf("%s-%s", name, env.Provider)).WithLogger(logr.Discard()), nil
}
15 changes: 11 additions & 4 deletions tests/.flagops.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
envs:
production:
flagsmith:
provider: flagsmith
apiKey: h8jqBWsXuGqtW4EKY945Cm
env:
provider: env

paths:
- path: basic/test.txt
env: production
env: flagsmith
dest:
type: file
path: basic/output.txt
- path: conditional/test.txt
env: production
env: flagsmith
dest:
type: file
path: conditional/output.txt
path: conditional/output.txt
- path: env/test.txt
env: env
dest:
type: file
path: env/output.txt
3 changes: 3 additions & 0 deletions tests/env/expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test string
3
true
3 changes: 3 additions & 0 deletions tests/env/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[{ env "string_feature" }]
[{ env "integer_feature" }]
[{ env "bool_feature_enabled" }]
Binary file modified tests/flagops
Binary file not shown.
4 changes: 4 additions & 0 deletions tests/makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@

SUBDIRS := $(wildcard */)

export string_feature = {"defaultVariant":"string","variants":[{"name":"string","targetingKey":"","criteria":[],"value":"test string"}]}
export integer_feature = {"defaultVariant":"int","variants":[{"name":"int","targetingKey":"","criteria":[],"value":3}]}
export bool_feature = {"defaultVariant":"bool","variants":[{"name":"bool","targetingKey":"","criteria":[],"value":true}]}

.PHONY: test
test: ${SUBDIRS}
@./flagops
Expand Down
Loading