From 46fec2db7634c04d1c86b78a6bb5ef62c14470ff Mon Sep 17 00:00:00 2001 From: Jonathan Cobb Date: Thu, 25 Jun 2020 18:57:02 -0400 Subject: [PATCH] add godaddy scripts to make cleaning up stale dns records easier --- bin/godaddy/gd_list_records.sh | 8 ++++++++ bin/godaddy/gd_update_records.sh | 8 ++++++++ bin/godaddy/gdcurl | 26 ++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100755 bin/godaddy/gd_list_records.sh create mode 100755 bin/godaddy/gd_update_records.sh create mode 100755 bin/godaddy/gdcurl diff --git a/bin/godaddy/gd_list_records.sh b/bin/godaddy/gd_list_records.sh new file mode 100755 index 00000000..f491c8ae --- /dev/null +++ b/bin/godaddy/gd_list_records.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +DOMAIN=${1:?no domain provided} + +THISDIR=$(cd $(dirname ${0}) && pwd) +GDCURL=${THISDIR}/gdcurl + +${GDCURL} ${DOMAIN}/records diff --git a/bin/godaddy/gd_update_records.sh b/bin/godaddy/gd_update_records.sh new file mode 100755 index 00000000..cf168a56 --- /dev/null +++ b/bin/godaddy/gd_update_records.sh @@ -0,0 +1,8 @@ +#!/bin/bash +DOMAIN=${1:?no domain provided} +RECORDS_JSON="${2:?no JSON DNS records file provided}" + +THISDIR=$(cd $(dirname ${0}) && pwd) +GDCURL=${THISDIR}/gdcurl + +${GDCURL} ${DOMAIN}/records "${RECORDS_JSON}" PUT diff --git a/bin/godaddy/gdcurl b/bin/godaddy/gdcurl new file mode 100755 index 00000000..da6e6d49 --- /dev/null +++ b/bin/godaddy/gdcurl @@ -0,0 +1,26 @@ +#!/bin/bash + +if [[ -z "${GODADDY_API_KEY}" ]] ; then + echo "GODADDY_API_KEY not defined in environment" + exit 1 +fi +if [[ -z "${GODADDY_API_SECRET}" ]] ; then + echo "GODADDY_API_SECRET not defined in environment" + exit 1 +fi + +URI="${1:?no uri}" +POST_FILE="${2}" +HTTP_METHOD=${3} + +API_BASE=https://api.godaddy.com/v1/domains/ + +if [[ ! -z "${POST_FILE}" ]] ; then + if [[ -z "${HTTP_METHOD}" ]] ; then + curl -d @${POST_FILE} -s -H 'Content-Type: application/json' -H "Authorization: sso-key ${GODADDY_API_KEY}:${GODADDY_API_SECRET}" ${API_BASE}${URI} + else + curl -d @${POST_FILE} -X ${HTTP_METHOD} -s -H 'Content-Type: application/json' -H "Authorization: sso-key ${GODADDY_API_KEY}:${GODADDY_API_SECRET}" ${API_BASE}${URI} + fi +else + curl -s -H "Authorization: sso-key ${GODADDY_API_KEY}:${GODADDY_API_SECRET}" ${API_BASE}${URI} +fi