Skip to content

Commit 1c04fc7

Browse files
committed
SDK-668: Add version to request headers, extract version to separate file
1 parent 9d2fc78 commit 1c04fc7

File tree

6 files changed

+45
-20
lines changed

6 files changed

+45
-20
lines changed

setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
# -*- coding: utf-8 -*-
22
from setuptools import setup, find_packages
3+
from yoti_python_sdk import __version__
34

4-
VERSION = '2.5.0'
55
long_description = 'This package contains the tools you need to quickly ' \
66
'integrate your Python back-end with Yoti, so that your ' \
77
'users can share their identity details with your ' \
88
'application in a secure and trusted way.'
99

1010
setup(
1111
name='yoti',
12-
version=VERSION,
12+
version=__version__,
1313
packages=find_packages(),
1414
license='MIT',
1515
description='The Yoti Python SDK, providing API support for Login, Verify (2FA) and Age Verification.',
1616
long_description=long_description,
1717
url='https://github.com/getyoti/yoti-python-sdk',
1818
author='Yoti',
19-
author_email='tech@yoti.com',
19+
author_email='websdk@yoti.com',
2020
install_requires=['cryptography>=2.2.1', 'protobuf>=3.1.0',
2121
'requests>=2.11.1', 'future>=0.11.0', 'asn1==2.2.0', 'pyopenssl>=18.0.0'],
2222
extras_require={

yoti_python_sdk/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,26 @@
22
from os import environ
33

44
from yoti_python_sdk.client import Client
5+
from distutils.util import convert_path
56

67
DEFAULTS = {
78
'YOTI_API_URL': 'https://api.yoti.com',
89
'YOTI_API_PORT': 443,
910
'YOTI_API_VERSION': 'v1',
1011
}
1112

13+
main_ns = {}
14+
ver_path = convert_path('yoti_python_sdk/version.py')
15+
with open(ver_path) as ver_file:
16+
exec(ver_file.read(), main_ns)
17+
18+
__version__ = main_ns['__version__']
1219
YOTI_API_URL = environ.get('YOTI_API_URL', DEFAULTS['YOTI_API_URL'])
1320
YOTI_API_PORT = environ.get('YOTI_API_PORT', DEFAULTS['YOTI_API_PORT'])
1421
YOTI_API_VERSION = environ.get('YOTI_API_VERSION', DEFAULTS['YOTI_API_VERSION'])
1522
YOTI_API_ENDPOINT = '{0}:{1}/api/{2}'.format(YOTI_API_URL, YOTI_API_PORT, YOTI_API_VERSION)
1623

1724
__all__ = [
1825
'Client',
26+
__version__
1927
]

yoti_python_sdk/client.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
from yoti_python_sdk.crypto import Crypto
1616
from yoti_python_sdk.endpoint import Endpoint
1717
from yoti_python_sdk.protobuf.v1 import protobuf
18-
from .config import SDK_IDENTIFIER
18+
from .config import *
19+
1920

2021
NO_KEY_FILE_SPECIFIED_ERROR = 'Please specify the correct private key file ' \
2122
'in Client(pem_file_path=...)\nor by setting ' \
@@ -112,13 +113,15 @@ def __make_aml_check_request(self, http_method, aml_profile):
112113

113114
def __get_request_headers(self, path, http_method, content):
114115
request = self.__create_request(http_method, path, content)
116+
sdk_version = yoti_python_sdk.__version__
115117

116118
return {
117-
'X-Yoti-Auth-Key': self.__crypto.get_public_key(),
118-
'X-Yoti-Auth-Digest': self.__crypto.sign(request),
119-
'X-Yoti-SDK': SDK_IDENTIFIER,
120-
'Content-Type': 'application/json',
121-
'Accept': 'application/json'
119+
X_YOTI_AUTH_KEY: self.__crypto.get_public_key(),
120+
X_YOTI_AUTH_DIGEST: self.__crypto.sign(request),
121+
X_YOTI_SDK: SDK_IDENTIFIER,
122+
X_YOTI_SDK_VERSION: sdk_version,
123+
'Content-Type': JSON_CONTENT_TYPE,
124+
'Accept': JSON_CONTENT_TYPE
122125
}
123126

124127
@staticmethod

yoti_python_sdk/config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,8 @@
1818
KEY_AGE_VERIFIED = "is_age_verified"
1919
KEY_BASE64_SELFIE = "base64_selfie_uri"
2020
KEY_FORMATTED_ADDRESS = "formatted_address"
21+
X_YOTI_AUTH_KEY = "X-Yoti-Auth-Key"
22+
X_YOTI_AUTH_DIGEST = "X-Yoti-Auth-Digest"
23+
X_YOTI_SDK = "X-Yoti-SDK"
24+
X_YOTI_SDK_VERSION = X_YOTI_SDK + "-Version"
25+
JSON_CONTENT_TYPE = 'application/json'

yoti_python_sdk/tests/test_client.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616
except ImportError:
1717
import mock
1818

19+
import yoti_python_sdk
1920
from yoti_python_sdk import YOTI_API_ENDPOINT
2021
from yoti_python_sdk import Client
2122
from yoti_python_sdk import aml
22-
from yoti_python_sdk.config import SDK_IDENTIFIER
23+
from yoti_python_sdk.config import *
2324
from yoti_python_sdk.client import NO_KEY_FILE_SPECIFIED_ERROR
2425
from yoti_python_sdk.activity_details import ActivityDetails
2526
from yoti_python_sdk.tests.conftest import YOTI_CLIENT_SDK_ID, PEM_FILE_PATH
@@ -41,23 +42,29 @@
4142

4243
@pytest.fixture(scope='module')
4344
def expected_get_headers(x_yoti_auth_key, x_yoti_auth_digest_get):
45+
sdk_version = yoti_python_sdk.__version__
46+
4447
return {
45-
'Content-Type': 'application/json',
46-
'Accept': 'application/json',
47-
'X-Yoti-Auth-Key': x_yoti_auth_key,
48-
'X-Yoti-Auth-Digest': x_yoti_auth_digest_get,
49-
'X-Yoti-SDK': SDK_IDENTIFIER
48+
'Content-Type': JSON_CONTENT_TYPE,
49+
'Accept': JSON_CONTENT_TYPE,
50+
X_YOTI_AUTH_KEY: x_yoti_auth_key,
51+
X_YOTI_AUTH_DIGEST: x_yoti_auth_digest_get,
52+
X_YOTI_SDK: SDK_IDENTIFIER,
53+
X_YOTI_SDK_VERSION: sdk_version
5054
}
5155

5256

5357
@pytest.fixture(scope='module')
5458
def expected_post_headers(x_yoti_auth_key, x_yoti_auth_digest_post):
59+
sdk_version = yoti_python_sdk.__version__
60+
5561
return {
56-
'X-Yoti-Auth-Key': x_yoti_auth_key,
57-
'X-Yoti-Auth-Digest': x_yoti_auth_digest_post,
58-
'X-Yoti-SDK': SDK_IDENTIFIER,
59-
'Content-Type': 'application/json',
60-
'Accept': 'application/json'
62+
X_YOTI_AUTH_KEY: x_yoti_auth_key,
63+
X_YOTI_AUTH_DIGEST: x_yoti_auth_digest_post,
64+
X_YOTI_SDK: SDK_IDENTIFIER,
65+
X_YOTI_SDK_VERSION: sdk_version,
66+
'Content-Type': JSON_CONTENT_TYPE,
67+
'Accept': JSON_CONTENT_TYPE
6168
}
6269

6370

yoti_python_sdk/version.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# -*- coding: utf-8 -*-
2+
__version__ = "2.6.0"

0 commit comments

Comments
 (0)