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.

57 lines
1.9 KiB

1 year ago
  1. #!/usr/bin/env sh
  2. #Here is a script to deploy cert to nutanix prism server.
  3. #returns 0 means success, otherwise error.
  4. # export NUTANIX_USER="" # required
  5. # export NUTANIX_PASS="" # required
  6. # export NUTANIX_HOST="" # required
  7. #domain keyfile certfile cafile fullchain
  8. nutanix_deploy() {
  9. _cdomain="$1"
  10. _ckey="$2"
  11. _ccert="$3"
  12. _cca="$4"
  13. _cfullchain="$5"
  14. _debug _cdomain "$_cdomain"
  15. _debug _ckey "$_ckey"
  16. _debug _ccert "$_ccert"
  17. _debug _cca "$_cca"
  18. _debug _cfullchain "$_cfullchain"
  19. _info "Deploying to $NUTANIX_HOST"
  20. # NUTANIX ENV VAR check
  21. if [ -z "$NUTANIX_USER" ] || [ -z "$NUTANIX_PASS" ] || [ -z "$NUTANIX_HOST" ]; then
  22. _debug "No ENV variables found lets check for saved variables"
  23. _getdeployconf NUTANIX_USER
  24. _getdeployconf NUTANIX_PASS
  25. _getdeployconf NUTANIX_HOST
  26. _nutanix_user=$NUTANIX_USER
  27. _nutanix_pass=$NUTANIX_PASS
  28. _nutanix_host=$NUTANIX_HOST
  29. if [ -z "$_nutanix_user" ] && [ -z "$_nutanix_pass" ] && [ -z "$_nutanix_host" ]; then
  30. _err "No host, user and pass found.. If this is the first time deploying please set NUTANIX_HOST, NUTANIX_USER and NUTANIX_PASS in environment variables. Delete them after you have succesfully deployed certs."
  31. return 1
  32. else
  33. _debug "Using saved env variables."
  34. fi
  35. else
  36. _debug "Detected ENV variables to be saved to the deploy conf."
  37. # Encrypt and save user
  38. _savedeployconf NUTANIX_USER "$NUTANIX_USER" 1
  39. _savedeployconf NUTANIX_PASS "$NUTANIX_PASS" 1
  40. _savedeployconf NUTANIX_HOST "$NUTANIX_HOST" 1
  41. _nutanix_user="$NUTANIX_USER"
  42. _nutanix_pass="$NUTANIX_PASS"
  43. _nutanix_host="$NUTANIX_HOST"
  44. fi
  45. curl --silent --fail --user "$_nutanix_user:$_nutanix_pass" -F caChain=@"$_cca" -F cert=@"$_ccert" -F key=@"$_ckey" -F keyType=RSA_2048 -k https://"$_nutanix_host":9440/PrismGateway/services/rest/v1/keys/pem/import >/dev/null
  46. return $?
  47. }