From 7d9b2858d35494644c4f8dec21a825a3bbbb0d9f Mon Sep 17 00:00:00 2001 From: marwin-roth Date: Tue, 5 Nov 2024 17:37:55 +0100 Subject: [PATCH 1/5] Add first attempt of custom user agent --- emnify/api_manager.py | 3 +++ emnify/constants.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/emnify/api_manager.py b/emnify/api_manager.py index 40a97a5..d312759 100644 --- a/emnify/api_manager.py +++ b/emnify/api_manager.py @@ -44,6 +44,9 @@ def _build_headers(token=''): emnify_constants.RequestDefaultHeadersKeys.XEmnOriginAppVersion.value: emnify_constants.RequestDefaultHeadersValues.PYTHONSDK_VERSION.value, + + emnify_constants.RequestDefaultHeadersKeys.USER_AGENT.value: + emnify_constants.RequestDefaultHeadersValues.PLATFORM.value } def process_exception(self, response: requests.Response, client, data: dict = None, *args, **kwargs): diff --git a/emnify/constants.py b/emnify/constants.py index 57cbe0c..54cdf7a 100644 --- a/emnify/constants.py +++ b/emnify/constants.py @@ -1,3 +1,4 @@ +import platform from enum import Enum from emnify.version import EMNIFY_PACKAGE_VERSION @@ -39,6 +40,7 @@ class RequestDefaultHeadersKeys(ExtendedEnum): AUTHORIZATION = 'authorization' XEmnOriginApp = 'x-emn-origin-app' XEmnOriginAppVersion = 'x-emn-origin-app-version' + USER_AGENT = 'User-Agent' class RequestDefaultHeadersValues(ExtendedEnum): @@ -46,6 +48,7 @@ class RequestDefaultHeadersValues(ExtendedEnum): BEARER_TOKEN = 'Bearer {}' PYTHONSDK_VERSION = EMNIFY_PACKAGE_VERSION PYTHONSDK = 'PythonSDK' + PLATFORM = 'PythonSDK ' + '('+ platform.platform() + ')' class DeviceStatuses(ExtendedEnum): From 8b81690237a3a985f2f28722e29ef7e1ce9c7faa Mon Sep 17 00:00:00 2001 From: marwin-roth Date: Thu, 7 Nov 2024 11:10:16 +0100 Subject: [PATCH 2/5] Alter User-Agent value --- emnify/api_manager.py | 2 +- emnify/constants.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/emnify/api_manager.py b/emnify/api_manager.py index d312759..0ae9890 100644 --- a/emnify/api_manager.py +++ b/emnify/api_manager.py @@ -46,7 +46,7 @@ def _build_headers(token=''): emnify_constants.RequestDefaultHeadersValues.PYTHONSDK_VERSION.value, emnify_constants.RequestDefaultHeadersKeys.USER_AGENT.value: - emnify_constants.RequestDefaultHeadersValues.PLATFORM.value + emnify_constants.RequestDefaultHeadersValues.USER_AGENT.value } def process_exception(self, response: requests.Response, client, data: dict = None, *args, **kwargs): diff --git a/emnify/constants.py b/emnify/constants.py index 54cdf7a..2f12ae3 100644 --- a/emnify/constants.py +++ b/emnify/constants.py @@ -48,7 +48,7 @@ class RequestDefaultHeadersValues(ExtendedEnum): BEARER_TOKEN = 'Bearer {}' PYTHONSDK_VERSION = EMNIFY_PACKAGE_VERSION PYTHONSDK = 'PythonSDK' - PLATFORM = 'PythonSDK ' + '('+ platform.platform() + ')' + USER_AGENT = PYTHONSDK + '/' + PYTHONSDK_VERSION + ' ('+ platform.system() + ', ' + platform.release() + ')' class DeviceStatuses(ExtendedEnum): From 9533b31ad1d50cd86b83c949132ef2304f13ec20 Mon Sep 17 00:00:00 2001 From: marwin-roth Date: Thu, 7 Nov 2024 11:36:46 +0100 Subject: [PATCH 3/5] Add emnify to SDK name --- emnify/constants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/emnify/constants.py b/emnify/constants.py index 2f12ae3..d4e3ceb 100644 --- a/emnify/constants.py +++ b/emnify/constants.py @@ -47,7 +47,7 @@ class RequestDefaultHeadersValues(ExtendedEnum): APPLICATION_JSON = 'application/json' BEARER_TOKEN = 'Bearer {}' PYTHONSDK_VERSION = EMNIFY_PACKAGE_VERSION - PYTHONSDK = 'PythonSDK' + PYTHONSDK = 'emnify PythonSDK' USER_AGENT = PYTHONSDK + '/' + PYTHONSDK_VERSION + ' ('+ platform.system() + ', ' + platform.release() + ')' From a82c283028602002b867974d026b54273d56b1ba Mon Sep 17 00:00:00 2001 From: marwin-roth Date: Thu, 7 Nov 2024 14:07:44 +0100 Subject: [PATCH 4/5] Modify user agent name --- emnify/constants.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/emnify/constants.py b/emnify/constants.py index d4e3ceb..90f4802 100644 --- a/emnify/constants.py +++ b/emnify/constants.py @@ -1,4 +1,5 @@ import platform +import requests from enum import Enum from emnify.version import EMNIFY_PACKAGE_VERSION @@ -47,8 +48,15 @@ class RequestDefaultHeadersValues(ExtendedEnum): APPLICATION_JSON = 'application/json' BEARER_TOKEN = 'Bearer {}' PYTHONSDK_VERSION = EMNIFY_PACKAGE_VERSION - PYTHONSDK = 'emnify PythonSDK' - USER_AGENT = PYTHONSDK + '/' + PYTHONSDK_VERSION + ' ('+ platform.system() + ', ' + platform.release() + ')' + PYTHONSDK = 'emnifyPythonSDK' + + name_and_version = f"{PYTHONSDK}/{PYTHONSDK_VERSION}" + requests_user_agent = f" {requests.utils.default_user_agent()}" + python_version = f"Python {platform.python_version()}" + platform_info = f"{platform.system()}, {platform.release()}" + details = f" ({python_version}, {platform_info})" + + USER_AGENT = f"{name_and_version}{requests_user_agent}{details}" class DeviceStatuses(ExtendedEnum): From 6b51147b00cf092c8967519bef45186ef7b42031 Mon Sep 17 00:00:00 2001 From: marwin-roth Date: Thu, 7 Nov 2024 16:57:59 +0100 Subject: [PATCH 5/5] Update minimal python version --- README.md | 2 +- setup.py | 8 ++++---- sonar-project.properties | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 7efc92c..b22ca63 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Automate your routines with this SDK for Python. ### Prerequisites -- Python ([version 3.6.0](https://www.python.org/downloads/release/python-360/) or higher) +- Python ([version 3.9.0](https://www.python.org/downloads/release/python-390/) or higher) ### Install from source (requires build) diff --git a/setup.py b/setup.py index e5e6cab..ec99f34 100644 --- a/setup.py +++ b/setup.py @@ -6,10 +6,10 @@ VERSION = "0.3.12" # To install the library, run the following # -# python setup.py install +# python -m build --sdist --wheel # -# prerequisite: setuptools -# http://pypi.python.org/pypi/setuptools +# prerequisite: build +# https://pypi.org/project/build/ REQUIRES = ['requests>=2.27.0,<2.30.0', 'pydantic>=1.9.0,<2.0.0'] if __name__ == '__main__': @@ -28,7 +28,7 @@ "Bug Tracker": "https://github.com/EMnify/emnify-sdk-python", }, install_requires=REQUIRES, - python_requires=">=3.6", + python_requires=">=3.9", packages=find_packages(exclude=['tests']), include_package_data=True, long_description=long_description, diff --git a/sonar-project.properties b/sonar-project.properties index 7133ba9..79e3d4f 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -5,4 +5,4 @@ sonar.tests=tests sonar.verbose=true sonar.python.coverage.reportPaths=coverage.xml -sonar.python.version=3.7, 3.8, 3.9 +sonar.python.version=3.9, 3.10, 3.11, 3.12, 3.13