Skip to content

Instantly share code, notes, and snippets.

@Linda-chan
Last active December 23, 2018 11:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Linda-chan/a160ba323ebc403396b19f9b458b1758 to your computer and use it in GitHub Desktop.
Save Linda-chan/a160ba323ebc403396b19f9b458b1758 to your computer and use it in GitHub Desktop.
Clean up domain records from verification records
#!/usr/local/bin/run_ruby_script_in_rvm
require "json"
require "os"
DOCTL_FILE_NAME = "doctl"
#====================================================================
def main
if OS.windows? then
DOCTL_FILE_NAME.replace "doctl.exe"
end
get_domains
end
#====================================================================
def get_domains
txt = `"#{ DOCTL_FILE_NAME }" compute domain list --output json`
domains = JSON.parse(txt)
domains.each do |domain|
domain_name = domain["name"]
if not domain_name.empty? then
get_records domain_name
end
end
end
#====================================================================
def get_records(domain_name)
txt = `"#{ DOCTL_FILE_NAME }" compute domain records list #{ domain_name } --output json`
records = JSON.parse(txt)
records.each do |record|
record_name = record["name"]
if record_name[0, 15] == "_acme-challenge" then
record_id = record["id"]
cmd = "\"#{ DOCTL_FILE_NAME }\" compute domain records delete #{ domain_name } #{ record_id }" # --force"
puts "#{ record_id } :: #{ domain_name } :: #{ record_name }"
puts "==> #{ cmd }"
`#{ cmd }`
puts ""
end
end
end
#====================================================================
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment