Compare commits

...

2 Commits

Author SHA1 Message Date
Charandas Batra
0c730b5b8b revert 2026-01-09 16:51:39 -08:00
Charandas Batra
4aaf8ef714 FF: enumerate provider types and default to static for invalid 2026-01-09 16:48:18 -08:00
3 changed files with 31 additions and 9 deletions

View File

@@ -44,7 +44,7 @@ var groupVersion = schema.GroupVersion{
}
type APIBuilder struct {
providerType string
providerType setting.OpenFeatureProviderType
url *url.URL
insecure bool
caFile string
@@ -52,7 +52,7 @@ type APIBuilder struct {
logger log.Logger
}
func NewAPIBuilder(providerType string, url *url.URL, insecure bool, caFile string, staticEvaluator featuremgmt.StaticFlagEvaluator) *APIBuilder {
func NewAPIBuilder(providerType setting.OpenFeatureProviderType, url *url.URL, insecure bool, caFile string, staticEvaluator featuremgmt.StaticFlagEvaluator) *APIBuilder {
return &APIBuilder{
providerType: providerType,
url: url,

View File

@@ -20,7 +20,7 @@ const (
// OpenFeatureConfig holds configuration for initializing OpenFeature
type OpenFeatureConfig struct {
// ProviderType is either "static", "features-service", or "ofrep"
ProviderType string
ProviderType setting.OpenFeatureProviderType
// URL is the remote provider's URL (required for features-service + OFREP providers)
URL *url.URL
// HTTPClient is a pre-configured HTTP client (optional, used by features-service + OFREP providers)
@@ -98,7 +98,7 @@ func InitOpenFeatureWithCfg(cfg *setting.Cfg) error {
}
func createProvider(
providerType string,
providerType setting.OpenFeatureProviderType,
u *url.URL,
staticFlags map[string]bool,
httpClient *http.Client,

View File

@@ -5,15 +5,17 @@ import (
"net/url"
)
type OpenFeatureProviderType string
const (
StaticProviderType = "static"
FeaturesServiceProviderType = "features-service"
OFREPProviderType = "ofrep"
StaticProviderType OpenFeatureProviderType = "static"
FeaturesServiceProviderType OpenFeatureProviderType = "features-service"
OFREPProviderType OpenFeatureProviderType = "ofrep"
)
type OpenFeatureSettings struct {
APIEnabled bool
ProviderType string
ProviderType OpenFeatureProviderType
URL *url.URL
TargetingKey string
ContextAttrs map[string]string
@@ -24,7 +26,27 @@ func (cfg *Cfg) readOpenFeatureSettings() error {
config := cfg.Raw.Section("feature_toggles.openfeature")
cfg.OpenFeature.APIEnabled = config.Key("enable_api").MustBool(true)
cfg.OpenFeature.ProviderType = config.Key("provider").MustString(StaticProviderType)
providerType := config.Key("provider").Validate(func(in string) string {
if in == "" {
return string(StaticProviderType)
}
switch in {
case string(StaticProviderType):
return string(StaticProviderType)
case string(FeaturesServiceProviderType):
return string(FeaturesServiceProviderType)
case string(OFREPProviderType):
return string(OFREPProviderType)
default:
cfg.Logger.Warn("invalid provider type", "provider", in)
cfg.Logger.Info("using static provider for openfeature")
return string(StaticProviderType)
}
})
cfg.OpenFeature.ProviderType = OpenFeatureProviderType(providerType)
strURL := config.Key("url").MustString("")
defaultTargetingKey := "default"