51 lines
1.7 KiB
Python
51 lines
1.7 KiB
Python
import requests
|
|
|
|
def getHeaders(credentials):
|
|
headers = {'Authorization': f'Bearer {credentials["api_key"]}', 'X-Auth-Email': f'{credentials["email"]}',
|
|
'Content-Type': 'application/json'}
|
|
return headers
|
|
|
|
def errorChecker(r):
|
|
if r.status_code != 200:
|
|
print(f'Error {r.status_code}.\nDetails:\n{r.json()}')
|
|
assert False
|
|
|
|
def verifyCredentials(credentials):
|
|
"""
|
|
curl -X GET "https://api.cloudflare.com/client/v4/user/tokens/verify" \
|
|
-H "Authorization: Bearer <API TOKEN HERE>" \
|
|
-H "Content-Type:application/json"
|
|
"""
|
|
headers = getHeaders(credentials)
|
|
r = requests.get('https://api.cloudflare.com/client/v4/user/tokens/verify', headers=headers)
|
|
errorChecker(r)
|
|
return r
|
|
|
|
|
|
def listAllZones(credentials):
|
|
"""
|
|
curl -X GET "https://api.cloudflare.com/client/v4/zones \
|
|
-H "X-Auth-Email: user@example.com" \
|
|
-H "X-Auth-Key: c2547eb745079dac9320b638f5e225cf483cc5cfdda41" \
|
|
-H "Content-Type: application/json"
|
|
"""
|
|
headers = getHeaders(credentials)
|
|
zones = requests.get('https://api.cloudflare.com/client/v4/zones', headers= headers)
|
|
return zones
|
|
|
|
|
|
def getAllDNS(credentials):
|
|
"""
|
|
curl -X GET "https://api.cloudflare.com/client/v4/zones/023e105f4ecef8ad9ca31a8372d0c353/ \
|
|
-H "X-Auth-Email: user@example.com" \
|
|
-H "X-Auth-Key: c2547eb745079dac9320b638f5e225cf483cc5cfdda41" \
|
|
-H "Content-Type: application/json"
|
|
"""
|
|
|
|
def deleteARecord(credentials):
|
|
"""
|
|
curl -X DELETE "https://api.cloudflare.com/client/v4/zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records/372e67954025e0ba6aaa6d586b9e0b59" \
|
|
-H "X-Auth-Email: user@example.com" \
|
|
-H "X-Auth-Key: c2547eb745079dac9320b638f5e225cf483cc5cfdda41" \
|
|
-H "Content-Type: application/json"
|
|
""" |