This repository has been archived by the owner on Dec 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
holo-dns-delete.py
105 lines (85 loc) · 3.56 KB
/
holo-dns-delete.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
from zato.server.service import Service
from json import dumps
import httplib
class HoloDnsDelete(Service):
def checkKey(self, d, key):
return key in d
def handle(self):
# miscellaneous logging
self.logger.info(type(self.request.raw_request))
self.logger.info(self.request.raw_request)
self.logger.info('cid:[{}]'.format(self.cid))
# prep data
data = self.request.bunchified()
# exit if no pubkey incoming
if not self.checkKey(data, 'pubkey'):
response = {"error": "request must contain a public key"}
self.response.status_code = httplib.BAD_REQUEST
self.response.payload = dumps(response)
return
# else
# kvdb
service = 'zato.kvdb.data-dict.dictionary.get-value-list'
ddrequest = {'system':'cloudflare', 'key': 'auth_key'}
ddresponse = self.invoke(service, ddrequest)
auth_key = ddresponse["zato_kvdb_data_dict_dictionary_get_value_list_response"][0]["name"]
self.logger.info(auth_key)
ddrequest = {'system':'cloudflare', 'key': 'auth_email'}
ddresponse = self.invoke(service, ddrequest)
auth_email = ddresponse["zato_kvdb_data_dict_dictionary_get_value_list_response"][0]["name"]
self.logger.info(auth_email)
# Headers the endpoint expects
headers = {'X-Auth-Email':auth_email, 'X-Auth-Key':auth_key}
ddrequest = {'system':'cloudflare', 'key': 'zone'}
ddresponse = self.invoke(service, ddrequest)
zone = ddresponse["zato_kvdb_data_dict_dictionary_get_value_list_response"][0]["name"]
self.logger.info(zone)
# ---------------- Part One -------------------- #
# get domain id for domain
# params
domain = "*." + data.pubkey + ".holohost.net"
dtype = "CNAME"
params = {"zone":zone, "type":dtype, "domain":domain}
# Obtains a connection object
conn = self.outgoing.plain_http['cloudflare-dns-by-name'].conn
# Invoke the resource providing all the information on input
try:
response = conn.get(self.cid, params, headers=headers)
response_dict = response.json()
domain_id = response_dict["result"][0]["id"]
except:
response = {"error": "something broke"}
self.response.status_code = httplib.BAD_GATEWAY # 502
self.response.payload = dumps(response)
return
else:
# ---------------- Part Two -------------------- #
# DELETE domain by id
# params
params = {"zone":zone, "record_id":domain_id}
# Obtains a connection object
conn = self.outgoing.plain_http['cloudflare-dns-delete'].conn
# Invoke the resource providing all the information on input
response = conn.delete(self.cid, params, headers=headers)
# if no response
"""
if not response:
response = {"error": "no response"}
self.response.status_code = httplib.BAD_GATEWAY # 502
self.response.payload = dumps(response)
return
"""
# else
self.response.payload = dumps(response.json())
return
"""
uses the following server objects
outconn:cloudflare-dns-read:
https://api.cloudflare.com
/client/v4/zones/{zone}/dns_records
Cloudflare API
outconn:cloudflare-dns-delete:
https://api.cloudflare.com
/client/v4/zones/{zone}/dns_records/{record_id}
Cloudflare API
"""