55from oauth_helper import update_access_token
66import re
77
8+ def extract_link_regex (link_header_string ):
9+ """
10+ Extracts the URL from a Link header-like string using regex.
11+ """
12+ match = re .search (r'<([^>]+)>;' , link_header_string )
13+ if match :
14+ return match .group (1 )
15+ else :
16+ raise ValueError (f"Next page link string does not match expected link header format: '{ link_header_string } '" )
17+
818def paging_get_request_to_webex (
919 helper ,
1020 base_endpoint ,
@@ -22,8 +32,10 @@ def paging_get_request_to_webex(
2232 params ["max" ] = _MAX_PAGE_SIZE if not params .get ("max" ) else params ["max" ]
2333
2434 paging = True
35+ next_page_link = None
2536 try :
2637 while paging :
38+ helper .log_debug ("[-] next_page_link {}" .format (next_page_link ))
2739 data ,response_header = make_get_request_to_webex (
2840 helper ,
2941 base_endpoint ,
@@ -34,6 +46,7 @@ def paging_get_request_to_webex(
3446 client_id ,
3547 client_secret ,
3648 params ,
49+ next_page_link
3750 )
3851
3952 if data is None or len (data )== 0 :
@@ -42,24 +55,15 @@ def paging_get_request_to_webex(
4255 # append paging data
4356 results .extend (data .get (response_tag ))
4457
45- next_page_link = response_header .get ("link" , None )
46- helper .log_debug ("[--] next_page_link {}" .format (next_page_link ))
47-
48- if next_page_link :
49- # update offset to get the next page
50- if "offset" in next_page_link :
51- offset = int (params .get ("offset" , 0 )) + len (data .get (response_tag ))
52- params ["offset" ] = offset
53- else :
54- # Regular expression to find the cursor value
55- # This will capture characters following 'cursor=' until it hits either '&' or the end of the string
56- match = re .search (r'cursor=([^&>]+)' , next_page_link )
57- # Extract the cursor value if it is found
58- if match :
59- cursor_value = match .group (1 )
60- params ["cursor" ] = cursor_value
61- else :
62- raise Exception ("Cursor value not found for next page" )
58+ next_page_link_header = response_header .get ("link" , None )
59+ helper .log_debug ("[--] next_page_link_header {}" .format (next_page_link_header ))
60+
61+ if next_page_link_header :
62+ try :
63+ next_page_link = extract_link_regex (next_page_link_header )
64+ helper .log_debug ("[--] next_page_link {}" .format (next_page_link ))
65+ except ValueError as e :
66+ helper .log_error (f"Next page link extraction failed (regex): { e } " )
6367 else :
6468 helper .log_debug ("[--] This is the last page for {}" .format (endpoint ))
6569 paging = False
@@ -83,14 +87,19 @@ def make_get_request_to_webex(
8387 client_id ,
8488 client_secret ,
8589 params ,
86- retry = True ,
90+ next_page_link ,
91+ retry = True
8792):
88- url = _BASE_URL .format (base_endpoint = base_endpoint ) + endpoint
93+ if next_page_link :
94+ url = next_page_link
95+ params = None
96+ else :
97+ url = _BASE_URL .format (base_endpoint = base_endpoint ) + endpoint
8998
90- # reconstruct the url for meeting/qualities and cdr_feed endpoints
91- if endpoint == "meeting/qualities" or endpoint == "cdr_feed" :
92- protocol , rest = url .split ("//" )
93- url = f"{ protocol } //analytics.{ rest } "
99+ # reconstruct the url for meeting/qualities and cdr_feed endpoints
100+ if endpoint == "meeting/qualities" or endpoint == "cdr_feed" :
101+ protocol , rest = url .split ("//" )
102+ url = f"{ protocol } //analytics.{ rest } "
94103
95104 helper .log_debug ("[-] url: {} -- params: {}" .format (url , params ))
96105 headers = {
0 commit comments