diff --git a/.gitignore b/.gitignore index 74d9d73..ece0b0a 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,9 @@ /test/version_tmp/ /tmp/ +#rspec +**/spec/examples.txt + # Used by dotenv library to load environment variables. # .env @@ -58,4 +61,4 @@ build-iPhoneSimulator/ .DS_Store # Ignore jetbrains files -.idea/ \ No newline at end of file +.idea/ diff --git a/providers/openfeature-go-feature-flag-provider/Gemfile.lock b/providers/openfeature-go-feature-flag-provider/Gemfile.lock index d5e4fad..5f47e64 100644 --- a/providers/openfeature-go-feature-flag-provider/Gemfile.lock +++ b/providers/openfeature-go-feature-flag-provider/Gemfile.lock @@ -2,7 +2,7 @@ PATH remote: . specs: openfeature-go-feature-flag-provider (0.1.3) - faraday (~> 2.10) + faraday-net_http_persistent (~> 2.3) openfeature-sdk (~> 0.3.1) GEM @@ -12,24 +12,30 @@ GEM public_suffix (>= 2.0.2, < 7.0) ast (2.4.2) bigdecimal (3.1.8) + connection_pool (2.5.3) crack (1.0.0) bigdecimal rexml diff-lcs (1.5.1) docile (1.4.1) - faraday (2.12.1) + faraday (2.13.4) faraday-net_http (>= 2.0, < 3.5) json logger - faraday-net_http (3.4.0) + faraday-net_http (3.4.1) net-http (>= 0.5.0) + faraday-net_http_persistent (2.3.1) + faraday (~> 2.5) + net-http-persistent (>= 4.0.4, < 5) hashdiff (1.1.1) - json (2.7.2) + json (2.13.2) language_server-protocol (3.17.0.3) lint_roller (1.1.0) - logger (1.6.1) - net-http (0.5.0) + logger (1.7.0) + net-http (0.6.0) uri + net-http-persistent (4.0.6) + connection_pool (~> 2.2, >= 2.2.4) openfeature-sdk (0.3.1) parallel (1.24.0) parser (3.3.0.5) @@ -92,7 +98,7 @@ GEM rubocop-performance (~> 1.20.2) strscan (3.1.0) unicode-display_width (2.5.0) - uri (1.0.2) + uri (1.0.3) webmock (3.23.1) addressable (>= 2.8.0) crack (>= 0.3.2) 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 dc00f78..cb92266 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 @@ -10,7 +10,7 @@ class Provider def initialize(options: Options.new) @metadata = SDK::Provider::ProviderMetadata.new(name: PROVIDER_NAME) @options = options - @goff_api = GoFeatureFlagApi.new(options: options) + @goff_api = GoFeatureFlagApi.new(endpoint: options.endpoint, custom_headers: options.custom_headers) end def fetch_boolean_value(flag_key:, default_value:, evaluation_context: nil) 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 ffa8ffc..40f7586 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 @@ -3,7 +3,7 @@ require "open_feature/sdk" require "net/http" require "json" -require "faraday" +require "faraday/net_http_persistent" require_relative "error/errors" require_relative "model/ofrep_api_response" @@ -11,13 +11,12 @@ module OpenFeature module GoFeatureFlag # This class is the entry point for the GoFeatureFlagProvider class GoFeatureFlagApi - attr_reader :options - def initialize(options: {}) - @options = options - @faraday_connection = Faraday.new( - url: @options.endpoint, - headers: {"Content-Type" => "application/json"}.merge(@options.custom_headers || {}) - ) + def initialize(endpoint: nil, custom_headers: nil) + @faraday_connection = Faraday.new(url: endpoint, headers: headers(custom_headers)) do |f| + f.adapter :net_http_persistent do |http| + http.idle_timeout = 30 + end + end end def evaluate_ofrep_api(flag_key:, evaluation_context:) @@ -57,6 +56,10 @@ def evaluate_ofrep_api(flag_key:, evaluation_context:) private + def headers(custom_headers) + {"Content-Type" => "application/json"}.merge(custom_headers || {}) + end + def parse_error_response(response) required_keys = %w[key error_code] parsed = JSON.parse(response.body) diff --git a/providers/openfeature-go-feature-flag-provider/openfeature-go-feature-flag-provider.gemspec b/providers/openfeature-go-feature-flag-provider/openfeature-go-feature-flag-provider.gemspec index 33e03ef..fd4f6dc 100644 --- a/providers/openfeature-go-feature-flag-provider/openfeature-go-feature-flag-provider.gemspec +++ b/providers/openfeature-go-feature-flag-provider/openfeature-go-feature-flag-provider.gemspec @@ -30,7 +30,7 @@ Gem::Specification.new do |spec| spec.require_paths = ["lib"] spec.add_runtime_dependency "openfeature-sdk", "~> 0.3.1" - spec.add_runtime_dependency "faraday", "~> 2.10" + spec.add_runtime_dependency "faraday-net_http_persistent", "~> 2.3" spec.add_development_dependency "rake", "~> 13.0" spec.add_development_dependency "rspec", "~> 3.12.0" diff --git a/providers/openfeature-go-feature-flag-provider/spec/openfeature/gofeatureflag/goff_api_spec.rb b/providers/openfeature-go-feature-flag-provider/spec/openfeature/gofeatureflag/goff_api_spec.rb index ec939f7..0573a66 100644 --- a/providers/openfeature-go-feature-flag-provider/spec/openfeature/gofeatureflag/goff_api_spec.rb +++ b/providers/openfeature-go-feature-flag-provider/spec/openfeature/gofeatureflag/goff_api_spec.rb @@ -2,8 +2,7 @@ RSpec.describe OpenFeature::GoFeatureFlag::GoFeatureFlagApi do subject(:goff_api) do - options = OpenFeature::GoFeatureFlag::Options.new(endpoint: "http://localhost:1031") - described_class.new(options: options) + described_class.new(endpoint: "http://localhost:1031") end let(:default_evaluation_context) do