Skip to content

Commit c16f44b

Browse files
authored
Merge pull request #30 from docusign/using-environment-variables
Using env variables
2 parents ad79631 + 431073d commit c16f44b

File tree

5 files changed

+46
-53
lines changed

5 files changed

+46
-53
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Note: This may require the command console be elevated. You can accomplish this
6969
This client has the following external dependencies:
7070

7171
- certifi v14.05.14+
72-
- six v1.8.0
72+
- six v1.8.0+
7373
- python\_dateutil v2.5.3+
7474
- setuptools v21.0.0+
7575
- urllib3 v1.15.1+

requirements.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
certifi >= 14.05.14
2-
six == 1.8.0
2+
six >= 1.8.0
33
python_dateutil >= 2.5.3
44
setuptools >= 21.0.0
55
urllib3 >= 1.15
6-
PyJWT==1.7.1
7-
cryptography==2.5
8-
nose==1.3.7
6+
PyJWT>=1.7.1
7+
cryptography>=2.5
8+
nose>=1.3.7

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# http://pypi.python.org/pypi/setuptools
2626

2727

28-
REQUIRES = ["urllib3 >= 1.15", "six == 1.8.0", "certifi >= 14.05.14", "python-dateutil >= 2.5.3", "setuptools >= 21.0.0", "PyJWT==1.7.1", "cryptography==2.5", "nose==1.3.7"]
28+
REQUIRES = ["urllib3 >= 1.15", "six >= 1.8.0", "certifi >= 14.05.14", "python-dateutil >= 2.5.3", "setuptools >= 21.0.0", "PyJWT>=1.7.1", "cryptography>=2.5", "nose>=1.3.7"]
2929

3030
class CleanCommand(Command):
3131
"""Custom clean command to tidy up the project root."""

test/test_oauth.py

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
from __future__ import absolute_import
1414

15+
import base64
1516
import os
1617
import unittest
1718

@@ -20,27 +21,23 @@
2021

2122

2223
class TestConfig(object):
23-
def __init__(self, user_name=None, client_secret =None, user_id=None, password=None, integrator_key=None, host=None, recipient_email=None,
24+
def __init__(self, user_name=None, client_secret =None, user_id=None, integrator_key=None, host=None, recipient_email=None,
2425
recipient_name=None, template_role_name=None, template_id=None, return_url=None, redirect_uri=None):
25-
self.user_name = user_name if user_name else "[email protected]"
26-
self.password = password if password else "{PASSWORD}
27-
self.client_secret = client_secret if client_secret else "3b61ffcf-xxxx-xxxx-xxxx-d49f7d82cb55"
28-
self.integrator_key = integrator_key if integrator_key else "ae30ea4e-xxxx-xxxx-xxxx-fcb57d2dc4df"
26+
self.user_name = user_name if user_name else os.environ.get("USER_NAME")
27+
self.client_secret = client_secret if client_secret else os.environ.get("CLIENT_SECRET")
28+
self.integrator_key = integrator_key if integrator_key else os.environ.get("INTEGRATOR_KEY_JWT")
2929
self.host = host if host else "https://demo.docusign.net/restapi"
30-
self.recipient_email = recipient_email if recipient_email else "node_sdk@mailinator.com"
31-
self.recipient_name = recipient_name if recipient_name else "node_sdk@mailinator.com"
32-
self.template_role_name = template_role_name if template_role_name else "node_sdk@mailinator.com"
33-
self.template_id = template_id if template_id else "cf2a46c2-xxxx-xxxx-xxxx-752547b1a419"
34-
self.return_url = return_url if return_url else "node_sdk@mailinator.com"
35-
self.user_id = user_id if user_id else "fcc5726c-xxxx-xxxx-xxxx-40bbbe6ca126"
36-
self.redirect_uri = redirect_uri if redirect_uri else "http://38a36d7b.ngrok.io"
30+
self.recipient_email = recipient_email if recipient_email else os.environ.get("USER_NAME")
31+
self.recipient_name = recipient_name if recipient_name else os.environ.get("USER_NAME")
32+
self.template_role_name = template_role_name if template_role_name else os.environ.get("USER_NAME")
33+
self.template_id = template_id if template_id else os.environ.get("TEMPLATE_ID")
34+
self.return_url = return_url if return_url else os.environ.get("REDIRECT_URI")
35+
self.user_id = user_id if user_id else os.environ.get("USER_ID")
36+
self.redirect_uri = redirect_uri if redirect_uri else os.environ.get("REDIRECT_URI")
3737

3838
self.oauth_host_name = "account-d.docusign.com"
39-
self.private_key_file_name = "{}/keys/private.pem".format(os.path.dirname(os.path.abspath(__file__)))
40-
self.expires_in_hours = 1
41-
42-
# this.IntegratorKeyNoConsent = "66750331-xxxx-xxxx-xxxx-6c1a413a6096";
43-
# this.PrivateKeyNoConsentFilename = "../../docs/privateKeyConsentReq.pem";
39+
self.private_key_bytes = base64.b64decode(os.environ.get("PRIVATE_KEY"))
40+
self.expires_in = 3600
4441

4542

4643
class TestOauth(unittest.TestCase):
@@ -62,24 +59,22 @@ def test_oauth_uri(self):
6259
self.api_client.rest_client.pool_manager.clear()
6360

6461
def test_jwt_application(self):
65-
with open(self.test_config.private_key_file_name, 'r') as private_key:
66-
token_obj = self.api_client.request_jwt_application_token(client_id=self.test_config.integrator_key,
67-
oauth_host_name=self.test_config.oauth_host_name,
68-
private_key_bytes=private_key.read(),
69-
expires_in=self.test_config.expires_in_hours)
70-
self.assertTrue(isinstance(token_obj, OAuthToken))
71-
self.api_client.rest_client.pool_manager.clear()
62+
token_obj = self.api_client.request_jwt_application_token(client_id=self.test_config.integrator_key,
63+
oauth_host_name=self.test_config.oauth_host_name,
64+
private_key_bytes=self.test_config.private_key_bytes,
65+
expires_in=self.test_config.expires_in)
66+
self.assertTrue(isinstance(token_obj, OAuthToken))
67+
self.api_client.rest_client.pool_manager.clear()
7268

7369
def test_jwt_user(self):
74-
with open(self.test_config.private_key_file_name, 'r') as private_key:
75-
token_obj = self.api_client.request_jwt_user_token(client_id=self.test_config.integrator_key,
76-
user_id=self.test_config.user_id,
77-
oauth_host_name=self.api_client.get_oauth_host_name(),
78-
private_key_bytes=private_key.read(),
79-
expires_in=self.test_config.expires_in_hours
80-
)
81-
self.assertTrue(isinstance(token_obj, OAuthToken))
82-
self.api_client.rest_client.pool_manager.clear()
70+
token_obj = self.api_client.request_jwt_user_token(client_id=self.test_config.integrator_key,
71+
user_id=self.test_config.user_id,
72+
oauth_host_name=self.api_client.get_oauth_host_name(),
73+
private_key_bytes=self.test_config.private_key_bytes,
74+
expires_in=self.test_config.expires_in
75+
)
76+
self.assertTrue(isinstance(token_obj, OAuthToken))
77+
self.api_client.rest_client.pool_manager.clear()
8378

8479
def test_authorization_code_login(self):
8580
self.api_client.get_oauth_host_name()
@@ -100,7 +95,7 @@ def test_authorization_code_login(self):
10095
# # lines:
10196
# #
10297
# code = "code"
103-
# token_obj = self.api_client.generate_access_token(self.test_config.integrator_key, self.test_config.client_secret, code)
98+
# token_obj = self.api_client.generate_access_token(self.test_config.integrator_key,self.test_config.client_secret, code)
10499
# self.assertTrue(isinstance(token_obj, OAuthToken))
105100
#
106101
# self.api_client.set_access_token(token_obj)

test/unit_tests.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
import docusign_esign as docusign
1313
from docusign_esign import AuthenticationApi, EnvelopesApi, TemplatesApi, DiagnosticsApi, FoldersApi, ApiException
1414

15-
Username = "[email protected]"
16-
Password = "[PASSWORD]"
17-
IntegratorKey = "ae30ea4e-xxxx-xxxx-xxxx-fcb57d2dc4df"
15+
Username = os.environ.get("USER_NAME")
16+
IntegratorKey = os.environ.get("INTEGRATOR_KEY_JWT")
1817
BaseUrl = "https://demo.docusign.net/restapi"
1918
OauthHostName = "account-d.docusign.com"
2019
SignTest1File = "{}/docs/SignTest1.pdf".format(os.path.dirname(os.path.abspath(__file__)))
21-
TemplateId = "cf2a46c2-xxxx-xxxx-xxxx-752547b1a419"
22-
UserId = "fcc5726c-xxxx-xxxx-xxxx-40bbbe6ca126"
20+
TemplateId = os.environ.get("TEMPLATE_ID")
21+
UserId = os.environ.get("USER_ID")
22+
PrivateKeyBytes = base64.b64decode(os.environ.get("PRIVATE_KEY"))
2323

2424

2525
class SdkUnitTests(unittest.TestCase):
@@ -29,7 +29,6 @@ def setUp(self):
2929
self.api_client.rest_client.pool_manager.clear()
3030

3131
docusign.configuration.api_client = self.api_client
32-
self.private_key_file_name = "{}/keys/private.pem".format(os.path.dirname(os.path.abspath(__file__)))
3332
try:
3433
envelope_definition = docusign.EnvelopeDefinition()
3534
envelope_definition.email_subject = 'Please Sign my Python SDK Envelope'
@@ -45,13 +44,12 @@ def setUp(self):
4544
envelope_definition.status = 'sent'
4645
envelopes_api = EnvelopesApi()
4746

48-
with open(self.private_key_file_name, 'r') as private_key:
49-
self.api_client.host = BaseUrl
50-
token = (self.api_client.request_jwt_user_token(client_id=IntegratorKey,
51-
user_id=UserId,
52-
oauth_host_name=OauthHostName,
53-
private_key_bytes=private_key.read(),
54-
expires_in=1))
47+
self.api_client.host = BaseUrl
48+
token = (self.api_client.request_jwt_user_token(client_id=IntegratorKey,
49+
user_id=UserId,
50+
oauth_host_name=OauthHostName,
51+
private_key_bytes=PrivateKeyBytes,
52+
expires_in=3600))
5553
self.user_info = self.api_client.get_user_info(token.access_token)
5654
self.api_client.rest_client.pool_manager.clear()
5755
docusign.configuration.api_client = self.api_client

0 commit comments

Comments
 (0)