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.

55 lines
1.8 KiB

  1. #Here is a script to deploy cert to nutanix prism server.
  2. #returns 0 means success, otherwise error.
  3. # export NUTANIX_USER="" # required
  4. # export NUTANIX_PASS="" # required
  5. # export NUTANIX_HOST="" # required
  6. #domain keyfile certfile cafile fullchain
  7. nutanix_deploy() {
  8. _cdomain="$1"
  9. _ckey="$2"
  10. _ccert="$3"
  11. _cca="$4"
  12. _cfullchain="$5"
  13. _debug _cdomain "$_cdomain"
  14. _debug _ckey "$_ckey"
  15. _debug _ccert "$_ccert"
  16. _debug _cca "$_cca"
  17. _debug _cfullchain "$_cfullchain"
  18. _info "Deploying to $NUTANIX_HOST"
  19. # NUTANIX ENV VAR check
  20. if [ -z "$NUTANIX_USER" ] || [ -z "$NUTANIX_PASS" ] || [ -z "$NUTANIX_HOST" ]; then
  21. _debug "No ENV variables found lets check for saved variables"
  22. _getdeployconf NUTANIX_USER
  23. _getdeployconf NUTANIX_PASS
  24. _getdeployconf NUTANIX_HOST
  25. _nutanix_user=$NUTANIX_USER
  26. _nutanix_pass=$NUTANIX_PASS
  27. _nutanix_host=$NUTANIX_HOST
  28. if [ -z "$_nutanix_user" ] && [ -z "$_nutanix_pass" ] && [ -z "$_nutanix_host" ]; then
  29. _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."
  30. return 1
  31. else
  32. _debug "Using saved env variables."
  33. fi
  34. else
  35. _debug "Detected ENV variables to be saved to the deploy conf."
  36. # Encrypt and save user
  37. _savedeployconf NUTANIX_USER "$NUTANIX_USER" 1
  38. _savedeployconf NUTANIX_PASS "$NUTANIX_PASS" 1
  39. _savedeployconf NUTANIX_HOST "$NUTANIX_HOST" 1
  40. _nutanix_user="$NUTANIX_USER"
  41. _nutanix_pass="$NUTANIX_PASS"
  42. _nutanix_host="$NUTANIX_HOST"
  43. fi
  44. 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
  45. return $?
  46. }