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.

56 lines
1.6 KiB

7 months ago
  1. #!/usr/bin/env sh
  2. # Script to deploy certificate to CacheFly
  3. # https://api.cachefly.com/api/2.5/docs#tag/Certificates/paths/~1certificates/post
  4. # This deployment required following variables
  5. # export CACHEFLY_TOKEN="Your CacheFly API Token"
  6. # returns 0 means success, otherwise error.
  7. ######## Public functions #####################
  8. #domain keyfile certfile cafile fullchain
  9. CACHEFLY_API_BASE="https://api.cachefly.com/api/2.5"
  10. cachefly_deploy() {
  11. _cdomain="$1"
  12. _ckey="$2"
  13. _ccert="$3"
  14. _cca="$4"
  15. _cfullchain="$5"
  16. _debug _cdomain "$_cdomain"
  17. _debug _ckey "$_ckey"
  18. _debug _ccert "$_ccert"
  19. _debug _cca "$_cca"
  20. _debug _cfullchain "$_cfullchain"
  21. if [ -z "$CACHEFLY_TOKEN" ]; then
  22. _err "CACHEFLY_TOKEN is not defined."
  23. return 1
  24. else
  25. _savedomainconf CACHEFLY_TOKEN "$CACHEFLY_TOKEN"
  26. fi
  27. _info "Deploying certificate to CacheFly..."
  28. ## upload certificate
  29. string_fullchain=$(sed 's/$/\\n/' "$_cfullchain" | tr -d '\n')
  30. string_key=$(sed 's/$/\\n/' "$_ckey" | tr -d '\n')
  31. _request_body="{\"certificate\":\"$string_fullchain\",\"certificateKey\":\"$string_key\"}"
  32. _debug _request_body "$_request_body"
  33. _debug CACHEFLY_TOKEN "$CACHEFLY_TOKEN"
  34. export _H1="Authorization: Bearer $CACHEFLY_TOKEN"
  35. _response=$(_post "$_request_body" "$CACHEFLY_API_BASE/certificates" "" "POST" "application/json")
  36. if _contains "$_response" "message"; then
  37. _err "Error in deploying $_cdomain certificate to CacheFly."
  38. _err "$_response"
  39. return 1
  40. fi
  41. _debug response "$_response"
  42. _info "Domain $_cdomain certificate successfully deployed to CacheFly."
  43. return 0
  44. }