Browse Source

Add NS1 DNS Scripts

pull/817/head
Ayesh Karunaratne 2 years ago
parent
commit
fead9b7ab9
Failed to extract signature
2 changed files with 56 additions and 0 deletions
  1. +30
    -0
      dns_scripts/dns_add_ns1
  2. +26
    -0
      dns_scripts/dns_del_ns1

+ 30
- 0
dns_scripts/dns_add_ns1 View File

@ -0,0 +1,30 @@
#! /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%}"
function create {
curl "${api_url}/zones/${root}/${subdomain}/TXT" -X DELETE \
--header "X-NSONE-Key: $api_key"
curl "${api_url}/zones/${root}/${subdomain}/TXT" -X PUT \
--header "X-NSONE-Key: $api_key" \
--header "Content-Type: application/json" \
--data "{ \"zone\": \"${root}\", \"domain\": \"${subdomain}\", \"type\": \"TXT\", \"answers\": [ { \"answer\": [ \"${challenge}\" ] } ] }"
}
create $root $subdomain

+ 26
- 0
dns_scripts/dns_del_ns1 View File

@ -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%}"
function delete {
curl "${api_url}/zones/${root}/${subdomain}/TXT" -X DELETE \
--header "X-NSONE-Key: $api_key"
}
delete $root $subdomain

Loading…
Cancel
Save