项目作者: wangzn

项目描述 :
Go client wrapper and CTL tool for DNSPod API
高级语言: Go
项目地址: git://github.com/wangzn/dnspodapi.git
创建时间: 2018-08-31T06:46:23Z
项目社区:https://github.com/wangzn/dnspodapi

开源协议:Apache License 2.0

下载


dnspodapi

Go client wrapper and CTL tool for DNSPOD API

INSTALL

Make sure you have go installed in your env.

  1. go get -u github.com/wangzn/dnspodapi/dpctl

Usage

  1. dpctl help

Config

Default config file is at $HOME/.dnspod.yaml

Demo config file could be found at demo config

Test API token and print API version

  1. # test connection and print info
  2. dpctl info

Domain utils

  1. # list all domains
  2. dpctl domain -a list
  3. # get domain info
  4. dpctl domain -d ashtray.wang,ashtray.name -a info
  5. # create domain and add default record
  6. dpctl domain -d abc.xyz,abcde.xyz -a create
  7. # remove domain
  8. dpctl domain -d abc.xyz,abcde.xyz -a remove
  9. # enable domain
  10. dpctl domain -d abc.xyz,abcde.xyz -a enable
  11. # disable domain
  12. dpctl domain -d abc.xyz,abcde.xyz -a diable

Record utils

  1. # list record of domain ashtray.wang and ashtray.name
  2. dpctl record -a list -d ashtray.wang,ashtray.name
  3. # get record info of domain ashtray.wang, with record proxy,proxy11,proxy12
  4. dpctl record -a info -d ashtray.wang -r proxy,proxy11,proxy12
  5. # disalbe these records and enable them again
  6. dpctl record -a disable -d ashtray.wang -r proxy,proxy11,proxy12
  7. dpctl record -a enable -d ashtray.wang -r proxy,proxy11,proxy12
  8. # create a record
  9. dpctl record -a create -d ashtray.wang -r testcreate -t A -v 1.1.1.1
  10. # createa record with TTL 6000
  11. dpctl record -a create -d ashtray.wang -r testcreate -t A -v 1.1.1.1 -T 6000
  12. ## import records from local file but DO NOT CLEAR conflict records
  13. dpctl record -a import -d ashtray.wang -f testdata/records.lst
  14. # import records from local file and CLEAR conflict ones
  15. dpctl record -a import -d ashtray.wang -f testdata/records.lst --clear
  16. # import record and force create domain if not exist
  17. dpctl record -a import -d ashtray.wang,abcde.xyz -f testdata/records.lst --force-domain
  18. # export records to file, append if file exist
  19. dpctl record -d ashtray.wang -a export -f /dev/stdout --export-file-mode append
  20. # export records to file, with records filter www21,www22, and overwrite local file if exist
  21. dpctl record -d ashtray.wang -a export -f testdata/export.lst --export-file-mode overwrite -r www11,www12
  22. # ensure records defined in a file, and import into a domain
  23. dpctl record -a ensure -d abc.xyz -f testdata/records.lst
  24. # 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 @
  25. dpctl record -a ensure -d abc.xyz -f testdata/records.lst --clear --exclude --force-domain

Variable support in record file

  1. > tail -n 2 testdata/records.lst
  2. cdn1 CNAME proxy1.
  3. 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

Playbook utils

We can predefined some common used cmds into playbook (named as scene ), and reuse them in short command.

  1. dpctl help playbook

Scene definition

scene is a list of actions , e.g.:

  1. scene1:
  2. - auth: "default" # could omit to use default
  3. category: "domain"
  4. action: "create"
  5. subject: "abc.xyz,abcde.xyz"
  6. params:
  7. - auth: "default" # could omit to use default
  8. category: "record"
  9. action: "import"
  10. subject: ""
  11. params:
  12. domain: "abc.xyz,abcde.xyz"
  13. clear: "on"
  14. force_domain: "off"
  15. record_file: "testdata/record.lst"
  16. - auth: "default" # could omit to use default
  17. category: "record"
  18. action: "export"
  19. subject: "www,proxy"
  20. params:
  21. domain: "abc.xyz,abcde.xyz"
  22. file_mode: "append" # overwrite, default is exit for no damage
  23. record_file: "testdata/record.lst"

In this scene above, we define three actions:

  • create domain abc.xyz,abcde.xyz
  • import record from local file testdata/record.lst into domain abc.xyz,abcde.xyz
  • export record into local file testdata/record.lst with record www and proxy in domain abc.xyz,abcde.xyz

Preview scene

then we could preview this scene in case of any unexpected cmds

  1. dpctl playbook -a preview -s scene1

Run scene

finally, we could run this scene

  1. dpctl playbook -a run -s scene1

TODO

  • operate domains
  • add more info commands
  • more config entry for config file
  • add playbook cmd and modify config file structure