ovh-domain
This commit is contained in:
@@ -1,9 +1,16 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# GET DOMAIN
|
||||
# https://eu.api.ovh.com/createToken/?GET=/domain*&POST=/domain*&PUT=/domain*&DELETE=/domain*
|
||||
|
||||
# GET DOMAIN : https://eu.api.ovh.com/createToken/?GET=/domain*&POST=/domain*&PUT=/domain*&DELETE=/domain*
|
||||
|
||||
function usage {
|
||||
echo 'usage: <ACTION: list|get|set> <DOMAIN> [CNAME] [destination]'
|
||||
echo ' - list <DOMAIN>'
|
||||
echo ' - get <DOMAIN> <CNAME>'
|
||||
echo ' - set <DOMAIN> <CNAME> <DESTINATION>'
|
||||
exit 1
|
||||
}
|
||||
function set_base {
|
||||
|
||||
BASE_URL="https://eu.api.ovh.com/1.0"
|
||||
BASEDIR=$(dirname "$0")
|
||||
source "$BASEDIR"/.ovh-credential
|
||||
@@ -37,14 +44,22 @@ function list_records {
|
||||
sha=$(echo -n "$AS+$CK+$method+$query+$body+$tstamp" | shasum | cut -d ' ' -f 1)
|
||||
signature="\$1\$$sha"
|
||||
|
||||
curl -s \
|
||||
echo BEFORE CURL
|
||||
output=$(curl -s \
|
||||
-X $method \
|
||||
-H "Content-type: application/json" \
|
||||
-H "X-Ovh-Application: $AK" \
|
||||
-H "X-Ovh-Consumer: $CK" \
|
||||
-H "X-Ovh-Signature: $signature" \
|
||||
-H "X-Ovh-Timestamp: $tstamp" \
|
||||
"$query" | yq .[] # values of array
|
||||
"$query")
|
||||
|
||||
echo ""
|
||||
echo "output=$output"
|
||||
echo ""
|
||||
exit 1
|
||||
|
||||
# echo "$output" | yq .[] # values of array
|
||||
}
|
||||
|
||||
function get_record {
|
||||
@@ -67,13 +82,50 @@ function get_record {
|
||||
"$query" | yq -o=props
|
||||
}
|
||||
|
||||
function action_list {
|
||||
for record_id in $(list_records "$DOMAIN" CNAME "$CNAME"); do
|
||||
get_record "$DOMAIN" "$record_id"
|
||||
done
|
||||
}
|
||||
|
||||
function action_get {
|
||||
local record_id
|
||||
record_id=$(list_records "$DOMAIN" CNAME "$CNAME")
|
||||
get_record "$DOMAIN" "$record_id"
|
||||
}
|
||||
|
||||
function action_set {
|
||||
echo set_record "$DOMAIN" "$CNAME" "$DESTINATION"
|
||||
}
|
||||
|
||||
##-----------
|
||||
## -- MAIN --
|
||||
##-----------
|
||||
|
||||
. "$MIAOU_BASEDIR/lib/init.sh"
|
||||
|
||||
[[ $# -lt 2 ]] && usage && exit 1
|
||||
|
||||
ACTION="$1"
|
||||
DOMAIN="$2"
|
||||
CNAME="${3:-}"
|
||||
DESTINATION="${4:-}"
|
||||
|
||||
set_base
|
||||
for i in $(list_records "$1" CNAME "$2"); do
|
||||
get_record "$1" "$i"
|
||||
done
|
||||
|
||||
case $ACTION in
|
||||
list)
|
||||
action_list
|
||||
;;
|
||||
get)
|
||||
arg3_required "$@" || usage
|
||||
action_get
|
||||
;;
|
||||
set)
|
||||
arg4_required "$@" || usage
|
||||
action_set
|
||||
;;
|
||||
*)
|
||||
echoerr "unknown action <$ACTION> !" && usage && exit 2
|
||||
;;
|
||||
esac
|
||||
|
||||
Reference in New Issue
Block a user