Skip to content

Commit 62b4859

Browse files
authored
Merge pull request #13 from lampkicking/release/0-1-0
Initial 0-1-0 release changes
2 parents 09613ca + 3d25dbc commit 62b4859

File tree

11 files changed

+59
-43
lines changed

11 files changed

+59
-43
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
11
# Change Log #
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](http://keepachangelog.com/)
6+
and this project adheres to [Semantic Versioning](http://semver.org/).
7+
8+
## [0.1.0] - 2015-10-2X
9+
### Added
10+
- Initial SDK release

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ securely verify users' identities.
55

66
## Example ##
77

8-
from yoti.client import Client
8+
from yoti import Client
99

1010
@app.route('/callback')
1111
def callback():
@@ -78,6 +78,7 @@ One tool to do just this is [pyenv](https://github.com/yyuu/pyenv)
7878

7979
1. Install `pyenv`
8080
1. Install Python interpreters you want to test with, e.g. `pyenv install 2.6.9`
81+
1. Install project dependencies: `pip install -r requirements.txt`
8182
1. Execute in the main project dir: `tox`
8283
1. In order to execute integration tests run: `tox pytest_integration.ini`
8384

examples/yoti_example_django/yoti_example/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from django.views.generic import TemplateView
22

3-
from yoti.client import Client
3+
from yoti import Client
44

55
from .app_settings import (
66
YOTI_APPLICATION_ID,

examples/yoti_example_flask/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from flask import Flask, render_template, request
22

3-
from yoti.client import Client
3+
from yoti import Client
44

55
from settings import (
66
YOTI_APPLICATION_ID,

tox.ini

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tox]
2-
envlist = {py26,py27,py33,py34,py35,py36}-general
3-
{py26,py27,py33,py34,py35,py36}-general-{oldest,cryptography14,requests26,protobuf30}
2+
envlist = py26,py27,py33,py34,py35,py36
3+
{py26,py27,py33,py34,py35,py36}-{oldest,cryptography14,requests26,protobuf30}
44
py36-macOS
55
py36-macOS-{oldest,cryptography14,requests26,protobuf30}
66
skip_missing_interpreters = True
@@ -16,20 +16,20 @@ deps = future011,oldest: future==0.11.0
1616
future013: future>=0.13,<0.14
1717
requests26: requests>=2.6,<2.7
1818

19-
[testenv:py36-general]
19+
[testenv:py36]
2020
platform = win32|linux2|linux|cygwin
2121

22-
[testenv:py36-general-oldest]
23-
platform = {[testenv:py36-general]platform}
22+
[testenv:py36-oldest]
23+
platform = {[testenv:py36]platform}
2424

25-
[testenv:py36-general-requests26]
26-
platform = {[testenv:py36-general]platform}
25+
[testenv:py36-requests26]
26+
platform = {[testenv:py36]platform}
2727

28-
[testenv:py36-general-cryptography14]
29-
platform = {[testenv:py36-general]platform}
28+
[testenv:py36-cryptography14]
29+
platform = {[testenv:py36]platform}
3030

31-
[testenv:py36-general-protobuf30]
32-
platform = {[testenv:py36-general]platform}
31+
[testenv:py36-protobuf30]
32+
platform = {[testenv:py36]platform}
3333

3434
[testenv:macOS]
3535
; On macOS and Python versions where there aren't any binary wheels for `cryptography` yet

yoti/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# -*- coding: utf-8 -*-
22
from os import environ
33

4+
from yoti.client import Client
5+
46
DEFAULTS = {
57
'YOTI_API_URL': 'https://api.yoti.com',
68
'YOTI_API_PORT': 443,
@@ -11,3 +13,8 @@
1113
YOTI_API_PORT = environ.get('YOTI_API_PORT', DEFAULTS['YOTI_API_PORT'])
1214
YOTI_API_VERSION = environ.get('YOTI_API_VERSION', DEFAULTS['YOTI_API_VERSION'])
1315
YOTI_API_ENDPOINT = '{0}:{1}/api/{2}'.format(YOTI_API_URL, YOTI_API_PORT, YOTI_API_VERSION)
16+
17+
18+
__all__ = [
19+
'Client',
20+
]

yoti/client.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
# -*- coding: utf-8 -*-
22
from __future__ import unicode_literals
33

4+
import json
45
import time
56
import uuid
6-
import json
7-
import requests
8-
97
from os import environ
10-
from os.path import isfile
8+
from os.path import isfile, expanduser
119

10+
import requests
1211
from past.builtins import basestring
1312

14-
from yoti import YOTI_API_ENDPOINT
15-
from yoti.crypto import Crypto
13+
import yoti
1614
from yoti.activity_details import ActivityDetails
15+
from yoti.crypto import Crypto
1716
from yoti.protobuf.v1 import protobuf
1817

1918

@@ -41,12 +40,14 @@ def __init__(self, sdk_id=None, pem_file_path=None):
4140
@staticmethod
4241
def __read_pem_file(key_file_path, error_source):
4342
try:
43+
key_file_path = expanduser(key_file_path)
44+
4445
if not isinstance(key_file_path, basestring) or not isfile(key_file_path):
4546
raise IOError('File not found: {0}'.format(key_file_path))
4647
with open(key_file_path, 'rb') as pem_file:
4748
return pem_file.read().strip()
48-
except (IOError, TypeError, OSError) as exc:
49-
error = 'Invalid private key file ' + error_source
49+
except (AttributeError, IOError, TypeError, OSError) as exc:
50+
error = 'Could not read private key file: "{0}", passed as: {1} '.format(key_file_path, error_source)
5051
exception = '{0}: {1}'.format(type(exc).__name__, exc)
5152
raise RuntimeError('{0}: {1}'.format(error, exception))
5253

@@ -67,7 +68,7 @@ def get_activity_details(self, encrypted_request_token):
6768

6869
def __make_request(self, encrypted_request_token):
6970
path = self.__get_request_path(encrypted_request_token)
70-
url = YOTI_API_ENDPOINT + path
71+
url = yoti.YOTI_API_ENDPOINT + path
7172
headers = self.__get_request_headers(path)
7273
response = requests.get(url=url, headers=headers)
7374

yoti/crypto.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,11 @@ def decipher(key, iv, cipher_text):
5959
mode=modes.CBC(iv),
6060
backend=default_backend()
6161
).decryptor()
62-
return decryptor.update(cipher_text) + decryptor.finalize()
62+
plaintext = decryptor.update(cipher_text) + decryptor.finalize()
63+
64+
return Crypto.strip_pkcs5_padding(plaintext)
65+
66+
@staticmethod
67+
def strip_pkcs5_padding(data):
68+
number_of_padded_bytes = data[-1]
69+
return data[:-number_of_padded_bytes]

yoti/tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import pytest
55

6-
from yoti.client import Client
6+
from yoti import Client
77
from yoti.crypto import Crypto
88

99
FIXTURES_DIR = join(dirname(abspath(__file__)), 'fixtures')

yoti/tests/test_client.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# -*- coding: utf-8 -*-
22
from __future__ import unicode_literals
33

4-
import pytest
5-
64
from os import environ
5+
6+
import pytest
77
from past.builtins import basestring
88

99
try:
@@ -12,7 +12,8 @@
1212
import mock
1313

1414
from yoti import YOTI_API_ENDPOINT
15-
from yoti.client import Client, NO_KEY_FILE_SPECIFIED_ERROR
15+
from yoti import Client
16+
from yoti.client import NO_KEY_FILE_SPECIFIED_ERROR
1617
from yoti.activity_details import ActivityDetails
1718
from yoti.tests.conftest import YOTI_CLIENT_SDK_ID, PEM_FILE_PATH
1819
from yoti.tests.mocks import (
@@ -63,7 +64,7 @@ def test_creating_client_instance_without_private_key_file():
6364
def test_creating_client_instance_with_invalid_key_file_arg(key_file):
6465
with pytest.raises(RuntimeError) as exc:
6566
Client(YOTI_CLIENT_SDK_ID, key_file)
66-
expected_error = 'Invalid private key file argument specified in Client()'
67+
expected_error = 'Could not read private key file'
6768
assert expected_error in str(exc)
6869
assert str(key_file) in str(exc)
6970

@@ -73,9 +74,10 @@ def test_creating_client_instance_with_invalid_key_file_env(key_file):
7374
environ['YOTI_KEY_FILE_PATH'] = str(key_file)
7475
with pytest.raises(RuntimeError) as exc:
7576
Client(YOTI_CLIENT_SDK_ID)
76-
expected_error = 'Invalid private key file specified by the ' \
77-
'YOTI_KEY_FILE_PATH env variable'
77+
expected_error = 'Could not read private key file'
78+
expected_error_source = 'specified by the YOTI_KEY_FILE_PATH env variable'
7879
assert expected_error in str(exc)
80+
assert expected_error_source in str(exc)
7981
assert str(key_file) in str(exc)
8082

8183

@@ -88,7 +90,7 @@ def test_creating_client_instance_with_valid_key_file_env_but_invalid_key_file_a
8890
environ['YOTI_KEY_FILE_PATH'] = PEM_FILE_PATH
8991
with pytest.raises(RuntimeError) as exc:
9092
Client(YOTI_CLIENT_SDK_ID, INVALID_KEY_FILE_PATH)
91-
expected_error = 'Invalid private key file argument specified in Client()'
93+
expected_error = 'Could not read private key file'
9294
assert expected_error in str(exc)
9395
assert str(INVALID_KEY_FILE_PATH) in str(exc)
9496

0 commit comments

Comments
 (0)