Skip to content

Commit c37a958

Browse files
authored
Merge pull request #40 from adobe-apiplatform/v2
Fix #38: allow client to give key data directly
2 parents 949960c + 2f51b47 commit c37a958

File tree

6 files changed

+47
-15
lines changed

6 files changed

+47
-15
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ python:
33
- 2.7
44
- 3.4
55
- 3.5
6+
- 3.6
67
install:
78
- pip install --upgrade pip setuptools wheel
89
- pip install -r requirements.txt
@@ -16,6 +17,6 @@ deploy:
1617
secure: nqS9f74jOJZnZ7FqhwpChvP4MlslIF14StxxdYrMuKs0fh6Bcz8O5DROBiEEs9OvM3+cbPkmfkg7PKkZQx4UQTQzYCPKV85YegrQW2WRcwwW3ik6NB5AELphjx3RBMA61p827m7V4vHW67j70+ITDG1joKBNzj7XfQPNma4LtBAxNPsNP9sHaZsWAUAnBvDZ9m7s3mPp2x3t+f9klxaurW7V6NvrjB47r9ln5Ry2JWxHBPKBjJ4XgVVYVQF4HmyrOzszH6xYUVS1KY6S6RUeOl8u/PwSWh3/QH0TvNmVzuZgU/dZxF0JEJbFZvh6+tVNaCcCGYlF+bXkPKbeMEnnPPvaI1RHuUbplPhNWRjVSksAJsznbvYseSg/e7yGJ6ghpsVAySqamMzrpH+U2OJ09czxv3boo9zJm/WWwg069OYkKWyUpNdjgiz0mgYb4KfVak0qhVy3qtbxju4RdCRnxIM2TXF+G/nkUpgtoSFgydgVpMbU2hjj8nonPgesWthFs9KlZocW1epyGySUVvcOcp4KuSvxS3njmA0+knWkAnCvFv7ynCkx7V7CNZvMo49HSMxNGfEs+d12MGIbfqYpIa1van8m4ApOuZ8RhVQq0ZLxVyuORqIDrG1PO7Gg/FFn4objp7e850lBML5ruoMqTmr5FFNSSBXfO/3NQa7l9RM=
1718
on:
1819
tags: true
19-
python: "3.5"
20+
python: "3.6"
2021
repo: adobe-apiplatform/umapi-client.py
2122
all_branches: true

HISTORY.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,13 @@ Enhancement release:
5252
* return a new BatchError that has caught exceptions and batch statistics
5353
* (No Issue)
5454
* allow User Sync config key names in the connection `auth_dict`
55+
56+
### Version 2.3
57+
58+
Enhancement release:
59+
60+
* [Issue 38](https://github.com/adobe-apiplatform/umapi-client.py/issues/38)
61+
* accept private_key_data instead private_key_file
62+
* document all accepted `auth_dict` keys
63+
* (No Issue)
64+
* certify for Python 3.6

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
'Programming Language :: Python :: 2.7',
3838
'Programming Language :: Python :: 3.4',
3939
'Programming Language :: Python :: 3.5',
40+
'Programming Language :: Python :: 3.6',
4041
'License :: OSI Approved :: MIT License',
4142
'Intended Audience :: Developers',
4243
'Intended Audience :: System Administrators',

tests/test_live.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,26 @@
4141
@pytest.fixture(scope="module")
4242
def config():
4343
with open(config_file_name, "r") as f:
44-
config = yaml.load(f)
45-
creds = config["test_org"]
44+
conf_dict = yaml.load(f)
45+
creds = conf_dict["test_org"]
4646
conn = umapi_client.Connection(org_id=creds["org_id"], auth_dict=creds)
47-
return conn, config
47+
return conn, conf_dict
4848

4949

50-
def test_status(config):
51-
conn, _ = config
52-
_, status = conn.status(remote=True)
53-
logging.info("Server status is %s", status)
50+
def test_conn_and_status(config):
51+
# first create conn using key file, as usual
52+
conn1, params = config
53+
_, status = conn1.status(remote=True)
54+
logging.info("Server connection from key file, status is %s", status)
55+
assert status["state"] == "LIVE"
56+
# next create conn using key data
57+
creds = params["test_org"]
58+
key_file = creds.pop("private_key_file")
59+
with open(key_file) as f:
60+
creds["private_key_data"] = f.read()
61+
conn2 = umapi_client.Connection(org_id=creds["org_id"], auth_dict=creds)
62+
_, status = conn2.status(remote=True)
63+
logging.info("Server connection from key data, status is %s", status)
5464
assert status["state"] == "LIVE"
5565

5666

@@ -63,8 +73,8 @@ def test_list_users(config):
6373
if re.match(r".*@adobe.com$", str(email).lower()):
6474
assert str(user["type"]) == "adobeID"
6575
user_count += 1
66-
if user_count >= 2000:
67-
logging.info("Quitting enumeration after 2000 users.")
76+
if user_count >= 600:
77+
logging.info("Quitting enumeration after 600 users.")
6878
break
6979
logging.info("Found %d users.", user_count)
7080

umapi_client/connection.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from time import time, sleep, gmtime, strftime
2727

2828
import requests
29+
import six
2930
import six.moves.urllib.parse as urlparse
3031

3132
from .auth import JWT, Auth, AccessRequest
@@ -69,7 +70,12 @@ def __init__(self,
6970
:param tech_acct_id: string technical account ID from Adobe.IO integration data
7071
:param api_key: string api_key from Adobe.IO integration data
7172
:param client_secret: string client secret from Adobe.IO integration data
73+
and one of:
7274
:param private_key_file: path to local private key file that matches Adobe.IO public key for integration
75+
or:
76+
:param private_key_data: the contents of the private_key_file (PEM format)
77+
(NOTE: for compatibility with User Sync config files, the key names priv_key_path and tech_acct
78+
are accepted as aliases for private_key_file and tech_acct_id, respectively.)
7379
7480
Optional connection parameters (defaults are for Adobe production):
7581
:param ims_host: the IMS host which will exchange your JWT for an access token
@@ -121,14 +127,18 @@ def __init__(self,
121127
self.session.headers["User-Agent"] = ua_string
122128

123129
def _get_auth(self, ims_host, ims_endpoint_jwt,
124-
tech_acct_id=None, api_key=None, client_secret=None, private_key_file=None,
130+
tech_acct_id=None, api_key=None, client_secret=None,
131+
private_key_file=None, private_key_data=None,
125132
**kwargs):
126133
tech_acct_id = tech_acct_id or kwargs.get("tech_acct")
127134
private_key_file = private_key_file or kwargs.get("priv_key_path")
128-
if not (tech_acct_id and api_key and client_secret and private_key_file):
135+
if not (tech_acct_id and api_key and client_secret and (private_key_data or private_key_file)):
129136
raise ValueError("Connector create: not all required auth parameters were supplied; please see docs")
130-
with open(private_key_file, 'r') as private_key_stream:
131-
jwt = JWT(self.org_id, tech_acct_id, ims_host, api_key, private_key_stream)
137+
if private_key_data:
138+
jwt = JWT(self.org_id, tech_acct_id, ims_host, api_key, six.StringIO(private_key_data))
139+
else:
140+
with open(private_key_file, 'r') as private_key_stream:
141+
jwt = JWT(self.org_id, tech_acct_id, ims_host, api_key, private_key_stream)
132142
token = AccessRequest("https://" + ims_host + ims_endpoint_jwt, api_key, client_secret, jwt())
133143
return Auth(api_key, token())
134144

umapi_client/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@
1818
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
# SOFTWARE.
2020

21-
__version__ = "2.2"
21+
__version__ = "2.3"

0 commit comments

Comments
 (0)