Skip to content

Commit a4f0021

Browse files
committed
SDK-1076: Move create_nonce and create_timestamp into a utils module, and update references in the rest of the SDK
1 parent bcea9e5 commit a4f0021

File tree

5 files changed

+29
-49
lines changed

5 files changed

+29
-49
lines changed

sonar-project.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
sonar.projectKey = yoti-web-sdk:python
22
sonar.projectName = python-sdk
3-
sonar.projectVersion = 2.8.2
3+
sonar.projectVersion = 2.9.0
44
sonar.exclusions=yoti_python_sdk/tests/**,examples/**
55

66
sonar.python.pylint.reportPath=coverage.out

yoti_python_sdk/endpoint.py

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
from deprecated import deprecated
2-
import time
3-
import uuid
1+
from yoti_python_sdk.utils import create_timestamp, create_nonce
42

53

64
class Endpoint(object):
@@ -14,36 +12,21 @@ def get_activity_details_request_path(
1412
return "/profile/{0}".format(decrypted_request_token)
1513

1614
return "/profile/{0}?nonce={1}&timestamp={2}&appId={3}".format(
17-
decrypted_request_token,
18-
self.__create_nonce(),
19-
self.__create_timestamp(),
20-
self.sdk_id,
15+
decrypted_request_token, create_nonce(), create_timestamp(), self.sdk_id
2116
)
2217

2318
def get_aml_request_url(self, no_params=False):
2419
if no_params:
2520
return "/aml-check"
2621

2722
return "/aml-check?appId={0}&timestamp={1}&nonce={2}".format(
28-
self.sdk_id, self.__create_timestamp(), self.__create_nonce()
23+
self.sdk_id, create_timestamp(), create_nonce()
2924
)
3025

3126
def get_dynamic_share_request_url(self, no_params=False):
3227
if no_params:
3328
return "/qrcodes/app/{appid}".format(appid=self.sdk_id)
3429

3530
return "/qrcodes/apps/{appid}?nonce={nonce}&timestamp={timestamp}".format(
36-
appid=self.sdk_id,
37-
nonce=self.__create_nonce(),
38-
timestamp=self.__create_timestamp(),
31+
appid=self.sdk_id, nonce=create_nonce(), timestamp=create_timestamp()
3932
)
40-
41-
@staticmethod
42-
@deprecated
43-
def __create_nonce():
44-
return uuid.uuid4()
45-
46-
@staticmethod
47-
@deprecated
48-
def __create_timestamp():
49-
return int(time.time() * 1000)

yoti_python_sdk/http.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from yoti_python_sdk.crypto import Crypto
2+
from yoti_python_sdk.utils import create_nonce, create_timestamp
23
from yoti_python_sdk.config import (
34
X_YOTI_AUTH_KEY,
45
X_YOTI_AUTH_DIGEST,
@@ -12,8 +13,6 @@
1213

1314
import yoti_python_sdk
1415
import requests
15-
import uuid
16-
import time
1716

1817
try: # pragma: no cover
1918
from urllib.parse import urlencode
@@ -230,10 +229,7 @@ def __append_query_params(self, query_params=None):
230229
Appends supplied query params in a dict to default query params.
231230
Returns a url encoded query param string
232231
"""
233-
required = {
234-
"nonce": self.__create_nonce(),
235-
"timestamp": self.__create_timestamp(),
236-
}
232+
required = {"nonce": create_nonce(), "timestamp": create_timestamp()}
237233

238234
query_params = self.__merge_dictionary(query_params, required)
239235
return "?{}".format(urlencode(query_params))
@@ -304,14 +300,6 @@ def __validate_request(self):
304300
if self.__http_method is None:
305301
raise ValueError("HTTP method must be specified")
306302

307-
@staticmethod
308-
def __create_nonce():
309-
return uuid.uuid4()
310-
311-
@staticmethod
312-
def __create_timestamp():
313-
return int(time.time() * 1000)
314-
315303
def build(self):
316304
"""
317305
Builds a SignedRequest object with the supplied values
Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from yoti_python_sdk.endpoint import Endpoint
2-
import time
3-
import uuid
2+
from yoti_python_sdk.utils import create_timestamp, create_nonce
43

54

65
class SandboxEndpoint(Endpoint):
@@ -9,15 +8,5 @@ def __init__(self, sdk_id):
98

109
def get_sandbox_path(self):
1110
return "/apps/{sdk_id}/tokens?timestamp={timestamp}&nonce={nonce}".format(
12-
sdk_id=self.sdk_id,
13-
nonce=self.__create_nonce(),
14-
timestamp=self.__create_timestamp(),
11+
sdk_id=self.sdk_id, nonce=create_nonce(), timestamp=create_timestamp()
1512
)
16-
17-
@staticmethod
18-
def __create_nonce():
19-
return uuid.uuid4()
20-
21-
@staticmethod
22-
def __create_timestamp():
23-
return int(time.time() * 1000)

yoti_python_sdk/utils.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import uuid
2+
import time
3+
4+
5+
def create_nonce():
6+
"""
7+
Create and return a nonce
8+
\
9+
:return: the nonce
10+
"""
11+
return uuid.uuid4()
12+
13+
14+
def create_timestamp():
15+
"""
16+
Create and return a timestamp
17+
18+
:return: the timestamp as a int
19+
"""
20+
return int(time.time() * 1000)

0 commit comments

Comments
 (0)