Skip to content

Commit 505ab99

Browse files
authored
Merge pull request #538 from splitio/development
Release 10.0.0
2 parents 325a0f6 + 4d4baca commit 505ab99

File tree

138 files changed

+29855
-4166
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+29855
-4166
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
- name: Setup Python
3232
uses: actions/setup-python@v3
3333
with:
34-
python-version: '3.7'
34+
python-version: '3.7.16'
3535

3636
- name: Install dependencies
3737
run: |

CHANGES.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
10.0.0 (Jun 27, 2024)
2+
- Added support for asyncio library
3+
- BREAKING CHANGE: Minimum supported Python version is 3.7.16
4+
15
9.7.0 (May 15, 2024)
26
- Added support for targeting rules based on semantic versions (https://semver.org/).
37
- Added the logic to handle correctly when the SDK receives an unsupported Matcher type.

setup.cfg

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
universal = 1
33

44
[metadata]
5-
description-file = README.md
5+
name = splitio_client
6+
description = This SDK is designed to work with Split, the platform for controlled rollouts, which serves features to your users via a Split feature flag to manage your complete customer experience.
7+
long_description = file: README.md
8+
long_description_content_type = text/markdown
69

710
[flake8]
811
max-line-length=100
@@ -12,7 +15,6 @@ exclude=tests/*
1215
test=pytest
1316

1417
[tool:pytest]
15-
ignore_glob=./splitio/_OLD/*
1618
addopts = --verbose --cov=splitio --cov-report xml
1719
python_classes=*Tests
1820

setup.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,24 @@
66

77
TESTS_REQUIRES = [
88
'flake8',
9-
'pytest==7.1.0',
9+
'pytest==7.0.1',
1010
'pytest-mock==3.11.1',
11-
'coverage==7.2.7',
12-
'pytest-cov',
11+
'coverage',
12+
'pytest-cov==4.1.0',
1313
'importlib-metadata==6.7',
14-
'tomli',
15-
'iniconfig',
16-
'attrs'
14+
'tomli==1.2.3',
15+
'iniconfig==1.1.1',
16+
'attrs==22.1.0',
17+
'pytest-asyncio==0.21.0',
18+
'aiohttp>=3.8.4',
19+
'aiofiles>=23.1.0'
1720
]
1821

1922
INSTALL_REQUIRES = [
2023
'requests',
2124
'pyyaml',
2225
'docopt>=0.6.2',
26+
'enum34;python_version<"3.4"',
2327
'bloom-filter2>=2.0.0'
2428
]
2529

@@ -42,8 +46,9 @@
4246
'redis': ['redis>=2.10.5'],
4347
'uwsgi': ['uwsgi>=2.0.0'],
4448
'cpphash': ['mmh3cffi==0.2.1'],
49+
'asyncio': ['aiohttp>=3.8.4', 'aiofiles>=23.1.0']
4550
},
46-
setup_requires=['pytest-runner', 'pluggy==1.0.0;python_version<"3.7"'],
51+
setup_requires=['pytest-runner', 'pluggy==1.0.0;python_version<"3.8"'],
4752
classifiers=[
4853
'Environment :: Console',
4954
'Intended Audience :: Developers',

splitio/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
from splitio.client.factory import get_factory
1+
from splitio.client.factory import get_factory, get_factory_async
22
from splitio.client.key import Key
33
from splitio.version import __version__

splitio/api/__init__.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,34 @@ def __init__(self, custom_message, status_code=None):
1313
def status_code(self):
1414
"""Return HTTP status code."""
1515
return self._status_code
16+
17+
class APIUriException(APIException):
18+
"""Exception to raise when an API call fails due to 414 http error."""
19+
20+
def __init__(self, custom_message, status_code=None):
21+
"""Constructor."""
22+
APIException.__init__(self, custom_message, status_code)
23+
24+
def headers_from_metadata(sdk_metadata, client_key=None):
25+
"""
26+
Generate a dict with headers required by data-recording API endpoints.
27+
:param sdk_metadata: SDK Metadata object, generated at sdk initialization time.
28+
:type sdk_metadata: splitio.client.util.SdkMetadata
29+
:param client_key: client key.
30+
:type client_key: str
31+
:return: A dictionary with headers.
32+
:rtype: dict
33+
"""
34+
35+
metadata = {
36+
'SplitSDKVersion': sdk_metadata.sdk_version,
37+
'SplitSDKMachineIP': sdk_metadata.instance_ip,
38+
'SplitSDKMachineName': sdk_metadata.instance_name
39+
} if sdk_metadata.instance_ip != 'NA' and sdk_metadata.instance_ip != 'unknown' else {
40+
'SplitSDKVersion': sdk_metadata.sdk_version,
41+
}
42+
43+
if client_key is not None:
44+
metadata['SplitSDKClientKey'] = client_key
45+
46+
return metadata

splitio/api/auth.py

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import logging
44
import json
55

6-
from splitio.api import APIException
6+
from splitio.api import APIException, headers_from_metadata
77
from splitio.api.commons import headers_from_metadata, record_telemetry
88
from splitio.spec import SPEC_VERSION
99
from splitio.util.time import get_current_epoch_time_ms
@@ -32,6 +32,7 @@ def __init__(self, client, sdk_key, sdk_metadata, telemetry_runtime_producer):
3232
self._sdk_key = sdk_key
3333
self._metadata = headers_from_metadata(sdk_metadata)
3434
self._telemetry_runtime_producer = telemetry_runtime_producer
35+
self._client.set_telemetry_data(HTTPExceptionsAndLatencies.TOKEN, self._telemetry_runtime_producer)
3536

3637
def authenticate(self):
3738
"""
@@ -40,18 +41,17 @@ def authenticate(self):
4041
:return: Json representation of an authentication.
4142
:rtype: splitio.models.token.Token
4243
"""
43-
start = get_current_epoch_time_ms()
4444
try:
4545
response = self._client.get(
4646
'auth',
47-
'/v2/auth?s=' + SPEC_VERSION,
47+
'v2/auth?s=' + SPEC_VERSION,
4848
self._sdk_key,
4949
extra_headers=self._metadata,
5050
)
51-
record_telemetry(response.status_code, get_current_epoch_time_ms() - start, HTTPExceptionsAndLatencies.TOKEN, self._telemetry_runtime_producer)
5251
if 200 <= response.status_code < 300:
5352
payload = json.loads(response.body)
5453
return from_raw(payload)
54+
5555
else:
5656
if (response.status_code >= 400 and response.status_code < 500):
5757
self._telemetry_runtime_producer.record_auth_rejections()
@@ -60,3 +60,50 @@ def authenticate(self):
6060
_LOGGER.error('Exception raised while authenticating')
6161
_LOGGER.debug('Exception information: ', exc_info=True)
6262
raise APIException('Could not perform authentication.') from exc
63+
64+
class AuthAPIAsync(object): # pylint: disable=too-few-public-methods
65+
"""Async Class that uses an httpClient to communicate with the SDK Auth Service API."""
66+
67+
def __init__(self, client, sdk_key, sdk_metadata, telemetry_runtime_producer):
68+
"""
69+
Class constructor.
70+
71+
:param client: HTTP Client responsble for issuing calls to the backend.
72+
:type client: HttpClient
73+
:param sdk_key: User sdk key.
74+
:type sdk_key: string
75+
:param sdk_metadata: SDK version & machine name & IP.
76+
:type sdk_metadata: splitio.client.util.SdkMetadata
77+
"""
78+
self._client = client
79+
self._sdk_key = sdk_key
80+
self._metadata = headers_from_metadata(sdk_metadata)
81+
self._telemetry_runtime_producer = telemetry_runtime_producer
82+
self._client.set_telemetry_data(HTTPExceptionsAndLatencies.TOKEN, self._telemetry_runtime_producer)
83+
84+
async def authenticate(self):
85+
"""
86+
Perform authentication.
87+
88+
:return: Json representation of an authentication.
89+
:rtype: splitio.models.token.Token
90+
"""
91+
try:
92+
response = await self._client.get(
93+
'auth',
94+
'v2/auth?s=' + SPEC_VERSION,
95+
self._sdk_key,
96+
extra_headers=self._metadata,
97+
)
98+
if 200 <= response.status_code < 300:
99+
payload = json.loads(response.body)
100+
return from_raw(payload)
101+
102+
else:
103+
if (response.status_code >= 400 and response.status_code < 500):
104+
await self._telemetry_runtime_producer.record_auth_rejections()
105+
raise APIException(response.body, response.status_code)
106+
except HttpClientException as exc:
107+
_LOGGER.error('Exception raised while authenticating')
108+
_LOGGER.debug('Exception information: ', exc_info=True)
109+
raise APIException('Could not perform authentication.') from exc

0 commit comments

Comments
 (0)