Skip to content

Commit

Permalink
chore(dns-edit): update to new cloudflare module
Browse files Browse the repository at this point in the history
  • Loading branch information
nijel committed Jun 27, 2024
1 parent 11140a2 commit 1ccd259
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions dns-edit
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
#!/usr/bin/env python3
import CloudFlare
from cloudflare import Cloudflare
import os
from configparser import ConfigParser
import sys

if len(sys.argv) != 4:
raise ValueError("Usage: dns-edit IPV4 IPV6 NAME")

cf = CloudFlare.CloudFlare()
zone = cf.zones.get(params={"name": "weblate.cloud"})[0]
zone_id = zone["id"]
zone_name = zone["name"]
print("editing zone_id=%s zone_name=%s" % (zone_id, zone_name))
cp = ConfigParser()
cp.read([os.path.expanduser("~/.cloudflare/cloudflare.cfg")])
token = cp.get("Cloudflare", "token")

cf.zones.dns_records.post(
zone_id,
data={"name": sys.argv[3], "type": "A", "content": sys.argv[1]},
cf = Cloudflare(api_token=token)
zone = cf.zones.list(name="weblate.cloud").result[0]
print("editing zone_id=%s zone_name=%s" % (zone.id, zone.name))

cf.dns.records.create(
zone_id=zone.id,
name=sys.argv[3],
type="A",
content=sys.argv[1],
)
cf.zones.dns_records.post(
zone_id,
data={"name": sys.argv[3], "type": "AAAA", "content": sys.argv[2]},
cf.dns.records.create(
zone_id=zone.id,
name=sys.argv[3],
type="AAAA",
content=sys.argv[2],
)

0 comments on commit 1ccd259

Please sign in to comment.