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.

79 lines
1.9 KiB

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