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.

68 lines
2.1 KiB

  1. #!/bin/bash
  2. #Here is a sample custom api script.
  3. #This file name is "myapi.sh"
  4. #So, here must be a method myapi_deploy()
  5. #Which will be called by acme.sh to deploy the cert
  6. #returns 0 means success, otherwise error.
  7. ######## Public functions #####################
  8. #domain keyfile certfile cafile fullchain
  9. consul_deploy() {
  10. _cdomain="$1"
  11. _ckey="$2"
  12. _ccert="$3"
  13. _cca="$4"
  14. _cfullchain="$5"
  15. if [ -z "$DEPLOY_CONSUL_URL" ] || [ -z "$DEPLOY_CONSUL_ROOT_KEY" ]; then
  16. _err "You haven't specified the url or consul root key yet (DEPLOY_CONSUL_URL and DEPLOY_CONSUL_ROOT_KEY)."
  17. _err "Please set them via export and try again."
  18. _err "e.g. export DEPLOY_CONSUL_URL=http://localhost:8500/v1/kv"
  19. _err "e.g. export DEPLOY_CONSUL_ROOT_KEY=acme"
  20. return 1
  21. fi
  22. #Save consul url if it's succesful (First run case)
  23. _saveaccountconf DEPLOY_CONSUL_URL "$DEPLOY_CONSUL_URL"
  24. _saveaccountconf DEPLOY_CONSUL_ROOT_KEY "$DEPLOY_CONSUL_ROOT_KEY"
  25. _info "Deploying certificate to consul Key/Value store"
  26. _debug _cdomain "$_cdomain"
  27. _debug _ckey "$_ckey"
  28. _debug _ccert "$_ccert"
  29. _debug _cca "$_cca"
  30. _debug _cfullchain "$_cfullchain"
  31. _debug DEPLOY_CONSUL_URL "$DEPLOY_CONSUL_URL"
  32. _debug DEPLOY_CONSUL_ROOT_KEY "$DEPLOY_CONSUL_ROOT_KEY"
  33. # set base url for all uploads
  34. upload_base_url="${DEPLOY_CONSUL_URL}/${DEPLOY_CONSUL_ROOT_KEY}/${_cdomain}"
  35. _debug upload_base_url "$upload_base_url"
  36. # private
  37. _info uploading "$_ckey"
  38. response=$(_post "@${_ckey}" "${upload_base_url}/${_cdomain}.key" "" "PUT")
  39. _debug response "$response"
  40. # public
  41. _info uploading "$_ccert"
  42. response=$(_post "@${_ccert}" "${upload_base_url}/${_cdomain}.cer" "" "PUT")
  43. _debug response "$response"
  44. # ca
  45. _info uploading "$_cca"
  46. response=$(_post "@${_cca}" "${upload_base_url}/ca.cer" "" "PUT")
  47. _debug response "$response"
  48. # fullchain
  49. _info uploading "$_cfullchain"
  50. response=$(_post "@${_cfullchain}" "${upload_base_url}/fullchain.cer" "" "PUT")
  51. _debug response "$response"
  52. return 0
  53. }
  54. #################### Private functions below ##################################