Skip to content

Commit a0d5b7b

Browse files
Merge pull request #99 from adobe-apiplatform/feature/signals-v2
Feature/signals v2
2 parents b5c16af + ded6ed8 commit a0d5b7b

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "umapi-client"
3-
version = "2.18"
3+
version = "2.19"
44
description = "Client for the User Management API (UMAPI) from Adobe - see https://adobe.ly/2h1pHgV"
55
readme = "README.md"
66
authors = ["Andrew Dorton <[email protected]>", "Dan Brotsky", "Danimae Vossen", "Kevin Bhunut"]

umapi_client/connection.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@
2121
import json
2222
import logging
2323
import os
24-
import uuid
2524
from email.utils import parsedate_tz, mktime_tz
2625
from platform import python_version, version as platform_version
2726
from random import randint
2827
from time import time, sleep, gmtime, strftime
28+
from uuid import uuid4
29+
from datetime import datetime
2930
import requests
3031
import io
3132
import urllib.parse as urlparse
@@ -187,6 +188,7 @@ def __init__(self,
187188
if user_agent and user_agent.strip():
188189
ua_string = user_agent.strip() + " " + ua_string
189190
self.session.headers["User-Agent"] = ua_string
191+
self.uuid = str(uuid4())
190192

191193
def _get_auth(self, ims_host, ims_endpoint_jwt,
192194
tech_acct_id=None, api_key=None, client_secret=None,
@@ -479,17 +481,17 @@ def make_call(self, path, body=None, delete=False):
479481
:param body: (optional) list of dictionaries to be serialized into the request body
480482
:return: the requests.result object (on 200 response), raise error otherwise
481483
"""
484+
extra_headers = {"X-Request-Id": f"{self.uuid}_{int(datetime.now().timestamp()*1000)}"}
485+
# if the sync_started or sync_ended flags are set, send a header for any type of call
486+
if self.sync_started:
487+
self.logger.info("Sending start_sync signal")
488+
extra_headers['Pragma'] = 'umapi-sync-start'
489+
self.sync_started = False
490+
elif self.sync_ended:
491+
self.logger.info("Sending end_sync signal")
492+
extra_headers['Pragma'] = 'umapi-sync-end'
493+
self.sync_ended = False
482494
if body:
483-
extra_headers = {}
484-
# if the sync_started or sync_ended flags are set, send a header on this POST
485-
if self.sync_started:
486-
self.logger.info("Sending start_sync signal")
487-
extra_headers['Pragma'] = 'umapi-sync-start'
488-
self.sync_started = False
489-
elif self.sync_ended:
490-
self.logger.info("Sending end_sync signal")
491-
extra_headers['Pragma'] = 'umapi-sync-end'
492-
self.sync_ended = False
493495
request_body = json.dumps(body)
494496
def call():
495497
return self.session.post(self.endpoint + path, auth=self.auth, data=request_body, timeout=self.timeout,
@@ -498,11 +500,11 @@ def call():
498500
if not delete:
499501
def call():
500502
return self.session.get(self.endpoint + path, auth=self.auth, timeout=self.timeout,
501-
verify=self.ssl_verify, headers={"X-Request-Id": str(uuid.uuid4())})
503+
verify=self.ssl_verify, headers=extra_headers)
502504
else:
503505
def call():
504506
return self.session.delete(self.endpoint + path, auth=self.auth, timeout=self.timeout,
505-
verify=self.ssl_verify)
507+
verify=self.ssl_verify, headers=extra_headers)
506508

507509
start_time = time()
508510
result = None

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.18"
21+
__version__ = "2.19"

0 commit comments

Comments
 (0)