Go client wrapper and CTL tool for DNSPod API
Go client wrapper and CTL tool for DNSPOD API
Make sure you have go installed in your env.
go get -u github.com/wangzn/dnspodapi/dpctl
dpctl help
Default config file is at $HOME/.dnspod.yaml
Demo config file could be found at demo config
# test connection and print info
dpctl info
# list all domains
dpctl domain -a list
# get domain info
dpctl domain -d ashtray.wang,ashtray.name -a info
# create domain and add default record
dpctl domain -d abc.xyz,abcde.xyz -a create
# remove domain
dpctl domain -d abc.xyz,abcde.xyz -a remove
# enable domain
dpctl domain -d abc.xyz,abcde.xyz -a enable
# disable domain
dpctl domain -d abc.xyz,abcde.xyz -a diable
# list record of domain ashtray.wang and ashtray.name
dpctl record -a list -d ashtray.wang,ashtray.name
# get record info of domain ashtray.wang, with record proxy,proxy11,proxy12
dpctl record -a info -d ashtray.wang -r proxy,proxy11,proxy12
# disalbe these records and enable them again
dpctl record -a disable -d ashtray.wang -r proxy,proxy11,proxy12
dpctl record -a enable -d ashtray.wang -r proxy,proxy11,proxy12
# create a record
dpctl record -a create -d ashtray.wang -r testcreate -t A -v 1.1.1.1
# createa record with TTL 6000
dpctl record -a create -d ashtray.wang -r testcreate -t A -v 1.1.1.1 -T 6000
## import records from local file but DO NOT CLEAR conflict records
dpctl record -a import -d ashtray.wang -f testdata/records.lst
# import records from local file and CLEAR conflict ones
dpctl record -a import -d ashtray.wang -f testdata/records.lst --clear
# import record and force create domain if not exist
dpctl record -a import -d ashtray.wang,abcde.xyz -f testdata/records.lst --force-domain
# export records to file, append if file exist
dpctl record -d ashtray.wang -a export -f /dev/stdout --export-file-mode append
# export records to file, with records filter www21,www22, and overwrite local file if exist
dpctl record -d ashtray.wang -a export -f testdata/export.lst --export-file-mode overwrite -r www11,www12
# ensure records defined in a file, and import into a domain
dpctl record -a ensure -d abc.xyz -f testdata/records.lst
# ensure records defined in a file, and import into a domain, clear all conflict records, clear records not defined in `records.lst`, and clear NS record of @
dpctl record -a ensure -d abc.xyz -f testdata/records.lst --clear --exclude --force-domain
> tail -n 2 testdata/records.lst
cdn1 CNAME proxy1.
cdn2 CNAME www.{DOMAIN}.cdn.com
if the domain variable is abc.xyz
, then cdn1
will CNAME to proxy1.abc.xyz
,
and cdn2
will CNAME to www.abc.xyz.cdn.com
We can predefined some common used cmds into playbook (named as scene ), and reuse them in short command.
dpctl help playbook
scene is a list of actions , e.g.:
scene1:
- auth: "default" # could omit to use default
category: "domain"
action: "create"
subject: "abc.xyz,abcde.xyz"
params:
- auth: "default" # could omit to use default
category: "record"
action: "import"
subject: ""
params:
domain: "abc.xyz,abcde.xyz"
clear: "on"
force_domain: "off"
record_file: "testdata/record.lst"
- auth: "default" # could omit to use default
category: "record"
action: "export"
subject: "www,proxy"
params:
domain: "abc.xyz,abcde.xyz"
file_mode: "append" # overwrite, default is exit for no damage
record_file: "testdata/record.lst"
In this scene above, we define three actions:
abc.xyz,abcde.xyz
testdata/record.lst
into domain abc.xyz,abcde.xyz
testdata/record.lst
with record www
and proxy
in domain abc.xyz,abcde.xyz
then we could preview this scene in case of any unexpected cmds
dpctl playbook -a preview -s scene1
finally, we could run this scene
dpctl playbook -a run -s scene1