Last active
December 23, 2018 11:06
Clean up domain records from verification records
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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