Skip to content
This repository was archived by the owner on Nov 22, 2024. It is now read-only.

Commit 586ba80

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

1 file changed

Lines changed: 5 additions & 35 deletions

File tree

CloudFlare/cloudflare.py

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from .network import CFnetwork
88
from .logging_helper import CFlogger
9-
from .utils import user_agent, sanitize_secrets
9+
from .utils import user_agent, build_curl
1010
from .read_configs import read_configs
1111
from .api_v4 import api_v4
1212
from .api_extras import api_extras
@@ -164,29 +164,6 @@ def _call_network(self, method, headers, parts,
164164
params=None, data=None, files=None):
165165
""" Cloudflare v4 API"""
166166

167-
if self.logger:
168-
self.logger.debug('Call: %s,%s,%s,%s,%s,%s',
169-
str(parts[0]),
170-
str(identifier1),
171-
str(parts[1]),
172-
str(identifier2),
173-
str(parts[2]),
174-
str(identifier3))
175-
if params is not None:
176-
try:
177-
str_params = json.dumps(params)
178-
except:
179-
str_params = str(params)
180-
self.logger.debug('Call: params=%s', str_params)
181-
if data is not None:
182-
try:
183-
str_data = json.dumps(data)
184-
except:
185-
str_data = str(data)
186-
self.logger.debug('Call: data=%s', str_data)
187-
if files is not None:
188-
self.logger.debug('Call: upload file %r', files)
189-
190167
if (method is None) or (parts[0] is None):
191168
# should never happen
192169
raise CloudFlareInternalError(0, 'You must specify a method and endpoint')
@@ -219,23 +196,16 @@ def _call_network(self, method, headers, parts,
219196
url += '/' + identifier3
220197

221198
if self.logger:
222-
self.logger.debug('Call: method=%s url=%s', str(method), str(url))
223-
self.logger.debug('Call: headers=%s', str(sanitize_secrets(headers)))
199+
msg = build_curl(method, url, headers, params, data, files)
200+
self.logger.debug('Call: emulated curl command ...\n' + msg)
224201

225202
try:
226-
if self.logger:
227-
self.logger.debug('Call: doit!')
228203
response = self.network(method, url, headers, params, data, files)
229-
if self.logger:
230-
self.logger.debug('Call: done!')
231204
except Exception as e:
232205
if self.logger:
233206
self.logger.debug('Call: exception! "%s"' % (e))
234207
raise CloudFlareAPIError(0, 'connection failed.')
235208

236-
if self.logger:
237-
self.logger.debug('Response: url=%s', response.url)
238-
239209
# Create response_{type|code|data}
240210
try:
241211
response_type = response.headers['Content-Type']
@@ -929,8 +899,8 @@ def __init__(self, email=None, token=None, certtoken=None, debug=False, raw=Fals
929899

930900
try:
931901
config = read_configs(profile)
932-
except:
933-
raise CloudFlareAPIError(0, 'profile/configuration read error')
902+
except Exception as e:
903+
raise CloudFlareAPIError(0, str(e))
934904

935905
# class creation values override all configuration values
936906
if email is not None:

0 commit comments

Comments
 (0)