Skip to content

Commit 80918ea

Browse files
committed
now with curl style debug - i.e. matches api information page
1 parent 586ba80 commit 80918ea

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

CloudFlare/utils.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,38 @@ def sanitize_secrets(secrets):
3333
secrets_copy['Authorization'] = redacted_phrase
3434

3535
return secrets_copy
36+
37+
def build_curl(method, url, headers, params, data, files):
38+
""" misc utilities for Cloudflare API"""
39+
40+
msg = []
41+
# url
42+
url_full = url
43+
if params is not None:
44+
for k in params:
45+
if k is None:
46+
continue
47+
url_full += '&%s=%s' % (k, params[k])
48+
url_full = url_full.replace('&', '?', 1)
49+
msg.append(' curl -X %s "%s" \\' % (str(method), str(url_full)))
50+
# headers
51+
h = sanitize_secrets(headers)
52+
for k in h:
53+
if k is None:
54+
continue
55+
msg.append(' -H "%s: %s" \\' % (k, h[k]))
56+
# data
57+
if data is not None:
58+
try:
59+
str_data = json.dumps(data)
60+
except:
61+
str_data = str(data)
62+
msg.append(' --data \'%s\' \\' % (str_data.replace('\n', ' ')))
63+
# files
64+
if files is not None:
65+
msg.append(' --form "file=@%s" \\' % (files))
66+
67+
# remove the last \ from the last line.
68+
msg[-1] = msg[-1][:-1]
69+
70+
return '\n'.join(msg)

0 commit comments

Comments
 (0)