Skip to content

Commit

Permalink
Add NS1 DNS Scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayesh committed Nov 2, 2023
1 parent a3a26cb commit 256ea61
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
27 changes: 27 additions & 0 deletions dns_scripts/dns_add_ns1
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions dns_scripts/dns_del_ns1
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 256ea61

Please sign in to comment.