diff --git a/dns_scripts/dns_add_ns1 b/dns_scripts/dns_add_ns1 new file mode 100644 index 00000000..439be686 --- /dev/null +++ b/dns_scripts/dns_add_ns1 @@ -0,0 +1,27 @@ +#! /usr/bin/env bash +# NS1 Add DNS Record + +if [[ -z "$NS1_API_KEY" ]]; then + echo "NS1_API_KEY variable not set" + exit 1 +fi + +api_url="https://api.nsone.net/v1/" +api_key=${NS1_API_KEY:-''} + +domain="$1" +challenge="$2" + +root=$(echo "$domain" | awk -F\. '{print $(NF-1) FS $NF}') +subdomain="_acme-challenge.${domain%.$root}" + +function create { + +curl "${api_url}/zones/${domain}/${subdomain}/TXT" -X PUT \ + --header "X-NSONE-Key: $api_key" \ + --header "Content-Type: application/json" \ + --data "{ \"zone\": \"${domain}\", \"domain\": \"${subdomain}\", \"type\": \"TXT\", \"answers\": [ { \"answer\": [ \"${challenge}\" ] } ] }" + +} + +create $root $subdomain diff --git a/dns_scripts/dns_del_ns1 b/dns_scripts/dns_del_ns1 new file mode 100644 index 00000000..12c020e7 --- /dev/null +++ b/dns_scripts/dns_del_ns1 @@ -0,0 +1,26 @@ +#! /usr/bin/env bash +# NS1 Add DNS Record + +if [[ -z "$NS1_API_KEY" ]]; then + echo "NS1_API_KEY variable not set" + exit 1 +fi + +api_url="https://api.nsone.net/v1/" +api_key=${NS1_API_KEY:-''} + +domain="$1" +challenge="$2" + +root=$(echo "$domain" | awk -F\. '{print $(NF-1) FS $NF}') +subdomain="_acme-challenge.${domain%.$root}" + +function delete { + +curl "${api_url}/zones/${domain}/${subdomain}/TXT" -X DELETE \ + --header "X-NSONE-Key: $api_key" + +} + +delete $root $subdomain +