21
21
import json
22
22
import logging
23
23
import os
24
- import uuid
25
24
from email .utils import parsedate_tz , mktime_tz
26
25
from platform import python_version , version as platform_version
27
26
from random import randint
28
27
from time import time , sleep , gmtime , strftime
28
+ from uuid import uuid4
29
+ from datetime import datetime
29
30
import requests
30
31
import io
31
32
import urllib .parse as urlparse
@@ -187,6 +188,7 @@ def __init__(self,
187
188
if user_agent and user_agent .strip ():
188
189
ua_string = user_agent .strip () + " " + ua_string
189
190
self .session .headers ["User-Agent" ] = ua_string
191
+ self .uuid = str (uuid4 ())
190
192
191
193
def _get_auth (self , ims_host , ims_endpoint_jwt ,
192
194
tech_acct_id = None , api_key = None , client_secret = None ,
@@ -479,17 +481,17 @@ def make_call(self, path, body=None, delete=False):
479
481
:param body: (optional) list of dictionaries to be serialized into the request body
480
482
:return: the requests.result object (on 200 response), raise error otherwise
481
483
"""
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
482
494
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
493
495
request_body = json .dumps (body )
494
496
def call ():
495
497
return self .session .post (self .endpoint + path , auth = self .auth , data = request_body , timeout = self .timeout ,
@@ -498,11 +500,11 @@ def call():
498
500
if not delete :
499
501
def call ():
500
502
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 )
502
504
else :
503
505
def call ():
504
506
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 )
506
508
507
509
start_time = time ()
508
510
result = None
0 commit comments