Skip to content

Commit

Permalink
CloudFlare API v4 complete rewrite. Added all API calls. Added exampl…
Browse files Browse the repository at this point in the history
…es. Added CLU tool. Added initial tests. Updated README
  • Loading branch information
mahtin committed May 3, 2016
1 parent edefd99 commit 1eed90b
Show file tree
Hide file tree
Showing 22 changed files with 1,499 additions and 131 deletions.
297 changes: 297 additions & 0 deletions CloudFlare/__init__.py

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions CloudFlare/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

class CloudFlareError(Exception):
def __init__(self, code, message):
self.code = code
self.message = message

def __int__(self):
return self.code

def __str__(self):
return self.message

class CloudFlareAPIError(CloudFlareError):
pass

class CloudFlareInternalError(CloudFlareError):
pass

File renamed without changes.
35 changes: 35 additions & 0 deletions CloudFlare/read_configs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import os
import re
import ConfigParser

def read_configs():

# envioronment variables override config files
email = os.getenv('CF_API_EMAIL')
token = os.getenv('CF_API_KEY')
certtoken = os.getenv('CF_API_CERTKEY')

# grab values from config files
config = ConfigParser.RawConfigParser()
config.read(['.cloudflare.cfg', os.path.expanduser('~/.cloudflare.cfg'), os.path.expanduser('~/.cloudflare/cloudflare.cfg')])

if email is None:
try:
email = re.sub(r"\s+", '', config.get('CloudFlare', 'email'))
except:
email = None

if token is None:
try:
token = re.sub(r"\s+", '', config.get('CloudFlare', 'token'))
except:
token = None

if certtoken is None:
try:
certtoken = re.sub(r"\s+", '', config.get('CloudFlare', 'certtoken'))
except:
certtoken = None

return [ email, token, certtoken ]

5 changes: 5 additions & 0 deletions cloudflare_v4/utils.py → CloudFlare/utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
def sanitize_secrets(secrets):
redacted_phrase = 'REDACTED'

if secrets is None:
return None

secrets_copy = secrets.copy()
if 'password' in secrets_copy:
secrets_copy['password'] = redacted_phrase
elif 'X-Auth-Key' in secrets_copy:
secrets_copy['X-Auth-Key'] = redacted_phrase
elif 'X-Auth-User-Service-Key' in secrets_copy:
secrets_copy['X-Auth-User-Service-Key'] = redacted_phrase

return secrets_copy
Loading

0 comments on commit 1eed90b

Please sign in to comment.