flagnetic 0.1.2__tar.gz → 0.1.3__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.
- {flagnetic-0.1.2 → flagnetic-0.1.3}/PKG-INFO +1 -1
- {flagnetic-0.1.2 → flagnetic-0.1.3}/src/flagnetic/_client.py +5 -0
- {flagnetic-0.1.2 → flagnetic-0.1.3}/src/flagnetic/_delivery.py +23 -2
- {flagnetic-0.1.2 → flagnetic-0.1.3}/src/flagnetic/_ingest.py +2 -2
- {flagnetic-0.1.2 → flagnetic-0.1.3}/src/flagnetic/_version.py +1 -1
- {flagnetic-0.1.2 → flagnetic-0.1.3}/tests/test_client.py +46 -1
- {flagnetic-0.1.2 → flagnetic-0.1.3}/.gitignore +0 -0
- {flagnetic-0.1.2 → flagnetic-0.1.3}/LICENSE +0 -0
- {flagnetic-0.1.2 → flagnetic-0.1.3}/README.md +0 -0
- {flagnetic-0.1.2 → flagnetic-0.1.3}/e2e/test_smoke.py +0 -0
- {flagnetic-0.1.2 → flagnetic-0.1.3}/pyproject.toml +0 -0
- {flagnetic-0.1.2 → flagnetic-0.1.3}/scripts/_unicode_tables/main.go +0 -0
- {flagnetic-0.1.2 → flagnetic-0.1.3}/scripts/check_dist.py +0 -0
- {flagnetic-0.1.2 → flagnetic-0.1.3}/src/flagnetic/__init__.py +0 -0
- {flagnetic-0.1.2 → flagnetic-0.1.3}/src/flagnetic/_changes.py +0 -0
- {flagnetic-0.1.2 → flagnetic-0.1.3}/src/flagnetic/_detail.py +0 -0
- {flagnetic-0.1.2 → flagnetic-0.1.3}/src/flagnetic/_eval/__init__.py +0 -0
- {flagnetic-0.1.2 → flagnetic-0.1.3}/src/flagnetic/_eval/_re2/__init__.py +0 -0
- {flagnetic-0.1.2 → flagnetic-0.1.3}/src/flagnetic/_eval/_re2/charset.py +0 -0
- {flagnetic-0.1.2 → flagnetic-0.1.3}/src/flagnetic/_eval/_re2/parser.py +0 -0
- {flagnetic-0.1.2 → flagnetic-0.1.3}/src/flagnetic/_eval/_re2/program.py +0 -0
- {flagnetic-0.1.2 → flagnetic-0.1.3}/src/flagnetic/_eval/_re2/unicode_tables.py +0 -0
- {flagnetic-0.1.2 → flagnetic-0.1.3}/src/flagnetic/_eval/_re2/vm.py +0 -0
- {flagnetic-0.1.2 → flagnetic-0.1.3}/src/flagnetic/_eval/bucket.py +0 -0
- {flagnetic-0.1.2 → flagnetic-0.1.3}/src/flagnetic/_eval/evaluate.py +0 -0
- {flagnetic-0.1.2 → flagnetic-0.1.3}/src/flagnetic/_eval/instant.py +0 -0
- {flagnetic-0.1.2 → flagnetic-0.1.3}/src/flagnetic/_eval/model.py +0 -0
- {flagnetic-0.1.2 → flagnetic-0.1.3}/src/flagnetic/_eval/operators.py +0 -0
- {flagnetic-0.1.2 → flagnetic-0.1.3}/src/flagnetic/_eval/ruleset.py +0 -0
- {flagnetic-0.1.2 → flagnetic-0.1.3}/src/flagnetic/_eval/semver.py +0 -0
- {flagnetic-0.1.2 → flagnetic-0.1.3}/src/flagnetic/_events.py +0 -0
- {flagnetic-0.1.2 → flagnetic-0.1.3}/src/flagnetic/_overrides.py +0 -0
- {flagnetic-0.1.2 → flagnetic-0.1.3}/src/flagnetic/_reporting.py +0 -0
- {flagnetic-0.1.2 → flagnetic-0.1.3}/src/flagnetic/_sse.py +0 -0
- {flagnetic-0.1.2 → flagnetic-0.1.3}/src/flagnetic/_store.py +0 -0
- {flagnetic-0.1.2 → flagnetic-0.1.3}/src/flagnetic/openfeature.py +0 -0
- {flagnetic-0.1.2 → flagnetic-0.1.3}/src/flagnetic/py.typed +0 -0
- {flagnetic-0.1.2 → flagnetic-0.1.3}/src/flagnetic/testing.py +0 -0
- {flagnetic-0.1.2 → flagnetic-0.1.3}/tests/conformance.py +0 -0
- {flagnetic-0.1.2 → flagnetic-0.1.3}/tests/large_ruleset.py +0 -0
- {flagnetic-0.1.2 → flagnetic-0.1.3}/tests/mock_server.py +0 -0
- {flagnetic-0.1.2 → flagnetic-0.1.3}/tests/protocol.py +0 -0
- {flagnetic-0.1.2 → flagnetic-0.1.3}/tests/test_async.py +0 -0
- {flagnetic-0.1.2 → flagnetic-0.1.3}/tests/test_conformance.py +0 -0
- {flagnetic-0.1.2 → flagnetic-0.1.3}/tests/test_evaluator.py +0 -0
- {flagnetic-0.1.2 → flagnetic-0.1.3}/tests/test_events.py +0 -0
- {flagnetic-0.1.2 → flagnetic-0.1.3}/tests/test_fork.py +0 -0
- {flagnetic-0.1.2 → flagnetic-0.1.3}/tests/test_openfeature.py +0 -0
- {flagnetic-0.1.2 → flagnetic-0.1.3}/tests/test_p99.py +0 -0
- {flagnetic-0.1.2 → flagnetic-0.1.3}/tests/test_protocol.py +0 -0
- {flagnetic-0.1.2 → flagnetic-0.1.3}/tests/test_regex.py +0 -0
- {flagnetic-0.1.2 → flagnetic-0.1.3}/tests/test_sse.py +0 -0
- {flagnetic-0.1.2 → flagnetic-0.1.3}/tests/test_testing.py +0 -0
- {flagnetic-0.1.2 → flagnetic-0.1.3}/tests/test_version.py +0 -0
- {flagnetic-0.1.2 → flagnetic-0.1.3}/tests/test_without_openfeature.py +0 -0
- {flagnetic-0.1.2 → flagnetic-0.1.3}/uv.lock +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: flagnetic
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.3
|
|
4
4
|
Summary: Python SDK for Flagnetic, self-hosted feature flags and experiments
|
|
5
5
|
Project-URL: Homepage, https://github.com/azverinus/flagnetic
|
|
6
6
|
Project-URL: Source, https://github.com/azverinus/flagnetic/tree/main/sdks/python
|
|
@@ -258,6 +258,11 @@ class Client:
|
|
|
258
258
|
|
|
259
259
|
if not isinstance(sdk_key, str) or not sdk_key:
|
|
260
260
|
raise ValueError("flagnetic: the SDK key is empty")
|
|
261
|
+
if not sdk_key.isascii() or not sdk_key.isprintable() or any(c.isspace() for c in sdk_key):
|
|
262
|
+
# A trailing newline from an env file is the usual cause. The key is not repeated: it is a secret.
|
|
263
|
+
raise ValueError(
|
|
264
|
+
"flagnetic: the SDK key holds whitespace or a character that cannot be part of an HTTP header"
|
|
265
|
+
)
|
|
261
266
|
if sdk_key.startswith(_CLIENT_KEY_PREFIX):
|
|
262
267
|
raise ValueError(
|
|
263
268
|
"flagnetic: a client SDK key cannot fetch the ruleset; the Python SDK needs a server key"
|
|
@@ -155,6 +155,27 @@ class Host(Protocol):
|
|
|
155
155
|
_MAX_DOUBLINGS = 64
|
|
156
156
|
|
|
157
157
|
|
|
158
|
+
class RequestNotBuilt(http.client.HTTPException):
|
|
159
|
+
"""The HTTP library refused a request: names the error, never its text, which may hold a header."""
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def send_request(
|
|
163
|
+
conn: http.client.HTTPConnection,
|
|
164
|
+
method: str,
|
|
165
|
+
path: str,
|
|
166
|
+
headers: dict[str, str],
|
|
167
|
+
body: bytes | None = None,
|
|
168
|
+
) -> None:
|
|
169
|
+
"""``conn.request`` with a refusal to build the request reported by its class alone.
|
|
170
|
+
|
|
171
|
+
``http.client`` quotes the offending header in its ``ValueError``; the Authorization header is the key.
|
|
172
|
+
"""
|
|
173
|
+
try:
|
|
174
|
+
conn.request(method, path, body=body, headers=headers)
|
|
175
|
+
except ValueError as err:
|
|
176
|
+
raise RequestNotBuilt(f"request not built: {type(err).__name__}") from None
|
|
177
|
+
|
|
178
|
+
|
|
158
179
|
def backoff_ceiling(failures: int, base: float, limit: float) -> float:
|
|
159
180
|
"""The exponential ceiling of the nth consecutive failure: the base doubling up to the limit."""
|
|
160
181
|
doublings = min(max(failures - 1, 0), _MAX_DOUBLINGS)
|
|
@@ -497,7 +518,7 @@ class Delivery:
|
|
|
497
518
|
# A close that came while connecting found no socket to shut down.
|
|
498
519
|
if self._closing.is_set():
|
|
499
520
|
return _FETCH_CLOSING
|
|
500
|
-
conn
|
|
521
|
+
send_request(conn, "GET", self._ruleset_path, headers)
|
|
501
522
|
resp = conn.getresponse()
|
|
502
523
|
status = resp.status
|
|
503
524
|
if status == 304:
|
|
@@ -590,7 +611,7 @@ class Delivery:
|
|
|
590
611
|
if self._closing.is_set():
|
|
591
612
|
conn.close()
|
|
592
613
|
return
|
|
593
|
-
conn
|
|
614
|
+
send_request(conn, "GET", self._stream_path, headers)
|
|
594
615
|
resp = conn.getresponse()
|
|
595
616
|
except TimeoutError as err:
|
|
596
617
|
conn.close()
|
|
@@ -24,7 +24,7 @@ from enum import Enum
|
|
|
24
24
|
from typing import Any
|
|
25
25
|
from urllib.parse import urlsplit
|
|
26
26
|
|
|
27
|
-
from ._delivery import API_PATH
|
|
27
|
+
from ._delivery import API_PATH, send_request
|
|
28
28
|
|
|
29
29
|
#: This SDK's name in the envelope and in the SDK inventory, as the User-Agent names it.
|
|
30
30
|
SDK_NAME = "flagnetic-python"
|
|
@@ -167,7 +167,7 @@ class Ingest:
|
|
|
167
167
|
self._conn = conn
|
|
168
168
|
deadline = time.monotonic() + self._timeout
|
|
169
169
|
try:
|
|
170
|
-
conn
|
|
170
|
+
send_request(conn, "POST", self._path, headers, body)
|
|
171
171
|
resp = conn.getresponse()
|
|
172
172
|
status = resp.status
|
|
173
173
|
if status == 202:
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
import gzip
|
|
6
|
+
import http.client
|
|
6
7
|
import json
|
|
7
8
|
import logging
|
|
8
9
|
import os
|
|
@@ -17,7 +18,7 @@ from typing import Any
|
|
|
17
18
|
import pytest
|
|
18
19
|
|
|
19
20
|
import flagnetic
|
|
20
|
-
from flagnetic import _delivery
|
|
21
|
+
from flagnetic import _delivery, _ingest
|
|
21
22
|
from mock_server import MockServer, Request, Response
|
|
22
23
|
from protocol import SDK_KEY, Logs, eventually, read, read_json
|
|
23
24
|
|
|
@@ -622,3 +623,47 @@ def test_flush_without_a_timeout_returns_when_the_thread_is_gone(
|
|
|
622
623
|
done.start()
|
|
623
624
|
done.join(5)
|
|
624
625
|
assert not done.is_alive()
|
|
626
|
+
|
|
627
|
+
|
|
628
|
+
@pytest.mark.parametrize("suffix", ["\n", "\r\n", " ", "\t", "\x00", "\x7f", "é"])
|
|
629
|
+
def test_a_key_that_is_no_header_token_is_refused_without_repeating_it(suffix: str) -> None:
|
|
630
|
+
key = SDK_KEY + suffix
|
|
631
|
+
with pytest.raises(ValueError, match="flagnetic") as refused:
|
|
632
|
+
flagnetic.Client(key, "http://127.0.0.1:1")
|
|
633
|
+
assert SDK_KEY not in str(refused.value)
|
|
634
|
+
assert SDK_KEY not in repr(refused.value)
|
|
635
|
+
|
|
636
|
+
|
|
637
|
+
def test_an_error_raised_while_building_a_request_is_named_by_its_class_only() -> None:
|
|
638
|
+
conn = http.client.HTTPConnection("127.0.0.1", 1)
|
|
639
|
+
secret = "fn_srv_secret\n"
|
|
640
|
+
with pytest.raises(http.client.HTTPException) as failed:
|
|
641
|
+
_delivery.send_request(conn, "GET", "/x", {"Authorization": f"Bearer {secret}"})
|
|
642
|
+
assert secret.strip() not in str(failed.value)
|
|
643
|
+
assert "ValueError" in str(failed.value)
|
|
644
|
+
|
|
645
|
+
|
|
646
|
+
def test_a_key_the_http_library_refuses_never_reaches_the_log(
|
|
647
|
+
clients: Any, caplog: pytest.LogCaptureFixture, monkeypatch: pytest.MonkeyPatch
|
|
648
|
+
) -> None:
|
|
649
|
+
# Construction refuses such a key; this hands one past it to show what fetch, stream and report log.
|
|
650
|
+
bad_key = SDK_KEY + "\n"
|
|
651
|
+
for target in (_delivery.Delivery, _ingest.Ingest):
|
|
652
|
+
original = target.__init__
|
|
653
|
+
|
|
654
|
+
def with_bad_key(self: Any, *args: Any, _original: Any = original, **kwargs: Any) -> None:
|
|
655
|
+
_original(self, *args, **{**kwargs, "sdk_key": bad_key})
|
|
656
|
+
|
|
657
|
+
monkeypatch.setattr(target, "__init__", with_bad_key)
|
|
658
|
+
logs = Logs()
|
|
659
|
+
with caplog.at_level(logging.DEBUG):
|
|
660
|
+
client = clients(serving(RULESET), stream=True, logger=logs, _time_divisor=100)
|
|
661
|
+
client.alias("anonymous", "d-1", "user", "u-1")
|
|
662
|
+
client.flush(timeout=2)
|
|
663
|
+
assert (
|
|
664
|
+
eventually(lambda: [] if logs.count("sse_dropped") and logs.count("fetch_failed") else ["none"])
|
|
665
|
+
== []
|
|
666
|
+
)
|
|
667
|
+
logged = repr(logs.events) + caplog.text
|
|
668
|
+
assert SDK_KEY not in logged
|
|
669
|
+
assert logs.count("evaluation_failed") == 0
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|