Skip to content

Commit

Permalink
SDK-1076: Move create_nonce and create_timestamp into a utils module,…
Browse files Browse the repository at this point in the history
… and update references in the rest of the SDK
  • Loading branch information
MrBurtyyy committed Sep 10, 2019
1 parent bcea9e5 commit a4f0021
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 49 deletions.
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
sonar.projectKey = yoti-web-sdk:python
sonar.projectName = python-sdk
sonar.projectVersion = 2.8.2
sonar.projectVersion = 2.9.0
sonar.exclusions=yoti_python_sdk/tests/**,examples/**

sonar.python.pylint.reportPath=coverage.out
Expand Down
25 changes: 4 additions & 21 deletions yoti_python_sdk/endpoint.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from deprecated import deprecated
import time
import uuid
from yoti_python_sdk.utils import create_timestamp, create_nonce


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

return "/profile/{0}?nonce={1}&timestamp={2}&appId={3}".format(
decrypted_request_token,
self.__create_nonce(),
self.__create_timestamp(),
self.sdk_id,
decrypted_request_token, create_nonce(), create_timestamp(), self.sdk_id
)

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

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

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

return "/qrcodes/apps/{appid}?nonce={nonce}&timestamp={timestamp}".format(
appid=self.sdk_id,
nonce=self.__create_nonce(),
timestamp=self.__create_timestamp(),
appid=self.sdk_id, nonce=create_nonce(), timestamp=create_timestamp()
)

@staticmethod
@deprecated
def __create_nonce():
return uuid.uuid4()

@staticmethod
@deprecated
def __create_timestamp():
return int(time.time() * 1000)
16 changes: 2 additions & 14 deletions yoti_python_sdk/http.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from yoti_python_sdk.crypto import Crypto
from yoti_python_sdk.utils import create_nonce, create_timestamp
from yoti_python_sdk.config import (
X_YOTI_AUTH_KEY,
X_YOTI_AUTH_DIGEST,
Expand All @@ -12,8 +13,6 @@

import yoti_python_sdk
import requests
import uuid
import time

try: # pragma: no cover
from urllib.parse import urlencode
Expand Down Expand Up @@ -230,10 +229,7 @@ def __append_query_params(self, query_params=None):
Appends supplied query params in a dict to default query params.
Returns a url encoded query param string
"""
required = {
"nonce": self.__create_nonce(),
"timestamp": self.__create_timestamp(),
}
required = {"nonce": create_nonce(), "timestamp": create_timestamp()}

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

@staticmethod
def __create_nonce():
return uuid.uuid4()

@staticmethod
def __create_timestamp():
return int(time.time() * 1000)

def build(self):
"""
Builds a SignedRequest object with the supplied values
Expand Down
15 changes: 2 additions & 13 deletions yoti_python_sdk/sandbox/endpoint.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from yoti_python_sdk.endpoint import Endpoint
import time
import uuid
from yoti_python_sdk.utils import create_timestamp, create_nonce


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

def get_sandbox_path(self):
return "/apps/{sdk_id}/tokens?timestamp={timestamp}&nonce={nonce}".format(
sdk_id=self.sdk_id,
nonce=self.__create_nonce(),
timestamp=self.__create_timestamp(),
sdk_id=self.sdk_id, nonce=create_nonce(), timestamp=create_timestamp()
)

@staticmethod
def __create_nonce():
return uuid.uuid4()

@staticmethod
def __create_timestamp():
return int(time.time() * 1000)
20 changes: 20 additions & 0 deletions yoti_python_sdk/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import uuid
import time


def create_nonce():
"""
Create and return a nonce
\
:return: the nonce
"""
return uuid.uuid4()


def create_timestamp():
"""
Create and return a timestamp
:return: the timestamp as a int
"""
return int(time.time() * 1000)

0 comments on commit a4f0021

Please sign in to comment.