Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,24 @@ Usage
test - perform an authentication test

Environment:
Ensure that the following two environment variables are exported:
CLOUDNS_API_ID - your ClouDNS API ID (auth-id)
CLOUDNS_PASSWORD - your ClouDNS API password (auth-password)
Ensure that the following environment variable
CLOUDNS_PASSWORD - your ClouDNS API password (auth-password)
And that one of the following are exported:
CLOUDNS_API_ID - your ClouDNS API ID (auth-id)
CLOUDNS_API_SUB_ID - your ClouDNS API sub-ID (sub-auth-id)
CLOUDNS_API_SUB_USER - your ClouDNS API sub-user name (sub-auth-user)

Environment
-----------

You should ensure that you export the following environment variables correctly. Their
existence is tested by the script.

$ export CLOUDNS_API_ID=<your_auth-id>
$ export CLOUDNS_PASSWORD=<your_auth-password>
# and one of
$ export CLOUDNS_API_ID=<your_auth-id>
$ export CLOUDNS_API_SUB_ID=<your_sub-auth-id>
$ export CLOUDNS_API_SUB_USER=<your_sub-auth-user>

The script does not currently support sub-auth-id, etc. See Limitations at the end of
this document. This does allow us to operate globally on your account. Ensure you
Expand Down
59 changes: 51 additions & 8 deletions bin/cloudns_api.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,12 @@ function print_usage() {
builtin echo " test - perform an authentication test"
builtin echo ""
builtin echo " Environment:"
builtin echo " Ensure that the following two environment variables are exported:"
builtin echo " CLOUDNS_API_ID - your ClouDNS API ID (auth-id)"
builtin echo " Ensure that the following environment variable"
builtin echo " CLOUDNS_PASSWORD - your ClouDNS API password (auth-password)"
builtin echo " And that one of the following are exported:"
builtin echo " CLOUDNS_API_ID - your ClouDNS API ID (auth-id)"
builtin echo " CLOUDNS_API_SUB_ID - your ClouDNS API sub-ID (sub-auth-id)"
builtin echo " CLOUDNS_API_SUB_USER - your ClouDNS API sub-user name (sub-auth-user)"
} >&2
}

Expand Down Expand Up @@ -130,22 +133,62 @@ function process_arguments() {

function check_environment_variables() {
local ERROR_COUNT=0
local REQUIRED_VARIABLES=( CLOUDNS_API_ID CLOUDNS_PASSWORD )
for REQUIRED_VARIABLE in ${REQUIRED_VARIABLES[@]}; do
if $( builtin eval test -z \${${REQUIRED_VARIABLE}} ); then
print_error "Environment variable \${${REQUIRED_VARIABLE}} unset"
(( ERROR_COUNT = ERROR_COUNT + 1 ))

# Check if CLOUDNS_PASSWORD is set
if $(builtin eval test -z \${CLOUDNS_PASSWORD}); then
print_error "Environment variable CLOUDNS_PASSWORD unset"
(( ERROR_COUNT = ERROR_COUNT + 1 ))
fi

# Check if only one of the required CloudNS identifier is set
local CLOUDNS_API_IDENTIFIERS=( CLOUDNS_API_ID CLOUDNS_API_SUB_ID CLOUDNS_API_SUB_USER )
local CLOUDNS_API_IDENTIFIERS_COUNT=0

for CLOUDNS_API_IDENTIFIER in ${CLOUDNS_API_IDENTIFIERS[@]}; do
if ! $(builtin eval test -z \${${CLOUDNS_API_IDENTIFIER}}); then
(( CLOUDNS_API_IDENTIFIERS_COUNT = CLOUDNS_API_IDENTIFIERS_COUNT + 1 ))
fi
done

if [ "${CLOUDNS_API_IDENTIFIERS_COUNT}" -eq "0" ]; then
print_error "None of the environment variables CLOUDNS_API_ID, CLOUDNS_API_SUB_ID, CLOUDNS_API_SUB_USER are set."
(( ERROR_COUNT = ERROR_COUNT + 1 ))
fi

if [ "${CLOUDNS_API_IDENTIFIERS_COUNT}" -gt "1" ]; then
print_error "Exactly one of the environment variables CLOUDNS_API_ID, CLOUDNS_API_SUB_ID, CLOUDNS_API_SUB_USER must be set, not more."
(( ERROR_COUNT = ERROR_COUNT + 1 ))
fi

if [ "${ERROR_COUNT}" -gt "0" ]; then
exit 1
fi
}


function set_auth_post_data() {
AUTH_POST_DATA="-d auth-id=${CLOUDNS_API_ID} -d auth-password=${CLOUDNS_PASSWORD}"
local AUTH_TYPE=""
local AUTH_ID=""

if [ ! -z "${CLOUDNS_API_ID}" ]; then
AUTH_TYPE="auth-id"
AUTH_ID="${CLOUDNS_API_ID}"
elif [ ! -z "${CLOUDNS_API_SUB_ID}" ]; then
AUTH_TYPE="sub-auth-id"
AUTH_ID="${CLOUDNS_API_SUB_ID}"
elif [ ! -z "${CLOUDNS_API_SUB_USER}" ]; then
AUTH_TYPE="sub-auth-user"
AUTH_ID="${CLOUDNS_API_SUB_USER}"
else
print_error "No valid authentication environment variable set"
exit 1
fi

AUTH_POST_DATA="-d ${AUTH_TYPE}=${AUTH_ID} -d auth-password=${CLOUDNS_PASSWORD}"
}



function test_api_url() {
local HTTP_CODE=$( curl -4qs -o /dev/null -w '%{http_code}' ${API_URL}/login.json )
if [ "${HTTP_CODE}" != "200" ]; then
Expand Down