flagsmith 3.8.0__tar.gz → 3.9.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: flagsmith
3
- Version: 3.8.0
3
+ Version: 3.9.0
4
4
  Summary: Flagsmith Python SDK
5
5
  License: BSD3
6
6
  Keywords: feature,flag,flagsmith,remote,config
@@ -12,7 +12,6 @@ Classifier: Programming Language :: Python :: 3
12
12
  Classifier: Programming Language :: Python :: 3.9
13
13
  Classifier: Programming Language :: Python :: 3.10
14
14
  Classifier: Programming Language :: Python :: 3.11
15
- Classifier: Programming Language :: Python :: 3.12
16
15
  Requires-Dist: flagsmith-flag-engine (>=5.1.0,<6.0.0)
17
16
  Requires-Dist: pydantic (>=2,<3)
18
17
  Requires-Dist: requests (>=2.32.3,<3.0.0)
@@ -0,0 +1,4 @@
1
+ from . import webhooks
2
+ from .flagsmith import Flagsmith
3
+
4
+ __all__ = ("Flagsmith", "webhooks")
@@ -0,0 +1,41 @@
1
+ import hashlib
2
+ import hmac
3
+ from typing import Union
4
+
5
+
6
+ def generate_signature(
7
+ request_body: Union[str, bytes],
8
+ shared_secret: str,
9
+ ) -> str:
10
+ """Generates a signature for a webhook request body using HMAC-SHA256.
11
+
12
+ :param request_body: The raw request body, as string or bytes.
13
+ :param shared_secret: The shared secret configured for this specific webhook.
14
+ :return: The hex-encoded signature.
15
+ """
16
+ if isinstance(request_body, str):
17
+ request_body = request_body.encode()
18
+
19
+ shared_secret_bytes = shared_secret.encode()
20
+
21
+ return hmac.new(
22
+ key=shared_secret_bytes,
23
+ msg=request_body,
24
+ digestmod=hashlib.sha256,
25
+ ).hexdigest()
26
+
27
+
28
+ def verify_signature(
29
+ request_body: Union[str, bytes],
30
+ received_signature: str,
31
+ shared_secret: str,
32
+ ) -> bool:
33
+ """Verifies a webhook's signature to determine if the request was sent by Flagsmith.
34
+
35
+ :param request_body: The raw request body, as string or bytes.
36
+ :param received_signature: The signature as received in the X-Flagsmith-Signature request header.
37
+ :param shared_secret: The shared secret configured for this specific webhook.
38
+ :return: True if the signature is valid, False otherwise.
39
+ """
40
+ expected_signature = generate_signature(request_body, shared_secret)
41
+ return hmac.compare_digest(expected_signature, received_signature)
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "flagsmith"
3
- version = "3.8.0"
3
+ version = "3.9.0"
4
4
  description = "Flagsmith Python SDK"
5
5
  authors = ["Flagsmith <support@flagsmith.com>"]
6
6
  license = "BSD3"
@@ -1,3 +0,0 @@
1
- from .flagsmith import Flagsmith
2
-
3
- __all__ = ("Flagsmith",)
File without changes
File without changes
File without changes
File without changes
File without changes