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

Commit 834509f

Browse files
committed
Added support for DNS names after /dns_records/
1 parent 637400e commit 834509f

1 file changed

Lines changed: 26 additions & 6 deletions

File tree

cli4/cli4.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,23 @@ def convert_zones_to_identifier(cf, zone_name):
3030

3131
exit('cli4: %s - zone not found' % (zone_name))
3232

33+
def convert_dns_record_to_identifier(cf, zone_id, dns_name):
34+
params = {'name':dns_name,'per_page':1}
35+
try:
36+
dns_records = cf.zones.dns_records.get(zone_id, params=params)
37+
except CloudFlare.CloudFlareAPIError as e:
38+
exit('cli4: %s - %d %s' % (dns_name, e, e))
39+
except Exception as e:
40+
exit('cli4: %s - %s' % (dns_name, e))
41+
42+
for dns_record in dns_records:
43+
name = dns_record['name']
44+
if dns_name == name:
45+
dns_id = dns_record['id']
46+
return dns_id
47+
48+
exit('cli4: %s - dns_name not found' % (dns_name))
49+
3350
def convert_certificates_to_identifier(cf, certificate_name):
3451
try:
3552
certificates = cf.certificates.get()
@@ -183,22 +200,25 @@ def cli4(args):
183200
identifier1 = convert_zones_to_identifier(cf, element)
184201
elif cmd[0] == 'zones':
185202
identifier1 = convert_zones_to_identifier(cf, element)
186-
elif (cmd[0] == 'user' and cmd[1] == 'organizations') or cmd[0] == 'organizations':
203+
elif cmd[0] == 'organizations':
204+
identifier1 = convert_organizations_to_identifier(cf, element)
205+
elif (cmd[0] == 'user') and (cmd[1] == 'organizations'):
187206
identifier1 = convert_organizations_to_identifier(cf, element)
188-
elif (cmd[0] == 'user' and cmd[1] == 'invites'):
207+
elif (cmd[0] == 'user') and (cmd[1] == 'invites'):
189208
identifier1 = convert_invites_to_identifier(cf, element)
190-
elif (cmd[0] == 'user' and cmd[1] == 'virtual_dns'):
209+
elif (cmd[0] == 'user') and (cmd[1] == 'virtual_dns'):
191210
identifier1 = convert_virtual_dns_to_identifier(cf, element)
192211
else:
193-
print cmd[0], element, ':NOT CODED YET'
194-
exit(0)
212+
exit("/%s/%s :NOT CODED YET 1" % ('/'.join(cmd), element))
195213
cmd.append(':' + identifier1)
196214
else:
197215
if len(element) in [32, 40, 48] and hex_only.match(element):
198216
# raw identifier - lets just use it as-is
199217
identifier2 = element
218+
elif (cmd[0] and cmd[0] == 'zones') and (cmd[2] and cmd[2] == 'dns_records'):
219+
identifier2 = convert_dns_record_to_identifier(cf, identifier1, element)
200220
else:
201-
identifier2 = convert_zones_to_identifier(cf, element)
221+
exit("/%s/%s :NOT CODED YET 2" % ('/'.join(cmd), element))
202222
cmd.append(':' + identifier2)
203223
else:
204224
try:

0 commit comments

Comments
 (0)