launchdarkly-openfeature-server 0.2.0__tar.gz → 0.2.2__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.
Files changed (14) hide show
  1. {launchdarkly_openfeature_server-0.2.0 → launchdarkly_openfeature_server-0.2.2}/PKG-INFO +5 -7
  2. {launchdarkly_openfeature_server-0.2.0 → launchdarkly_openfeature_server-0.2.2}/README.md +3 -5
  3. {launchdarkly_openfeature_server-0.2.0 → launchdarkly_openfeature_server-0.2.2}/ld_openfeature/impl/context_converter.py +2 -2
  4. {launchdarkly_openfeature_server-0.2.0 → launchdarkly_openfeature_server-0.2.2}/pyproject.toml +2 -2
  5. {launchdarkly_openfeature_server-0.2.0 → launchdarkly_openfeature_server-0.2.2}/tests/impl/test_context_converter.py +35 -0
  6. {launchdarkly_openfeature_server-0.2.0 → launchdarkly_openfeature_server-0.2.2}/LICENSE +0 -0
  7. {launchdarkly_openfeature_server-0.2.0 → launchdarkly_openfeature_server-0.2.2}/ld_openfeature/__init__.py +0 -0
  8. {launchdarkly_openfeature_server-0.2.0 → launchdarkly_openfeature_server-0.2.2}/ld_openfeature/impl/details_converter.py +0 -0
  9. {launchdarkly_openfeature_server-0.2.0 → launchdarkly_openfeature_server-0.2.2}/ld_openfeature/provider.py +0 -0
  10. {launchdarkly_openfeature_server-0.2.0 → launchdarkly_openfeature_server-0.2.2}/ld_openfeature/py.typed +0 -0
  11. {launchdarkly_openfeature_server-0.2.0 → launchdarkly_openfeature_server-0.2.2}/tests/__init__.py +0 -0
  12. {launchdarkly_openfeature_server-0.2.0 → launchdarkly_openfeature_server-0.2.2}/tests/impl/test_details_converter.py +0 -0
  13. {launchdarkly_openfeature_server-0.2.0 → launchdarkly_openfeature_server-0.2.2}/tests/test_data_sources.py +0 -0
  14. {launchdarkly_openfeature_server-0.2.0 → launchdarkly_openfeature_server-0.2.2}/tests/test_provider.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: launchdarkly-openfeature-server
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: An OpenFeature provider for the LaunchDarkly Python server SDK
5
5
  Home-page: https://github.com/launchdarkly/openfeature-python-server
6
6
  License: Apache-2.0
@@ -20,7 +20,7 @@ Classifier: Topic :: Software Development
20
20
  Classifier: Topic :: Software Development :: Libraries
21
21
  Requires-Dist: launchdarkly-server-sdk (<10)
22
22
  Requires-Dist: openfeature-sdk (>=0.7.0,<1)
23
- Project-URL: Documentation, https://launchdarkly-openfeature-server.readthedocs.io/en/latest/
23
+ Project-URL: Documentation, https://launchdarkly-openfeature-python-sdk.readthedocs.io/en/latest/
24
24
  Project-URL: Repository, https://github.com/launchdarkly/openfeature-python-server
25
25
  Description-Content-Type: text/markdown
26
26
 
@@ -40,7 +40,7 @@ This provider is designed primarily for use in multi-user systems such as web se
40
40
  > This is a beta version. The API is not stabilized and may introduce breaking changes.
41
41
 
42
42
  > [!NOTE]
43
- > This OpenFeature provider uses production versions of the LaunchDarkly SDK, which adhere to our standard [versioning policy](https://docs.launchdarkly.com/home/relay-proxy/versioning).
43
+ > This OpenFeature provider uses production versions of the LaunchDarkly SDK, which adhere to our standard [versioning policy](https://docs.launchdarkly.com/sdk/concepts/versioning).
44
44
 
45
45
  # LaunchDarkly overview
46
46
 
@@ -65,13 +65,11 @@ $ pip install launchdarkly-openfeature-server
65
65
  ### Usage
66
66
 
67
67
  ```python
68
- from ldclient import Config, LDClient
68
+ from ldclient import Config
69
69
  from ld_openfeature import LaunchDarklyProvider
70
- from openfeature.evaluation_context import EvaluationContext
71
70
  from openfeature import api
72
71
 
73
- ld_client = LDClient(config=Config("sdk-key"))
74
- openfeature_provider = LaunchDarklyProvider(ld_client)
72
+ openfeature_provider = LaunchDarklyProvider(Config("sdk-key"))
75
73
 
76
74
  api.set_provider(openfeature_provider)
77
75
 
@@ -14,7 +14,7 @@ This provider is designed primarily for use in multi-user systems such as web se
14
14
  > This is a beta version. The API is not stabilized and may introduce breaking changes.
15
15
 
16
16
  > [!NOTE]
17
- > This OpenFeature provider uses production versions of the LaunchDarkly SDK, which adhere to our standard [versioning policy](https://docs.launchdarkly.com/home/relay-proxy/versioning).
17
+ > This OpenFeature provider uses production versions of the LaunchDarkly SDK, which adhere to our standard [versioning policy](https://docs.launchdarkly.com/sdk/concepts/versioning).
18
18
 
19
19
  # LaunchDarkly overview
20
20
 
@@ -39,13 +39,11 @@ $ pip install launchdarkly-openfeature-server
39
39
  ### Usage
40
40
 
41
41
  ```python
42
- from ldclient import Config, LDClient
42
+ from ldclient import Config
43
43
  from ld_openfeature import LaunchDarklyProvider
44
- from openfeature.evaluation_context import EvaluationContext
45
44
  from openfeature import api
46
45
 
47
- ld_client = LDClient(config=Config("sdk-key"))
48
- openfeature_provider = LaunchDarklyProvider(ld_client)
46
+ openfeature_provider = LaunchDarklyProvider(Config("sdk-key"))
49
47
 
50
48
  api.set_provider(openfeature_provider)
51
49
 
@@ -49,7 +49,7 @@ class EvaluationContextConverter:
49
49
  if key is not None and isinstance(key, str):
50
50
  targeting_key = targeting_key if targeting_key else key
51
51
 
52
- if targeting_key is None or targeting_key == "":
52
+ if targeting_key is None or targeting_key == "" or not isinstance(targeting_key, str):
53
53
  logger.error("The EvaluationContext must contain either a 'targetingKey' or a 'key' and the type must be a string.")
54
54
 
55
55
  return targeting_key if targeting_key else ""
@@ -83,7 +83,7 @@ class EvaluationContextConverter:
83
83
  builder.kind(kind)
84
84
 
85
85
  for k, v in attributes.items():
86
- if k == 'key' or k == 'targetingKey':
86
+ if k == 'key' or k == 'targetingKey' or k == 'kind':
87
87
  continue
88
88
 
89
89
  if k == 'name' and isinstance(v, str):
@@ -1,12 +1,12 @@
1
1
  [tool.poetry]
2
2
  name = "launchdarkly-openfeature-server"
3
- version = "0.2.0"
3
+ version = "0.2.2"
4
4
  description = "An OpenFeature provider for the LaunchDarkly Python server SDK"
5
5
  authors = ["LaunchDarkly <dev@launchdarkly.com>"]
6
6
  license = "Apache-2.0"
7
7
  readme = "README.md"
8
8
  repository = "https://github.com/launchdarkly/openfeature-python-server"
9
- documentation = "https://launchdarkly-openfeature-server.readthedocs.io/en/latest/"
9
+ documentation = "https://launchdarkly-openfeature-python-sdk.readthedocs.io/en/latest/"
10
10
  classifiers = [
11
11
  "Intended Audience :: Developers",
12
12
  "License :: OSI Approved :: Apache Software License",
@@ -28,6 +28,16 @@ def test_create_context_with_invalid_key(context_converter: EvaluationContextCon
28
28
  assert caplog.records[0].message == "A non-string 'key' attribute was provided."
29
29
 
30
30
 
31
+ def test_create_context_with_invalid_targeting_key(context_converter: EvaluationContextConverter, caplog):
32
+ context = EvaluationContext(False) # type: ignore[arg-type]
33
+ ld_context = context_converter.to_ld_context(context)
34
+
35
+ assert ld_context.valid is False
36
+ assert ld_context.key == ''
37
+
38
+ assert caplog.records[0].message == "The EvaluationContext must contain either a 'targetingKey' or a 'key' and the type must be a string."
39
+
40
+
31
41
  def test_invalid_private_attribute_types_are_ignored(context_converter: EvaluationContextConverter, caplog):
32
42
  context = EvaluationContext("user-key", {"privateAttributes": [True]})
33
43
  ld_context = context_converter.to_ld_context(context)
@@ -156,6 +166,31 @@ def test_can_create_multi_kind_context(context_converter: EvaluationContextConve
156
166
  assert org_context.name == 'Org name'
157
167
 
158
168
 
169
+ def test_can_multi_kind_ignores_kind_attribute(context_converter: EvaluationContextConverter):
170
+ attributes = {
171
+ 'kind': 'multi',
172
+ 'user': {'key': 'user-key', 'kind': 'device', 'name': 'User name'},
173
+ 'org': {'key': 'org-key', 'name': 'Org name'},
174
+ }
175
+ context = EvaluationContext(None, attributes)
176
+ ld_context = context_converter.to_ld_context(context)
177
+
178
+ assert ld_context.valid is True
179
+ assert ld_context.multiple is True
180
+
181
+ user_context = ld_context.get_individual_context('user')
182
+ assert user_context is not None
183
+ assert user_context.key == 'user-key'
184
+ assert user_context.kind == 'user'
185
+ assert user_context.name == 'User name'
186
+
187
+ org_context = ld_context.get_individual_context('org')
188
+ assert org_context is not None
189
+ assert org_context.key == 'org-key'
190
+ assert org_context.kind == 'org'
191
+ assert org_context.name == 'Org name'
192
+
193
+
159
194
  def test_multi_context_discards_invalid_single_kind(context_converter: EvaluationContextConverter):
160
195
  attributes = {
161
196
  'kind': 'multi',