-
Notifications
You must be signed in to change notification settings - Fork 7
/
GDTest.py
77 lines (56 loc) · 2.02 KB
/
GDTest.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
import json
import requests
from domainconnectzone.DomainConnectImpl import *
try:
raw_input
except:
raw_input = input
template_dir = '/home/arnoldb/templates'
def ReadZoneRecords(domain, apiKeySecret):
r = requests.get('https://api.godaddy.com/v1/domains/' + domain + '/records', headers={'Authorization' : 'sso-key ' + apiKeySecret})
if r.status_code == 200:
return r.json()
return None
def WriteZoneRecords(domain, zone_records, apiKeySecret):
r = requests.put('https://api.godaddy.com/v1/domains/' + domain + '/records', headers={'Authorization' : 'sso-key ' + apiKeySecret}, json=zone_records)
return r.status_code
def run():
# Collect the data
print("Enter domain:")
domain = raw_input()
print("Enter host:")
host = raw_input()
if host == '':
host = None
print("Enter Service Provider Id (template providerId):")
providerId = raw_input()
print("Enter Service Id (template serviceId):")
serviceId = raw_input()
# Create the DomainConnect Object
try:
dc = DomainConnect(providerId, serviceId, template_dir)
except InvalidTemplate:
print ("Unknown or missing template")
return
# Ask for an API Key (GoDaddy Specific)
print("Enter GoDaddy API Key (see https://developer.godaddy.com/keys):")
apiKey = raw_input()
# Read the zone
zone_records = ReadZoneRecords(domain, apiKey)
if zone_records == None:
print("Unknown or unauthorized domain")
return
# Now use the domain connect object to prompt for variables
params = dc.prompt()
# Apply the zone
new_r, deleted_r, final_r = dc.apply_template(zone_records, domain, host, params, ignore_signature=True)
# Echo the final records
print("Final Records")
print(json.dumps(final_r, indent=2))
# Write them to the zone
status = WriteZoneRecords(domain, final_r, apiKey)
# Display the result
if status != 200:
print("Write failed: " + status)
return
print("Template applied")