gofeatureflag-python-provider 0.2.0__tar.gz → 0.3.0__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: gofeatureflag-python-provider
3
- Version: 0.2.0
3
+ Version: 0.3.0
4
4
  Summary: GO Feature Flag provider for OpenFeature
5
5
  Home-page: https://gofeatureflag.org
6
6
  License: Apache-2.0
@@ -13,6 +13,7 @@ Classifier: Programming Language :: Python :: 3.9
13
13
  Classifier: Programming Language :: Python :: 3.10
14
14
  Classifier: Programming Language :: Python :: 3.11
15
15
  Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
16
17
  Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
17
18
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
18
19
  Requires-Dist: asyncio (>=3.4.3,<4.0.0)
@@ -63,8 +63,8 @@ class DataCollectorHook(Hook):
63
63
  self._event_queue.append(feature_event)
64
64
 
65
65
  def error(self, hook_context: HookContext, exception: Exception, hints: dict):
66
- if self._options.disable_data_collection or details.reason != Reason.CACHED:
67
- # we don't collect data if the data collection is disabled or if the flag is not cached
66
+ if self._options.disable_data_collection:
67
+ # we don't collect data if the data collection is disabled
68
68
  return
69
69
 
70
70
  feature_event = FeatureEvent(
@@ -109,10 +109,14 @@ class DataCollectorHook(Hook):
109
109
  meta={"provider": "open-feature-python-sdk"},
110
110
  events=self._event_queue,
111
111
  )
112
+ headers = {"Content-Type": "application/json"}
113
+ if self._options.api_key:
114
+ headers["Authorization"] = "Bearer {}".format(self._options.api_key)
115
+
112
116
  response = self._http_client.request(
113
117
  method="POST",
114
118
  url=urljoin(str(self._options.endpoint), "/v1/data/collector"),
115
- headers={"Content-Type": "application/json"},
119
+ headers=headers,
116
120
  body=goff_request.model_dump_json(),
117
121
  )
118
122
 
@@ -45,3 +45,8 @@ class GoFeatureFlagOptions(BaseModel):
45
45
  # config changes.
46
46
  # default: false
47
47
  disable_cache_invalidation: typing.Optional[bool] = False
48
+
49
+ # api_key (optional) If the relay proxy is configured to authenticate the requests, you should provide
50
+ # an API Key to the provider. Please ask the administrator of the relay proxy to provide an API Key.
51
+ # Default: None
52
+ api_key: typing.Optional[str] = None
@@ -188,13 +188,18 @@ class GoFeatureFlagProvider(BaseModel, AbstractProvider, metaclass=CombinedMetac
188
188
  response_body = self._cache[evaluation_context_hash]
189
189
  is_from_cache = True
190
190
  else:
191
+ headers = {"Content-Type": "application/json"}
192
+ if self.options.api_key is not None:
193
+ headers["Authorization"] = "Bearer {}".format(self.options.api_key)
194
+ url = "{}{}".format(
195
+ str(self.options.endpoint).rstrip("/"),
196
+ "/v1/feature/{}/eval".format(flag_key),
197
+ )
198
+
191
199
  response = self._http_client.request(
192
200
  method="POST",
193
- url=urljoin(
194
- str(self.options.endpoint),
195
- "/v1/feature/{}/eval".format(flag_key),
196
- ),
197
- headers={"Content-Type": "application/json"},
201
+ url=url,
202
+ headers=headers,
198
203
  body=goff_request.model_dump_json(),
199
204
  )
200
205
 
@@ -261,10 +266,15 @@ class GoFeatureFlagProvider(BaseModel, AbstractProvider, metaclass=CombinedMetac
261
266
  _build_websocket_uri is a helper to build the websocket uri to connect to the GO Feature Flag relay proxy.
262
267
  :return: a string representing the websocket uri
263
268
  """
264
- http_uri = urljoin(
265
- str(self.options.endpoint),
266
- "/ws/v1/flag/change",
269
+ url = "/ws/v1/flag/change"
270
+ if self.options.api_key is not None:
271
+ url = "{}?apiKey={}".format(url, self.options.api_key)
272
+
273
+ http_uri = "{}{}".format(
274
+ str(self.options.endpoint).rstrip("/"),
275
+ url,
267
276
  )
277
+
268
278
  http_uri = http_uri.replace("http", "ws")
269
279
  http_uri = http_uri.replace("https", "wss")
270
280
  return http_uri
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "gofeatureflag-python-provider"
3
- version = "0.2.0"
3
+ version = "0.3.0"
4
4
  description = "GO Feature Flag provider for OpenFeature"
5
5
  license = "Apache-2.0"
6
6
  authors = [ "Thomas Poignant" ]