FF: enumerate provider types and default to static for invalid
This commit is contained in:
@@ -11,6 +11,9 @@ import (
|
||||
_ "github.com/Azure/azure-sdk-for-go/services/keyvault/v7.1/keyvault"
|
||||
_ "github.com/Azure/go-autorest/autorest"
|
||||
_ "github.com/Azure/go-autorest/autorest/adal"
|
||||
_ "github.com/aws/aws-sdk-go-v2/credentials"
|
||||
_ "github.com/aws/aws-sdk-go-v2/service/secretsmanager"
|
||||
_ "github.com/aws/aws-sdk-go-v2/service/sts"
|
||||
_ "github.com/beevik/etree"
|
||||
_ "github.com/blugelabs/bluge"
|
||||
_ "github.com/blugelabs/bluge_segment_api"
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user