Skip to content

Commit cc3c304

Browse files
authored
Merge pull request #31 from adobe-apiplatform/v2
merge release 2.0.2 to master
2 parents 70128b5 + 1f09d2f commit cc3c304

File tree

6 files changed

+78
-1
lines changed

6 files changed

+78
-1
lines changed

HISTORY.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Version 2.0
2+
3+
First release with functional wrapper and built-in throttling/batching.
4+
5+
### Version 2.0.1
6+
7+
Fast-follow bug fix release:
8+
9+
* [Issue 27](https://github.com/adobe-apiplatform/umapi-client.py/issues/27)
10+
* Update parameter names were incorrect.
11+
* Test mode wasn't working.
12+
* [Issue 28](https://github.com/adobe-apiplatform/umapi-client.py/issues/28)
13+
* Reuse exisiting open connections across calls.
14+
15+
### Version 2.0.2
16+
17+
Enhancement release:
18+
19+
* [Issue 30](https://github.com/adobe-apiplatform/umapi-client.py/issues/30)
20+
* Add control of user-agent header.
21+
* (No Issue)
22+
* Add this HISTORY.md file to summarize releases
23+
* Add version.py file to synchronize version between setup and module.

setup.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@
2020

2121
from setuptools import setup, find_packages
2222

23+
version_namespace = {}
24+
with open('umapi_client/version.py') as f:
25+
exec(f.read(), version_namespace)
26+
2327
setup(name='umapi-client',
24-
version='2.0.1',
28+
version=version_namespace['__version__'],
2529
description='Client for the User Management API (UMAPI) from Adobe - see https://adobe.ly/2h1pHgV',
2630
long_description=('The User Management API (aka the UMAPI) is an Adobe-hosted network service '
2731
'which provides Adobe Enterprise customers the ability to manage their users. This '

tests/test_connections.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
from conftest import mock_connection_params, MockResponse
2929
from umapi_client import Connection, UnavailableError, ServerError, RequestError
30+
from umapi_client import __version__ as umapi_version
3031

3132

3233
def test_remote_status_success():
@@ -52,6 +53,25 @@ def test_remote_status_timeout():
5253
_, remote_status = conn.status(remote=True)
5354
assert remote_status["status"].startswith("Unreachable")
5455

56+
def test_ua_string():
57+
conn = Connection(**mock_connection_params)
58+
req = conn.session.prepare_request(requests.Request('GET', "http://test.com/"))
59+
ua_header = req.headers.get("User-Agent")
60+
assert ua_header.startswith("umapi-client/" + umapi_version)
61+
assert " Python" in ua_header
62+
req = conn.session.prepare_request(requests.Request('POST', "http://test.com/", data="This is a test"))
63+
ua_header = req.headers.get("User-Agent")
64+
assert ua_header.startswith("umapi-client/" + umapi_version)
65+
assert " Python" in ua_header
66+
67+
def test_ua_string_additional():
68+
conn = Connection(user_agent="additional/1.0", **mock_connection_params)
69+
req = conn.session.prepare_request(requests.Request('GET', "http://test.com/"))
70+
ua_header = req.headers.get("User-Agent")
71+
assert ua_header.startswith("additional/1.0 umapi-client/" + umapi_version)
72+
req = conn.session.prepare_request(requests.Request('POST', "http://test.com/", data="This is a test"))
73+
ua_header = req.headers.get("User-Agent")
74+
assert ua_header.startswith("additional/1.0 umapi-client/" + umapi_version)
5575

5676
def test_get_success():
5777
with mock.patch("umapi_client.connection.requests.Session.get") as mock_get:

umapi_client/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@
2424
from .functional import IdentityTypes, GroupTypes, RoleTypes, IfAlreadyExistsOptions
2525
from .functional import UserAction, UserQuery, UsersQuery
2626
from .functional import UserGroupAction, GroupsQuery
27+
from .version import __version__

umapi_client/connection.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import json
2222
import logging
2323
from email.utils import parsedate_tz, mktime_tz
24+
from platform import python_version, version as platform_version
2425
from random import randint
2526
from time import time, sleep, gmtime, strftime
2627

@@ -29,6 +30,7 @@
2930

3031
from .auth import JWT, Auth, AccessRequest
3132
from .error import UnavailableError, ClientError, RequestError, ServerError
33+
from .version import __version__ as umapi_version
3234

3335

3436
class Connection:
@@ -52,6 +54,7 @@ def __init__(self,
5254
timeout_seconds=60.0,
5355
throttle_actions=10,
5456
throttle_commands=10,
57+
user_agent=None,
5558
**kwargs):
5659
"""
5760
Open a connection for the given parameters that has the given options.
@@ -82,6 +85,7 @@ def __init__(self,
8285
:param timeout_seconds: How many seconds to wait for server response (default=60, <= 0 or None means forever)
8386
:param throttle_actions: Max number of actions to pack into a single call
8487
:param throttle_commands: Max number of commands allowed in a single action
88+
:param user_agent: (optional) string to use as User-Agent header (umapi-client/version data will be added)
8589
8690
Additional keywords are allowed to make it easy to pass a big dictionary with other values
8791
:param kwargs: any keywords passed that we ignore.
@@ -111,6 +115,10 @@ def __init__(self,
111115
else:
112116
raise ValueError("Connector create: either auth (an Auth object) or auth_dict (a dictionary) is required")
113117
self.session = requests.Session()
118+
ua_string = "umapi-client/" + umapi_version + " Python/" + python_version() + " (" + platform_version() + ")"
119+
if user_agent and user_agent.strip():
120+
ua_string = user_agent.strip() + " " + ua_string
121+
self.session.headers["User-Agent"] = ua_string
114122

115123
def _get_auth(self, ims_host, ims_endpoint_jwt,
116124
tech_acct_id=None, api_key=None, client_secret=None, private_key_file=None,

umapi_client/version.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright (c) 2016-2017 Adobe Systems Incorporated. All rights reserved.
2+
#
3+
# Permission is hereby granted, free of charge, to any person obtaining a copy
4+
# of this software and associated documentation files (the "Software"), to deal
5+
# in the Software without restriction, including without limitation the rights
6+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
# copies of the Software, and to permit persons to whom the Software is
8+
# furnished to do so, subject to the following conditions:
9+
#
10+
# The above copyright notice and this permission notice shall be included in all
11+
# copies or substantial portions of the Software.
12+
#
13+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
# SOFTWARE.
20+
21+
__version__ = "2.0.2"

0 commit comments

Comments
 (0)