openfeature-ruby-sdk-contrib 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a769e314a26cad2d838cd2038cc0bf7c419bb341b3a1d84c8f25af1c86f431a4
4
- data.tar.gz: f5fe644274b24df571e54d2128f39de106ca0e88a7e3c8d1ec354e2ead2fdbf2
3
+ metadata.gz: aa6213b99bd5852e81c1fe7184950031c35038513eeef5ac9003694197ba1633
4
+ data.tar.gz: 3aa3234f79d229c9520580d217d8cdf859f6f95ec80967b5a63c994bea83f454
5
5
  SHA512:
6
- metadata.gz: 4295a9914e8e7be4f79e65e1879964d5ffa4ccb560b71a094f6618df9731afc39a611a199f99efa69ab759bb24b6d3e6bcd16fc6aa2a3fecac2e22e71fcb0458
7
- data.tar.gz: 01e988330d77f7ec392c53ab253622141d4e698ed1662bc8dd70aa03085d15d35980367b96502afcf6a6d35042394735952567673a34d868b2d36c6971106638
6
+ metadata.gz: 0c7d32302bfe0f293e9a7aaf00413a289ee7c0805dc76f5d623b7a0f972d156a63b5783e51a1ef55c6a39d47f6e48608d665d6d714e7161abd7e2eb37eafec08
7
+ data.tar.gz: 48828fff61ed31bc5c97fabdccdf8c578091d8eb814cb9b21ec8a77a3ede301bed6f36a7fc87b32370b93dd494d15534605eaf83444e5375eb9c2fbc2a310b5b
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- openfeature-ruby-sdk-contrib (0.1.2)
4
+ openfeature-ruby-sdk-contrib (0.3.0)
5
5
  concurrent-ruby (~> 1.2.2)
6
6
  faraday (~> 2.7.10)
7
7
  openfeature-sdk (~> 0.1)
@@ -10,11 +10,13 @@ GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
12
  ast (2.4.2)
13
+ base64 (0.2.0)
13
14
  byebug (11.1.3)
14
15
  coderay (1.1.3)
15
16
  concurrent-ruby (1.2.2)
16
17
  diff-lcs (1.5.0)
17
- faraday (2.7.10)
18
+ faraday (2.7.12)
19
+ base64
18
20
  faraday-net_http (>= 2.0, < 3.1)
19
21
  ruby2_keywords (>= 0.0.4)
20
22
  faraday-net_http (3.0.2)
@@ -22,7 +24,7 @@ GEM
22
24
  language_server-protocol (3.17.0.3)
23
25
  lint_roller (1.1.0)
24
26
  method_source (1.0.0)
25
- openfeature-sdk (0.1.0)
27
+ openfeature-sdk (0.1.1)
26
28
  parallel (1.23.0)
27
29
  parser (3.2.2.3)
28
30
  ast (~> 2.4.1)
@@ -95,6 +97,7 @@ GEM
95
97
 
96
98
  PLATFORMS
97
99
  arm64-darwin-22
100
+ arm64-darwin-23
98
101
 
99
102
  DEPENDENCIES
100
103
  openfeature-ruby-sdk-contrib!
data/README.md CHANGED
@@ -107,6 +107,32 @@ Rails.application.config.openfeature_client = OpenFeature::SDK::Contrib::Client.
107
107
  )
108
108
  ```
109
109
 
110
+ #### Custom Auth Strategy
111
+
112
+ Some applications may require more finesse to authenticate, for example, an OAuth Flow. To use this style flow, the `extra_options` key that is passed to `HttpProvider.new` accepts an `authentication_strategy` key. This key gets passed to the internal Faraday client as a middleware, so it can be anything usable as a Faraday middleware. Example:
113
+
114
+ ```
115
+ module FaradayMiddleware
116
+ class MyCustomMiddleware < Faraday::Middleware
117
+ def initialize(args)
118
+ # do stuff
119
+ end
120
+
121
+ def call(env)
122
+ @app.call(env)
123
+ end
124
+ end
125
+
126
+ Faraday::Request.register_middleware my_custom_middleware: -> { MyCustomMiddleware }
127
+ end
128
+
129
+ Rails.application.config.openfeature_provider = OpenFeature::SDK::Contrib::Providers::HttpProvider.new(
130
+ extra_options: {
131
+ authentication_strategy: [:my_custom_middleware, my_custom_middleware_arguments]
132
+ }
133
+ )
134
+ ```
135
+
110
136
  ## Development
111
137
 
112
138
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -14,6 +14,10 @@ module OpenFeature
14
14
  result = @provider.fetch_float_value(flag_key: flag_key, default_value: default_value, evaluation_context: evaluation_context)
15
15
  result.value
16
16
  end
17
+
18
+ def fetch_raw_flag(flag_key:)
19
+ @provider.fetch_raw_key(flag_key: flag_key)
20
+ end
17
21
  end
18
22
  end
19
23
  end
@@ -67,6 +67,10 @@ module OpenFeature
67
67
  @flag_contents = nil
68
68
  end
69
69
 
70
+ def fetch_raw_key(flag_key:)
71
+ read_all_values_with_cache.detect { |f| f["name"] == flag_key }
72
+ end
73
+
70
74
  # Returns a boolean value for the key specified
71
75
  #
72
76
  # @param flag_key [String] flag key to search for
@@ -151,7 +155,7 @@ module OpenFeature
151
155
  # Returns a value for the requested flag_key
152
156
  #
153
157
  # @param flag_key [String] requested flag key
154
- # @param type ["boolean", "number", "float", "string"]
158
+ # @param type ["boolean", "number", "float", "string", "array"]
155
159
  def read_value_with_cache(flag_key:, type:)
156
160
  read_all_values_with_cache.detect { |f| f["kind"] == type && f["name"] == flag_key }
157
161
  end
@@ -30,9 +30,10 @@ module OpenFeature
30
30
  NAME = "Http Provider"
31
31
 
32
32
  def read_and_parse_flags
33
- headers = extra_options.fetch(:headers, {})
34
- uri = URI(source)
35
- base_url = "#{uri.scheme}://#{uri.host}:#{uri.port}"
33
+ headers = extra_options.fetch(:headers, {})
34
+ uri = URI(source)
35
+ base_url = "#{uri.scheme}://#{uri.host}:#{uri.port}"
36
+ authentication_strategy = extra_options.delete(:authentication_strategy)
36
37
 
37
38
  if format == :yaml
38
39
  headers["Content-Type"] ||= "application/yaml"
@@ -40,8 +41,11 @@ module OpenFeature
40
41
  headers["Content-Type"] ||= "application/json"
41
42
  end
42
43
 
43
- client = Faraday.new(url: base_url, **extra_options, headers: headers)
44
- res = client.get(uri.request_uri)
44
+ client = Faraday.new(url: base_url, **extra_options, headers: headers) do |conn|
45
+ conn.request(*authentication_strategy) if authentication_strategy
46
+ end
47
+
48
+ res = client.get(uri.request_uri)
45
49
 
46
50
  return custom_parser.call(res.body) if custom_parser
47
51
 
@@ -3,7 +3,7 @@
3
3
  module OpenFeature
4
4
  module SDK
5
5
  module Contrib
6
- VERSION = "0.2.0"
6
+ VERSION = "0.4.0"
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openfeature-ruby-sdk-contrib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eugene Howe
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-10-03 00:00:00.000000000 Z
11
+ date: 2024-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -94,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
94
  - !ruby/object:Gem::Version
95
95
  version: '0'
96
96
  requirements: []
97
- rubygems_version: 3.2.33
97
+ rubygems_version: 3.3.7
98
98
  signing_key:
99
99
  specification_version: 4
100
100
  summary: Providers and Hooks for the OpenFeature Ruby SDK