From d437e7f72f3790d6c82ce1d006efdd528da7402e Mon Sep 17 00:00:00 2001 From: Alexandre Chakroun <11556013+alxckn@users.noreply.github.com> Date: Tue, 23 Apr 2024 19:34:06 +0200 Subject: [PATCH] feat: Flagd provider uses structs from sdk (#24) Signed-off-by: Alexandre Chakroun --- providers/openfeature-flagd-provider/Gemfile | 2 -- .../openfeature-flagd-provider/Gemfile.lock | 4 ++-- .../lib/openfeature/flagd/provider/client.rb | 23 ++++++++++++++----- .../openfeature-flagd-provider.gemspec | 1 + 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/providers/openfeature-flagd-provider/Gemfile b/providers/openfeature-flagd-provider/Gemfile index 95ca43f..c607af6 100644 --- a/providers/openfeature-flagd-provider/Gemfile +++ b/providers/openfeature-flagd-provider/Gemfile @@ -4,5 +4,3 @@ source "https://rubygems.org" # Specify your gem's dependencies in openfeature-flagd-provider.gemspec gemspec - -gem "openfeature-sdk" diff --git a/providers/openfeature-flagd-provider/Gemfile.lock b/providers/openfeature-flagd-provider/Gemfile.lock index b50169a..23f1f95 100644 --- a/providers/openfeature-flagd-provider/Gemfile.lock +++ b/providers/openfeature-flagd-provider/Gemfile.lock @@ -3,6 +3,7 @@ PATH specs: openfeature-flagd-provider (0.0.1) grpc (~> 1.50) + openfeature-sdk (~> 0.3) GEM remote: https://rubygems.org/ @@ -22,7 +23,7 @@ GEM json (2.7.2) language_server-protocol (3.17.0.3) lint_roller (1.1.0) - openfeature-sdk (0.3.0) + openfeature-sdk (0.3.1) parallel (1.24.0) parser (3.3.0.5) ast (~> 2.4.1) @@ -82,7 +83,6 @@ PLATFORMS DEPENDENCIES openfeature-flagd-provider! - openfeature-sdk rake (~> 13.0) rspec (~> 3.12.0) rubocop diff --git a/providers/openfeature-flagd-provider/lib/openfeature/flagd/provider/client.rb b/providers/openfeature-flagd-provider/lib/openfeature/flagd/provider/client.rb index e9a98b8..691ee6b 100644 --- a/providers/openfeature-flagd-provider/lib/openfeature/flagd/provider/client.rb +++ b/providers/openfeature-flagd-provider/lib/openfeature/flagd/provider/client.rb @@ -37,7 +37,7 @@ class Client attr_reader :metadata def initialize(configuration: nil) - @metadata = Metadata.new(PROVIDER_NAME) + @metadata = OpenFeature::SDK::Provider::ProviderMetadata.new(name: PROVIDER_NAME) @grpc_client = grpc_client(configuration) end @@ -77,12 +77,16 @@ def fetch_object_value(flag_key:, default_value:, evaluation_context: nil) private - Metadata = Struct.new("Metadata", :name) - ResolutionDetails = Struct.new("ResolutionDetails", :error_code, :error_message, :reason, :value, :variant) - def process_request(&block) response = block.call - ResolutionDetails.new(nil, nil, response.reason, response.value, response.variant) + OpenFeature::SDK::Provider::ResolutionDetails.new( + value: response.value, + reason: response.reason, + variant: response.variant, + error_code: nil, + error_message: nil, + flag_metadata: nil + ) rescue GRPC::NotFound => e error_response("FLAG_NOT_FOUND", e.message) rescue GRPC::InvalidArgument => e @@ -104,7 +108,14 @@ def prepare_evaluation_context(evaluation_context) end def error_response(error_code, error_message) - ResolutionDetails.new(error_code, error_message, "ERROR", nil, nil) + OpenFeature::SDK::Provider::ResolutionDetails.new( + value: nil, + reason: "ERROR", + variant: nil, + error_code: error_code, + error_message: error_message, + flag_metadata: nil + ) end def grpc_client(configuration) diff --git a/providers/openfeature-flagd-provider/openfeature-flagd-provider.gemspec b/providers/openfeature-flagd-provider/openfeature-flagd-provider.gemspec index 1cbfc0a..28f7ab7 100644 --- a/providers/openfeature-flagd-provider/openfeature-flagd-provider.gemspec +++ b/providers/openfeature-flagd-provider/openfeature-flagd-provider.gemspec @@ -28,6 +28,7 @@ Gem::Specification.new do |spec| spec.require_paths = ["lib"] spec.add_runtime_dependency "grpc", "~> 1.50" + spec.add_runtime_dependency "openfeature-sdk", "~> 0.3" spec.add_development_dependency "rake", "~> 13.0" spec.add_development_dependency "rspec", "~> 3.12.0"