5
5
from oauth_helper import update_access_token
6
6
import re
7
7
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
+
8
18
def paging_get_request_to_webex (
9
19
helper ,
10
20
base_endpoint ,
@@ -22,8 +32,10 @@ def paging_get_request_to_webex(
22
32
params ["max" ] = _MAX_PAGE_SIZE if not params .get ("max" ) else params ["max" ]
23
33
24
34
paging = True
35
+ next_page_link = None
25
36
try :
26
37
while paging :
38
+ helper .log_debug ("[-] next_page_link {}" .format (next_page_link ))
27
39
data ,response_header = make_get_request_to_webex (
28
40
helper ,
29
41
base_endpoint ,
@@ -34,6 +46,7 @@ def paging_get_request_to_webex(
34
46
client_id ,
35
47
client_secret ,
36
48
params ,
49
+ next_page_link
37
50
)
38
51
39
52
if data is None or len (data )== 0 :
@@ -42,24 +55,15 @@ def paging_get_request_to_webex(
42
55
# append paging data
43
56
results .extend (data .get (response_tag ))
44
57
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 } " )
63
67
else :
64
68
helper .log_debug ("[--] This is the last page for {}" .format (endpoint ))
65
69
paging = False
@@ -83,14 +87,19 @@ def make_get_request_to_webex(
83
87
client_id ,
84
88
client_secret ,
85
89
params ,
86
- retry = True ,
90
+ next_page_link ,
91
+ retry = True
87
92
):
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
89
98
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 } "
94
103
95
104
helper .log_debug ("[-] url: {} -- params: {}" .format (url , params ))
96
105
headers = {
0 commit comments