|
9 | 9 | from .read_configs import read_configs |
10 | 10 | from .api_v4 import api_v4 |
11 | 11 | from .api_extras import api_extras |
| 12 | +from .api_decode_from_web import api_decode_from_web |
12 | 13 | from .exceptions import CloudFlareError, CloudFlareAPIError, CloudFlareInternalError |
13 | 14 |
|
14 | 15 | BASE_URL = 'https://api.cloudflare.com/client/v4' |
@@ -154,7 +155,7 @@ def call_with_certauth(self, method, parts, |
154 | 155 | identifier1, identifier2, identifier3, |
155 | 156 | params, data, files) |
156 | 157 |
|
157 | | - def _connection(self, method, url, headers, params, data, files): |
| 158 | + def _connection(self, method, url, headers=None, params=None, data=None, files=None): |
158 | 159 | """ Cloudflare v4 API""" |
159 | 160 |
|
160 | 161 | if self.use_sessions: |
@@ -254,10 +255,9 @@ def _network(self, method, headers, parts, |
254 | 255 | self.logger.debug('Call: method and url %s %s', str(method), str(url)) |
255 | 256 | self.logger.debug('Call: headers %s', str(sanitize_secrets(headers))) |
256 | 257 |
|
257 | | - if self.logger: |
258 | | - self.logger.debug('Call: doit!') |
259 | | - |
260 | 258 | try: |
| 259 | + if self.logger: |
| 260 | + self.logger.debug('Call: doit!') |
261 | 261 | response = self._connection(method, url, headers, params, data, files) |
262 | 262 | if self.logger: |
263 | 263 | self.logger.debug('Call: done!') |
@@ -595,6 +595,25 @@ def _call_unwrapped(self, method, headers, parts, |
595 | 595 | result = response_data |
596 | 596 | return result |
597 | 597 |
|
| 598 | + def _api_from_web(self): |
| 599 | + """ Cloudflare v4 API""" |
| 600 | + |
| 601 | + # base url isn't enough; we need less |
| 602 | + url = '/'.join(self.base_url.split('/')[0:3]) |
| 603 | + |
| 604 | + try: |
| 605 | + if self.logger: |
| 606 | + self.logger.debug('Call: doit!') |
| 607 | + response = self._connection("GET", url) |
| 608 | + if self.logger: |
| 609 | + self.logger.debug('Call: done!') |
| 610 | + except Exception as e: |
| 611 | + if self.logger: |
| 612 | + self.logger.debug('Call: exception! "%s"' % (e)) |
| 613 | + raise CloudFlareAPIError(0, 'connection failed.') |
| 614 | + |
| 615 | + return response.text |
| 616 | + |
598 | 617 | class _AddUnused(object): |
599 | 618 | """ Cloudflare v4 API""" |
600 | 619 |
|
@@ -919,6 +938,11 @@ def api_list(self, m=None, s=''): |
919 | 938 | w = w + self.api_list(a, s + '/' + n) |
920 | 939 | return w |
921 | 940 |
|
| 941 | + def api_from_web(self): |
| 942 | + """ Cloudflare v4 API""" |
| 943 | + |
| 944 | + return api_decode_from_web(self._base._api_from_web()) |
| 945 | + |
922 | 946 | def __init__(self, email=None, token=None, certtoken=None, debug=False, raw=False, use_sessions=True, profile=None): |
923 | 947 | """ Cloudflare v4 API""" |
924 | 948 |
|
|
0 commit comments