diff --git a/CloudFlare/cloudflare.py b/CloudFlare/cloudflare.py index 5c2ff58..f38ed91 100644 --- a/CloudFlare/cloudflare.py +++ b/CloudFlare/cloudflare.py @@ -38,7 +38,7 @@ def call_with_no_auth(self, method, api_call_part1, api_call_part2=None, api_call_part3=None, - identifier1=None, identifier2=None, + identifier1=None, identifier2=None, identifier3=None, params=None, data=None): """ Cloudflare v4 API""" @@ -48,14 +48,14 @@ def call_with_no_auth(self, method, } return self._call(method, headers, api_call_part1, api_call_part2, api_call_part3, - identifier1, identifier2, + identifier1, identifier2, identifier3, params, data) def call_with_auth(self, method, api_call_part1, api_call_part2=None, api_call_part3=None, - identifier1=None, identifier2=None, + identifier1=None, identifier2=None, identifier3=None, params=None, data=None): """ Cloudflare v4 API""" @@ -69,14 +69,14 @@ def call_with_auth(self, method, } return self._call(method, headers, api_call_part1, api_call_part2, api_call_part3, - identifier1, identifier2, + identifier1, identifier2, identifier3, params, data) def call_with_certauth(self, method, api_call_part1, api_call_part2=None, api_call_part3=None, - identifier1=None, identifier2=None, + identifier1=None, identifier2=None, identifier3=None, params=None, data=None): """ Cloudflare v4 API""" @@ -89,16 +89,32 @@ def call_with_certauth(self, method, } return self._call(method, headers, api_call_part1, api_call_part2, api_call_part3, - identifier1, identifier2, + identifier1, identifier2, identifier3, params, data) def _raw(self, method, headers, api_call_part1, api_call_part2=None, api_call_part3=None, - identifier1=None, identifier2=None, + identifier1=None, identifier2=None, identifier3=None, params=None, data=None): """ Cloudflare v4 API""" + if self.logger: + self.logger.debug('Call: %s,%s,%s,%s,%s,%s' % (str(api_call_part1), + str(identifier1), + str(api_call_part2), + str(identifier2), + str(api_call_part3), + str(identifier3))) + self.logger.debug('Call: optional params and data %s %s' % (str(params), + str(data))) + + if (method is None) or (api_call_part1 is None): + # should never happen + raise CloudFlareInternalError(0, 'You must specify a method and endpoint') + if api_call_part2 is not None or (data is not None and method == 'GET'): + if identifier1 is None: + raise CloudFlareAPIError(0, 'You must specify identifier1') if identifier2 is None: url = (self.base_url + '/' + api_call_part1 + '/' @@ -120,22 +136,13 @@ def _raw(self, method, headers, + identifier1) if api_call_part3: url += '/' + api_call_part3 + if identifier3: + url += '/' + identifier3 if self.logger: - self.logger.debug('Call: %s,%s,%s,%s,%s' % (str(api_call_part1), - str(identifier1), - str(api_call_part2), - str(identifier2), - str(api_call_part3))) - self.logger.debug('Call: optional params and data %s %s' % (str(params), - str(data))) self.logger.debug('Call: method and url %s %s' % (str(method), str(url))) self.logger.debug('Call: headers %s' % str(sanitize_secrets(headers))) - if (method is None) or (api_call_part1 is None): - # should never happen - raise CloudFlareInternalError(0, 'You must specify a method and endpoint') - method = method.upper() if self.logger: @@ -180,13 +187,13 @@ def _call(self, method, headers, api_call_part1, api_call_part2=None, api_call_part3=None, - identifier1=None, identifier2=None, + identifier1=None, identifier2=None, identifier3=None, params=None, data=None): """ Cloudflare v4 API""" response_data = self._raw(method, headers, api_call_part1, api_call_part2, api_call_part3, - identifier1, identifier2, + identifier1, identifier2, identifier3, params, data) # Sanatize the returned results - just in case API is messed up @@ -259,27 +266,27 @@ def __init__(self, base, api_call_part1, api_call_part2=None, api_call_part3=Non # self.api_call_part2 = api_call_part2 # self.api_call_part3 = api_call_part3 - def get(self, identifier1=None, identifier2=None, params=None, data=None): + def get(self, identifier1=None, identifier2=None, identifier3=None, params=None, data=None): """ Cloudflare v4 API""" raise CloudFlareAPIError(0, 'get() call not available for this endpoint') - def patch(self, identifier1=None, identifier2=None, params=None, data=None): + def patch(self, identifier1=None, identifier2=None, identifier3=None, params=None, data=None): """ Cloudflare v4 API""" raise CloudFlareAPIError(0, 'patch() call not available for this endpoint') - def post(self, identifier1=None, identifier2=None, params=None, data=None): + def post(self, identifier1=None, identifier2=None, identifier3=None, params=None, data=None): """ Cloudflare v4 API""" raise CloudFlareAPIError(0, 'post() call not available for this endpoint') - def put(self, identifier1=None, identifier2=None, params=None, data=None): + def put(self, identifier1=None, identifier2=None, identifier3=None, params=None, data=None): """ Cloudflare v4 API""" raise CloudFlareAPIError(0, 'put() call not available for this endpoint') - def delete(self, identifier1=None, identifier2=None, params=None, data=None): + def delete(self, identifier1=None, identifier2=None, identifier3=None, params=None, data=None): """ Cloudflare v4 API""" raise CloudFlareAPIError(0, 'delete() call not available for this endpoint') @@ -295,32 +302,32 @@ def __init__(self, base, api_call_part1, api_call_part2=None, api_call_part3=Non self.api_call_part2 = api_call_part2 self.api_call_part3 = api_call_part3 - def get(self, identifier1=None, identifier2=None, params=None, data=None): + def get(self, identifier1=None, identifier2=None, identifier3=None, params=None, data=None): """ Cloudflare v4 API""" return self._base.call_with_no_auth('GET', self.api_call_part1, self.api_call_part2, self.api_call_part3, - identifier1, identifier2, + identifier1, identifier2, identifier3, params, data) - def patch(self, identifier1=None, identifier2=None, params=None, data=None): + def patch(self, identifier1=None, identifier2=None, identifier3=None, params=None, data=None): """ Cloudflare v4 API""" raise CloudFlareAPIError(0, 'patch() call not available for this endpoint') - def post(self, identifier1=None, identifier2=None, params=None, data=None): + def post(self, identifier1=None, identifier2=None, identifier3=None, params=None, data=None): """ Cloudflare v4 API""" raise CloudFlareAPIError(0, 'post() call not available for this endpoint') - def put(self, identifier1=None, identifier2=None, params=None, data=None): + def put(self, identifier1=None, identifier2=None, identifier3=None, params=None, data=None): """ Cloudflare v4 API""" raise CloudFlareAPIError(0, 'put() call not available for this endpoint') - def delete(self, identifier1=None, identifier2=None, params=None, data=None): + def delete(self, identifier1=None, identifier2=None, identifier3=None, params=None, data=None): """ Cloudflare v4 API""" raise CloudFlareAPIError(0, 'delete() call not available for this endpoint') @@ -336,54 +343,54 @@ def __init__(self, base, api_call_part1, api_call_part2=None, api_call_part3=Non self.api_call_part2 = api_call_part2 self.api_call_part3 = api_call_part3 - def get(self, identifier1=None, identifier2=None, params=None, data=None): + def get(self, identifier1=None, identifier2=None, identifier3=None, params=None, data=None): """ Cloudflare v4 API""" return self._base.call_with_auth('GET', self.api_call_part1, self.api_call_part2, self.api_call_part3, - identifier1, identifier2, + identifier1, identifier2, identifier3, params, data) - def patch(self, identifier1=None, identifier2=None, params=None, data=None): + def patch(self, identifier1=None, identifier2=None, identifier3=None, params=None, data=None): """ Cloudflare v4 API""" return self._base.call_with_auth('PATCH', self.api_call_part1, self.api_call_part2, self.api_call_part3, - identifier1, identifier2, + identifier1, identifier2, identifier3, params, data) - def post(self, identifier1=None, identifier2=None, params=None, data=None): + def post(self, identifier1=None, identifier2=None, identifier3=None, params=None, data=None): """ Cloudflare v4 API""" return self._base.call_with_auth('POST', self.api_call_part1, self.api_call_part2, self.api_call_part3, - identifier1, identifier2, + identifier1, identifier2, identifier3, params, data) - def put(self, identifier1=None, identifier2=None, params=None, data=None): + def put(self, identifier1=None, identifier2=None, identifier3=None, params=None, data=None): """ Cloudflare v4 API""" return self._base.call_with_auth('PUT', self.api_call_part1, self.api_call_part2, self.api_call_part3, - identifier1, identifier2, + identifier1, identifier2, identifier3, params, data) - def delete(self, identifier1=None, identifier2=None, params=None, data=None): + def delete(self, identifier1=None, identifier2=None, identifier3=None, params=None, data=None): """ Cloudflare v4 API""" return self._base.call_with_auth('DELETE', self.api_call_part1, self.api_call_part2, self.api_call_part3, - identifier1, identifier2, + identifier1, identifier2, identifier3, params, data) class _add_with_cert_auth(object): @@ -397,54 +404,54 @@ def __init__(self, base, api_call_part1, api_call_part2=None, api_call_part3=Non self.api_call_part2 = api_call_part2 self.api_call_part3 = api_call_part3 - def get(self, identifier1=None, identifier2=None, params=None, data=None): + def get(self, identifier1=None, identifier2=None, identifier3=None, params=None, data=None): """ Cloudflare v4 API""" return self._base.call_with_certauth('GET', self.api_call_part1, self.api_call_part2, self.api_call_part3, - identifier1, identifier2, + identifier1, identifier2, identifier3, params, data) - def patch(self, identifier1=None, identifier2=None, params=None, data=None): + def patch(self, identifier1=None, identifier2=None, identifier3=None, params=None, data=None): """ Cloudflare v4 API""" return self._base.call_with_certauth('PATCH', self.api_call_part1, self.api_call_part2, self.api_call_part3, - identifier1, identifier2, + identifier1, identifier2, identifier3, params, data) - def post(self, identifier1=None, identifier2=None, params=None, data=None): + def post(self, identifier1=None, identifier2=None, identifier3=None, params=None, data=None): """ Cloudflare v4 API""" return self._base.call_with_certauth('POST', self.api_call_part1, self.api_call_part2, self.api_call_part3, - identifier1, identifier2, + identifier1, identifier2, identifier3, params, data) - def put(self, identifier1=None, identifier2=None, params=None, data=None): + def put(self, identifier1=None, identifier2=None, identifier3=None, params=None, data=None): """ Cloudflare v4 API""" return self._base.call_with_certauth('PUT', self.api_call_part1, self.api_call_part2, self.api_call_part3, - identifier1, identifier2, + identifier1, identifier2, identifier3, params, data) - def delete(self, identifier1=None, identifier2=None, params=None, data=None): + def delete(self, identifier1=None, identifier2=None, identifier3=None, params=None, data=None): """ Cloudflare v4 API""" return self._base.call_with_certauth('DELETE', self.api_call_part1, self.api_call_part2, self.api_call_part3, - identifier1, identifier2, + identifier1, identifier2, identifier3, params, data) def api_list(self, m=None, s=''): diff --git a/cli4/cli4.py b/cli4/cli4.py index da39374..2b602b9 100644 --- a/cli4/cli4.py +++ b/cli4/cli4.py @@ -287,6 +287,7 @@ def cli4(args): cmd = [] identifier1 = None identifier2 = None + identifier3 = None hex_only = re.compile('^[0-9a-fA-F]+$') @@ -318,7 +319,7 @@ def cli4(args): else: exit("/%s/%s :NOT CODED YET 1" % ('/'.join(cmd), element)) cmd.append(':' + identifier1) - else: + elif identifier2 is None: if len(element) in [32, 40, 48] and hex_only.match(element): # raw identifier - lets just use it as-is identifier2 = element @@ -337,6 +338,12 @@ def cli4(args): else: cmd.append(':' + identifier2) identifier2 = [identifier2] + else: + if len(element) in [32, 40, 48] and hex_only.match(element): + # raw identifier - lets just use it as-is + identifier3 = element + else: + exit("/%s/%s :NOT CODED YET 3" % ('/'.join(cmd), element)) else: try: m = getattr(m, element) @@ -354,15 +361,15 @@ def cli4(args): for i2 in identifier2: try: if method is 'GET': - r = m.get(identifier1=identifier1, identifier2=i2, params=params) + r = m.get(identifier1=identifier1, identifier2=i2, identifier3=identifier3, params=params) elif method is 'PATCH': - r = m.patch(identifier1=identifier1, identifier2=i2, data=params) + r = m.patch(identifier1=identifier1, identifier2=i2, identifier3=identifier3, data=params) elif method is 'POST': - r = m.post(identifier1=identifier1, identifier2=i2, data=params) + r = m.post(identifier1=identifier1, identifier2=i2, identifier3=identifier3, data=params) elif method is 'PUT': - r = m.put(identifier1=identifier1, identifier2=i2, data=params) + r = m.put(identifier1=identifier1, identifier2=i2, identifier3=identifier3, data=params) elif method is 'DELETE': - r = m.delete(identifier1=identifier1, identifier2=i2, data=params) + r = m.delete(identifier1=identifier1, identifier2=i2, identifier3=identifier3, data=params) else: pass except CloudFlare.exceptions.CloudFlareAPIError as e: