From 454d46a2288eba7b786008847ebc464e2768167f Mon Sep 17 00:00:00 2001 From: Ola Thoresen Date: Mon, 5 Jun 2023 09:22:52 +0200 Subject: [PATCH 1/4] 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 $? +} + + From 7e1999e3c1d5f133e2f885980b2c5e9e9b5fa710 Mon Sep 17 00:00:00 2001 From: Ola Thoresen Date: Mon, 5 Jun 2023 12:13:51 +0200 Subject: [PATCH 2/4] Adding lost shebang --- deploy/nutanix.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/deploy/nutanix.sh b/deploy/nutanix.sh index 59cc278c..ee1f50b5 100644 --- a/deploy/nutanix.sh +++ b/deploy/nutanix.sh @@ -1,3 +1,5 @@ +#!/usr/bin/env sh + #Here is a script to deploy cert to nutanix prism server. #returns 0 means success, otherwise error. From 225e6eadb7f1498f72d9aeda7c75fc8d5a58ddb6 Mon Sep 17 00:00:00 2001 From: Ola Thoresen Date: Wed, 7 Jun 2023 09:36:49 +0200 Subject: [PATCH 3/4] Fix shellcheck --- deploy/nutanix.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy/nutanix.sh b/deploy/nutanix.sh index ee1f50b5..463a8aee 100644 --- a/deploy/nutanix.sh +++ b/deploy/nutanix.sh @@ -50,7 +50,7 @@ nutanix_deploy() { _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 + 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 $? } From 62eae98571245fa5ef9d6b360f6b0b3300e8e10d Mon Sep 17 00:00:00 2001 From: Ola Thoresen Date: Wed, 7 Jun 2023 09:37:35 +0200 Subject: [PATCH 4/4] Fix shellfmt --- deploy/nutanix.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/deploy/nutanix.sh b/deploy/nutanix.sh index 463a8aee..39f74c9a 100644 --- a/deploy/nutanix.sh +++ b/deploy/nutanix.sh @@ -8,7 +8,6 @@ # export NUTANIX_PASS="" # required # export NUTANIX_HOST="" # required - #domain keyfile certfile cafile fullchain nutanix_deploy() { _cdomain="$1" @@ -53,5 +52,3 @@ nutanix_deploy() { 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 $? } - -