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

Commit 8e79a53

Browse files
committed
posting dns_records to zone
1 parent 0dee0ba commit 8e79a53

2 files changed

Lines changed: 21 additions & 14 deletions

File tree

cloudflare_v4/util.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,28 @@
44
import json
55
import requests
66

7-
logger = logger.Logger(logger.DEBUG).getLogger()
7+
logger = logger.Logger(logger.INFO).getLogger()
8+
BASE_URL = 'https://api.cloudflare.com/client/v4'
89

910
def call(auth, method, endpoint, params=None):
10-
logger.debug(auth)
11-
logger.debug(method)
12-
logger.debug(endpoint)
13-
logger.debug(params)
11+
headers = { "X-Auth-Email": auth['EMAIL'], "X-Auth-Key": auth['TOKEN'] }
12+
url = BASE_URL + '/' + endpoint
13+
logger.debug("auth is: " + str(auth))
14+
logger.debug("method type is: " + method)
15+
logger.debug("url endpoint is: " + url)
16+
logger.debug("optional params is: " + str(params))
1417
if (auth is None) or (method is None) or (endpoint is None):
1518
raise CloudFlareError('You must specify auth, method, and endpoint')
1619
else:
17-
response = requests.request(method,
18-
'https://api.cloudflare.com/client/v4/' + endpoint,
19-
headers={ "X-Auth-Email": auth['EMAIL'],
20-
"X-Auth-Key": auth['TOKEN'] },
21-
params=params
22-
)
20+
if method.upper() == 'GET':
21+
logger.debug("headers being sent: " + str(headers))
22+
response = requests.get(url, headers=headers, params=params)
23+
elif method.upper() == 'POST':
24+
headers['Content-Type'] = 'application/json'
25+
logger.debug("headers being sent: " + str(headers))
26+
response = requests.post(url, headers=headers, json=params)
2327
data = response.text
24-
logger.debug(data)
28+
logger.debug("data received: " + data)
2529
try:
2630
data = json.loads(data)
2731
return data

cloudflare_v4/zones/dns_records.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@
22

33
ENDPOINT = 'dns_records'
44

5-
def get(auth, params=None):
6-
util.call(auth, 'GET', 'zones/' + params + '/' + ENDPOINT)
5+
def get(auth, zone_id, params=None):
6+
return util.call(auth, 'GET', 'zones/' + zone_id + '/' + ENDPOINT, params)
7+
8+
def post(auth, zone_id, params=None):
9+
return util.call(auth, 'POST', 'zones/' + zone_id + '/' + ENDPOINT, params)

0 commit comments

Comments
 (0)