diff --git a/contrib/jsonsh-lib.sh b/contrib/jsonsh-lib.sh index 028f916..755d651 100644 --- a/contrib/jsonsh-lib.sh +++ b/contrib/jsonsh-lib.sh @@ -161,7 +161,7 @@ _JSonSH_rewrite_output() } # -# return JSON keys +# print JSON keys # # usage : getJSONKeys # @@ -176,12 +176,9 @@ getJSONKeys() } # -# return the value for a defined filed +# print the value for a defined field # -# if field is a string, it can be set with/without double quotes -# if the result is between double quotes, only get the value inside -# -# usage : getJSONValue "json" field +# usage : getJSONValue field # getJSONValue() { diff --git a/contrib/ovh-api-lib.sh b/contrib/ovh-api-lib.sh index f37ca09..539f28a 100644 --- a/contrib/ovh-api-lib.sh +++ b/contrib/ovh-api-lib.sh @@ -4,7 +4,8 @@ readonly OVHAPI_BASHCLIENT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}")/.." && pwd) readonly OVHAPI_BASHCLIENT_BIN="${OVHAPI_BASHCLIENT_DIR}/ovh-api-bash-client.sh" readonly OVHAPI_BASHCLIENT_CONTRIB_DIR="${OVHAPI_BASHCLIENT_DIR}/contrib" -. "${OVHAPI_BASHCLIENT_DIR}/contrib/jsonsh-lib.sh" || exit 1 +JSONSH_DIR="${OVHAPI_BASHCLIENT_DIR}/libs/" +. "${OVHAPI_BASHCLIENT_CONTRIB_DIR}/jsonsh-lib.sh" || exit 1 OVHAPI_HTTP_STATUS= OVHAPI_HTTP_RESPONSE= @@ -43,13 +44,14 @@ OvhRequestApi() local data=$3 local client_response= - + local cmd_profile= local cmd=(${OVHAPI_BASHCLIENT_BIN}) ## construct arguments array if [ -n "${OVHAPI_BASHCLIENT_PROFILE}" ]; then cmd+=(--profile ${OVHAPI_BASHCLIENT_PROFILE}) fi + cmd_profile=${cmd[*]} if [ -n "${url}" ]; then cmd+=(--url ${url}) @@ -77,6 +79,14 @@ OvhRequestApi() OVHAPI_HTTP_STATUS=$(echo "${client_response}" | cut -d ' ' -f1) OVHAPI_HTTP_RESPONSE="$(echo "${client_response}" | cut -d ' ' -f2-)" + # catch profile error + if [[ ! ${OVHAPI_HTTP_STATUS} =~ ^[0-9]+$ ]] && [[ ${OVHAPI_HTTP_RESPONSE} == *$'\n'* ]]; then + OVHAPI_HTTP_STATUS=500 + OVHAPI_HTTP_RESPONSE=$(cat <