Fix formatting
This commit is contained in:
parent
8cb915023d
commit
6408c702d4
@ -18,12 +18,12 @@
|
||||
|
||||
rancher_deploy() {
|
||||
_cdomain="$1"
|
||||
# Further $(cat $1 | sed 's/$/\\n/' | tr -d '\n')
|
||||
# Further $(echo "$1" | sed 's/$/\\n/' | tr -d '\n')
|
||||
# Made for iclude cert in var in one line with \n
|
||||
_ckey=$(cat $2 | sed 's/$/\\n/' | tr -d '\n')
|
||||
_ccert=$(cat $3 | sed 's/$/\\n/' | tr -d '\n')
|
||||
_cca=$(cat $4 | sed 's/$/\\n/' | tr -d '\n')
|
||||
_cfullchain=$(cat $5 | sed 's/$/\\n/' | tr -d '\n')
|
||||
_ckey=$(echo "$2" | sed 's/$/\\n/' | tr -d '\n')
|
||||
_ccert=$(echo "$3" | sed 's/$/\\n/' | tr -d '\n')
|
||||
_cca=$(echo "$4" | sed 's/$/\\n/' | tr -d '\n')
|
||||
_cfullchain=$(echo "$5" | sed 's/$/\\n/' | tr -d '\n')
|
||||
|
||||
_debug _cdomain "$_cdomain"
|
||||
_debug _ckey "$_ckey"
|
||||
@ -91,12 +91,12 @@ rancher_deploy() {
|
||||
|
||||
# Check api connection
|
||||
response=$(
|
||||
curl $Le_rancher_server/v2-beta/ \
|
||||
--write-out %{http_code} \
|
||||
curl "$Le_rancher_server/v2-beta/" \
|
||||
--write-out "%{http_code}" \
|
||||
--silent \
|
||||
--output /dev/null
|
||||
)
|
||||
if [[ "$response" -ge 200 && "$response" -le 299 ]]; then
|
||||
if [ "$response" -ge 200 ] && [ "$response" -le 299 ]; then
|
||||
_err "Curl failed to connect to $Le_rancher_server v2-beta API"
|
||||
return 1
|
||||
else
|
||||
@ -105,20 +105,20 @@ rancher_deploy() {
|
||||
|
||||
# Check if certificate already exist in rancher
|
||||
|
||||
id_raw_json=`curl -s -u "$Le_rancher_access_key:$Le_rancher_secret_key" \
|
||||
id_raw_json=$(curl -s -u "$Le_rancher_access_key:$Le_rancher_secret_key" \
|
||||
-X GET \
|
||||
-H 'Accept: application/json' \
|
||||
-H 'Content-Type: application/json' \
|
||||
"$Le_rancher_server/v2-beta/projects/$Le_rancher_environment/certificates?name=$_cdomain"`
|
||||
cert_state=$(echo $id_raw_json | awk -F='\:' -v RS='\,' "\$id_raw_json~/\"state\"/ {print}" | tr -d "\n\t" | sed -e 's/^"//' -e 's/"$//' | grep -o active)
|
||||
"$Le_rancher_server/v2-beta/projects/$Le_rancher_environment/certificates?name=$_cdomain")
|
||||
cert_state=$(echo "$id_raw_json" | awk -F='\:' -v RS='\,' "\$id_raw_json~/\"state\"/ {print}" | tr -d "\n\t" | sed -e 's/^"//' -e 's/"$//' | grep -o "active")
|
||||
_info "Cert state is $cert_state"
|
||||
if [ -z $cert_state ]; then
|
||||
if [ -z "$cert_state" ]; then
|
||||
# Add new certificate
|
||||
_info "Adding new cert to rancher"
|
||||
response=$(
|
||||
curl -u "$Le_rancher_access_key:$Le_rancher_secret_key" \
|
||||
-X POST \
|
||||
--write-out %{http_code} \
|
||||
--write-out "%{http_code}" \
|
||||
--silent \
|
||||
--output /dev/null \
|
||||
-H 'Accept: application/json' \
|
||||
@ -127,25 +127,25 @@ rancher_deploy() {
|
||||
"$Le_rancher_server/v2-beta/projects/$Le_rancher_environment/certificates/"
|
||||
)
|
||||
_info "Update status code: $response"
|
||||
if [[ $response -lt 199 || $response -gt 300 ]]; then
|
||||
if [ "$response" -lt 199 ] || [ "$response" -gt 300 ]; then
|
||||
_err "Curl failed to create new cert"
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
# Get certificate ID
|
||||
id_raw_json=`curl -s -u "$Le_rancher_access_key:$Le_rancher_secret_key" \
|
||||
id_raw_json=$(curl -s -u "$Le_rancher_access_key:$Le_rancher_secret_key" \
|
||||
-X GET \
|
||||
-H 'Accept: application/json' \
|
||||
-H 'Content-Type: application/json' \
|
||||
"$Le_rancher_server/v2-beta/projects/$Le_rancher_environment/certificates?name=$_cdomain"`
|
||||
cert_id=$(echo $id_raw_json | awk -F='\:' -v RS='\,' "\$id_raw_json~/\"data\"/ {print}" | tr -d "\n\t" | sed -e 's/^"//' -e 's/"$//' | sed -e 's/data.*"//')
|
||||
"$Le_rancher_server/v2-beta/projects/$Le_rancher_environment/certificates?name=$_cdomain")
|
||||
cert_id=$(echo "$id_raw_json" | awk -F='\:' -v RS='\,' "\$id_raw_json~/\"data\"/ {print}" | tr -d "\n\t" | sed -e 's/^"//' -e 's/"$//' | sed -e 's/data.*"//')
|
||||
_info "Cert already exist ID is: $cert_id"
|
||||
# Update existing certificate
|
||||
_info "Updating..."
|
||||
response=$(
|
||||
curl -u "$Le_rancher_access_key:$Le_rancher_secret_key" \
|
||||
-X PUT \
|
||||
--write-out %{http_code} \
|
||||
--write-out "%{http_code}" \
|
||||
--silent \
|
||||
--output /dev/null \
|
||||
-H 'Accept: application/json' \
|
||||
@ -154,7 +154,7 @@ rancher_deploy() {
|
||||
"$Le_rancher_server/v2-beta/projects/$Le_rancher_environment/certificates/$cert_id"
|
||||
)
|
||||
_info "Update status code: $response"
|
||||
if [[ $response -lt 199 || $response -gt 300 ]]; then
|
||||
if [ "$response" -lt 199 ] || [ "$response" -gt 300 ]; then
|
||||
_err "Curl failed to update cert with id=$cert_id"
|
||||
return 1
|
||||
fi
|
||||
|
||||
Loading…
Reference in New Issue
Block a user