From 454d46a2288eba7b786008847ebc464e2768167f Mon Sep 17 00:00:00 2001 From: Ola Thoresen Date: Mon, 5 Jun 2023 09:22:52 +0200 Subject: [PATCH] Adding support for deploying certs to Nutanix Prism --- deploy/nutanix.sh | 55 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 deploy/nutanix.sh diff --git a/deploy/nutanix.sh b/deploy/nutanix.sh new file mode 100644 index 00000000..59cc278c --- /dev/null +++ b/deploy/nutanix.sh @@ -0,0 +1,55 @@ +#Here is a script to deploy cert to nutanix prism server. + +#returns 0 means success, otherwise error. + +# export NUTANIX_USER="" # required +# export NUTANIX_PASS="" # required +# export NUTANIX_HOST="" # required + + +#domain keyfile certfile cafile fullchain +nutanix_deploy() { + _cdomain="$1" + _ckey="$2" + _ccert="$3" + _cca="$4" + _cfullchain="$5" + + _debug _cdomain "$_cdomain" + _debug _ckey "$_ckey" + _debug _ccert "$_ccert" + _debug _cca "$_cca" + _debug _cfullchain "$_cfullchain" + + _info "Deploying to $NUTANIX_HOST" + + # NUTANIX ENV VAR check + if [ -z "$NUTANIX_USER" ] || [ -z "$NUTANIX_PASS" ] || [ -z "$NUTANIX_HOST" ]; then + _debug "No ENV variables found lets check for saved variables" + _getdeployconf NUTANIX_USER + _getdeployconf NUTANIX_PASS + _getdeployconf NUTANIX_HOST + _nutanix_user=$NUTANIX_USER + _nutanix_pass=$NUTANIX_PASS + _nutanix_host=$NUTANIX_HOST + if [ -z "$_nutanix_user" ] && [ -z "$_nutanix_pass" ] && [ -z "$_nutanix_host" ]; then + _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." + return 1 + else + _debug "Using saved env variables." + fi + else + _debug "Detected ENV variables to be saved to the deploy conf." + # Encrypt and save user + _savedeployconf NUTANIX_USER "$NUTANIX_USER" 1 + _savedeployconf NUTANIX_PASS "$NUTANIX_PASS" 1 + _savedeployconf NUTANIX_HOST "$NUTANIX_HOST" 1 + _nutanix_user="$NUTANIX_USER" + _nutanix_pass="$NUTANIX_PASS" + _nutanix_host="$NUTANIX_HOST" + fi + 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 + return $? +} + +