diff --git a/providers/openfeature-go-feature-flag-provider/lib/openfeature/go-feature-flag/go_feature_flag_provider.rb b/providers/openfeature-go-feature-flag-provider/lib/openfeature/go-feature-flag/go_feature_flag_provider.rb index 3ac64fc..9cb6f24 100644 --- a/providers/openfeature-go-feature-flag-provider/lib/openfeature/go-feature-flag/go_feature_flag_provider.rb +++ b/providers/openfeature-go-feature-flag-provider/lib/openfeature/go-feature-flag/go_feature_flag_provider.rb @@ -7,10 +7,10 @@ class Provider PROVIDER_NAME = "GO Feature Flag Provider" attr_reader :metadata, :options - def initialize(options: OpenFeature::GoFeatureFlag::Options.new) - @metadata = OpenFeature::SDK::Provider::ProviderMetadata.new(name: PROVIDER_NAME) + def initialize(options: Options.new) + @metadata = SDK::Provider::ProviderMetadata.new(name: PROVIDER_NAME) @options = options - @goff_api = OpenFeature::GoFeatureFlag::GoFeatureFlagApi.new(options: options) + @goff_api = GoFeatureFlagApi.new(options: options) end def fetch_boolean_value(flag_key:, default_value:, evaluation_context: nil) @@ -37,10 +37,10 @@ def evaluate(flag_key:, default_value:, allowed_classes:, evaluation_context: ni # do a http call to the go feature flag server parsed_response = @goff_api.evaluate_ofrep_api(flag_key: flag_key, evaluation_context: evaluation_context) - parsed_response = OpenFeature::GoFeatureFlag::OfrepApiResponse unless parsed_response.is_a?(OpenFeature::GoFeatureFlag::OfrepApiResponse) + parsed_response = OfrepApiResponse unless parsed_response.is_a?(OfrepApiResponse) if parsed_response.has_error? - return OpenFeature::SDK::Provider::ResolutionDetails.new( + return SDK::Provider::ResolutionDetails.new( value: default_value, error_code: parsed_response.error_code, error_message: parsed_response.error_details, @@ -49,39 +49,39 @@ def evaluate(flag_key:, default_value:, allowed_classes:, evaluation_context: ni end unless allowed_classes.include?(parsed_response.value.class) - return OpenFeature::SDK::Provider::ResolutionDetails.new( + return SDK::Provider::ResolutionDetails.new( value: default_value, - error_code: OpenFeature::SDK::Provider::ErrorCode::TYPE_MISMATCH, + error_code: SDK::Provider::ErrorCode::TYPE_MISMATCH, error_message: "flag type #{parsed_response.value.class} does not match allowed types #{allowed_classes}", - reason: OpenFeature::SDK::Provider::Reason::ERROR + reason: SDK::Provider::Reason::ERROR ) end - OpenFeature::SDK::Provider::ResolutionDetails.new( + SDK::Provider::ResolutionDetails.new( value: parsed_response.value, reason: parsed_response.reason, variant: parsed_response.variant, flag_metadata: parsed_response.metadata ) - rescue OpenFeature::GoFeatureFlag::UnauthorizedError, - OpenFeature::GoFeatureFlag::InvalidOptionError, - OpenFeature::GoFeatureFlag::FlagNotFoundError, - OpenFeature::GoFeatureFlag::InternalServerError => e - OpenFeature::SDK::Provider::ResolutionDetails.new( + rescue UnauthorizedError, + InvalidOptionError, + FlagNotFoundError, + InternalServerError => e + SDK::Provider::ResolutionDetails.new( value: default_value, error_code: e.error_code, error_message: e.error_message, - reason: OpenFeature::SDK::Provider::Reason::ERROR + reason: SDK::Provider::Reason::ERROR ) end def validate_parameters(flag_key, evaluation_context) if evaluation_context.nil? || evaluation_context.targeting_key.nil? || evaluation_context.targeting_key.empty? - raise OpenFeature::GoFeatureFlag::InvalidOptionError.new(OpenFeature::SDK::Provider::ErrorCode::INVALID_CONTEXT, "invalid evaluation context provided") + raise InvalidOptionError.new(SDK::Provider::ErrorCode::INVALID_CONTEXT, "invalid evaluation context provided") end if flag_key.nil? || flag_key.empty? - raise OpenFeature::GoFeatureFlag::InvalidOptionError.new(OpenFeature::SDK::Provider::ErrorCode::GENERAL, "invalid flag key provided") + raise InvalidOptionError.new(SDK::Provider::ErrorCode::GENERAL, "invalid flag key provided") end end end diff --git a/providers/openfeature-go-feature-flag-provider/lib/openfeature/go-feature-flag/goff_api.rb b/providers/openfeature-go-feature-flag-provider/lib/openfeature/go-feature-flag/goff_api.rb index 3905985..ffa8ffc 100644 --- a/providers/openfeature-go-feature-flag-provider/lib/openfeature/go-feature-flag/goff_api.rb +++ b/providers/openfeature-go-feature-flag-provider/lib/openfeature/go-feature-flag/goff_api.rb @@ -69,7 +69,7 @@ def parse_error_response(response) OpenFeature::GoFeatureFlag::OfrepApiResponse.new( value: nil, key: parsed["key"], - reason: OpenFeature::SDK::Provider::Reason::ERROR, + reason: SDK::Provider::Reason::ERROR, variant: nil, error_code: error_code_mapper(parsed["error_code"]), error_details: parsed["error_details"], @@ -100,31 +100,31 @@ def parse_success_response(response) def reason_mapper(reason_str) reason_str = reason_str.upcase reason_map = { - "STATIC" => OpenFeature::SDK::Provider::Reason::STATIC, - "DEFAULT" => OpenFeature::SDK::Provider::Reason::DEFAULT, - "TARGETING_MATCH" => OpenFeature::SDK::Provider::Reason::TARGETING_MATCH, - "SPLIT" => OpenFeature::SDK::Provider::Reason::SPLIT, - "CACHED" => OpenFeature::SDK::Provider::Reason::CACHED, - "DISABLED" => OpenFeature::SDK::Provider::Reason::DISABLED, - "UNKNOWN" => OpenFeature::SDK::Provider::Reason::UNKNOWN, - "STALE" => OpenFeature::SDK::Provider::Reason::STALE, - "ERROR" => OpenFeature::SDK::Provider::Reason::ERROR + "STATIC" => SDK::Provider::Reason::STATIC, + "DEFAULT" => SDK::Provider::Reason::DEFAULT, + "TARGETING_MATCH" => SDK::Provider::Reason::TARGETING_MATCH, + "SPLIT" => SDK::Provider::Reason::SPLIT, + "CACHED" => SDK::Provider::Reason::CACHED, + "DISABLED" => SDK::Provider::Reason::DISABLED, + "UNKNOWN" => SDK::Provider::Reason::UNKNOWN, + "STALE" => SDK::Provider::Reason::STALE, + "ERROR" => SDK::Provider::Reason::ERROR } - reason_map[reason_str] || OpenFeature::SDK::Provider::Reason::UNKNOWN + reason_map[reason_str] || SDK::Provider::Reason::UNKNOWN end def error_code_mapper(error_code_str) error_code_str = error_code_str.upcase error_code_map = { - "PROVIDER_NOT_READY" => OpenFeature::SDK::Provider::ErrorCode::PROVIDER_NOT_READY, - "FLAG_NOT_FOUND" => OpenFeature::SDK::Provider::ErrorCode::FLAG_NOT_FOUND, - "PARSE_ERROR" => OpenFeature::SDK::Provider::ErrorCode::PARSE_ERROR, - "TYPE_MISMATCH" => OpenFeature::SDK::Provider::ErrorCode::TYPE_MISMATCH, - "TARGETING_KEY_MISSING" => OpenFeature::SDK::Provider::ErrorCode::TARGETING_KEY_MISSING, - "INVALID_CONTEXT" => OpenFeature::SDK::Provider::ErrorCode::INVALID_CONTEXT, - "GENERAL" => OpenFeature::SDK::Provider::ErrorCode::GENERAL + "PROVIDER_NOT_READY" => SDK::Provider::ErrorCode::PROVIDER_NOT_READY, + "FLAG_NOT_FOUND" => SDK::Provider::ErrorCode::FLAG_NOT_FOUND, + "PARSE_ERROR" => SDK::Provider::ErrorCode::PARSE_ERROR, + "TYPE_MISMATCH" => SDK::Provider::ErrorCode::TYPE_MISMATCH, + "TARGETING_KEY_MISSING" => SDK::Provider::ErrorCode::TARGETING_KEY_MISSING, + "INVALID_CONTEXT" => SDK::Provider::ErrorCode::INVALID_CONTEXT, + "GENERAL" => SDK::Provider::ErrorCode::GENERAL } - error_code_map[error_code_str] || OpenFeature::SDK::Provider::ErrorCode::GENERAL + error_code_map[error_code_str] || SDK::Provider::ErrorCode::GENERAL end def parse_retry_later_header(response)