provisioning tool for building opinionated architecture
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
1.9 KiB

5 months ago
  1. #!/bin/bash
  2. # GET DOMAIN : https://eu.api.ovh.com/createToken/?GET=/domain*&POST=/domain*&PUT=/domain*&DELETE=/domain*
  3. function set_base {
  4. BASE_URL="https://eu.api.ovh.com/1.0"
  5. source ./.ovh-credential
  6. }
  7. function build_url_list_records {
  8. zone="$1"
  9. result="${BASE_URL}/domain/zone/$zone/record"
  10. fieldType="${2:-}"
  11. subDomain="${3:-}"
  12. any="$fieldType$subDomain"
  13. [[ -n $any ]] && result+="?"
  14. [[ -n $fieldType ]] && result+="fieldType=$fieldType&"
  15. [[ -n $subDomain ]] && result+="subDomain=$subDomain&"
  16. result=${result::-1}
  17. echo "$result"
  18. }
  19. function list_records {
  20. zone="$1"
  21. fieldType="${2:-}"
  22. subDomain="${3:-}"
  23. query=$(build_url_list_records "$zone" "$fieldType" "$subDomain")
  24. method="GET"
  25. body=""
  26. tstamp=$(date +%s)
  27. sha=$(echo -n "$AS+$CK+$method+$query+$body+$tstamp" | shasum | cut -d ' ' -f 1)
  28. signature="\$1\$$sha"
  29. curl -s \
  30. -X $method \
  31. -H "Content-type: application/json" \
  32. -H "X-Ovh-Application: $AK" \
  33. -H "X-Ovh-Consumer: $CK" \
  34. -H "X-Ovh-Signature: $signature" \
  35. -H "X-Ovh-Timestamp: $tstamp" \
  36. "$query" | yq .[] # values of array
  37. }
  38. function get_record {
  39. zone="$1"
  40. record="$2"
  41. method="GET"
  42. query="${BASE_URL}/domain/zone/$zone/record/$record"
  43. body=""
  44. tstamp=$(date +%s)
  45. sha=$(echo -n "$AS+$CK+$method+$query+$body+$tstamp" | shasum | cut -d ' ' -f 1)
  46. signature="\$1\$$sha"
  47. curl -s \
  48. -X $method \
  49. -H "Content-type: application/json" \
  50. -H "X-Ovh-Application: $AK" \
  51. -H "X-Ovh-Consumer: $CK" \
  52. -H "X-Ovh-Signature: $signature" \
  53. -H "X-Ovh-Timestamp: $tstamp" \
  54. "$query" | yq -o=props
  55. }
  56. ##-----------
  57. ## -- MAIN --
  58. ##-----------
  59. . "$MIAOU_BASEDIR/lib/init.sh"
  60. set_base
  61. for i in $(list_records "$1" CNAME "$2"); do
  62. get_record "$1" "$i"
  63. done