verify access and list zones
This commit is contained in:
parent
81cd95924e
commit
790a38a970
3
.gitignore
vendored
3
.gitignore
vendored
@ -168,4 +168,5 @@ cython_debug/
|
||||
|
||||
|
||||
# Project setup
|
||||
config.json
|
||||
config.json
|
||||
response-example*
|
||||
51
apicalls.py
Normal file
51
apicalls.py
Normal file
@ -0,0 +1,51 @@
|
||||
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"
|
||||
"""
|
||||
6
app.py
6
app.py
@ -2,6 +2,7 @@ import json
|
||||
from sys import argv
|
||||
from pathlib import Path
|
||||
import requests
|
||||
from apicalls import *
|
||||
|
||||
|
||||
# Get API key and Email address
|
||||
@ -24,4 +25,7 @@ if len(argv) > 1 and 'loadconfig' in argv:
|
||||
else:
|
||||
credentials = getCredentials()
|
||||
|
||||
# print(credentials)
|
||||
# print(credentials)
|
||||
|
||||
zones = listAllZones(credentials).json()["result"]
|
||||
# print(f"{zones.status_code}\n{zones.json()}")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user