API call improvement
This commit is contained in:
parent
aacd713265
commit
e766f4030b
31
functions.sh
31
functions.sh
@ -33,12 +33,31 @@ miria_error() {
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Output:
|
||||
# miria_url : Miria API URL
|
||||
#######################################
|
||||
miria_get_url() {
|
||||
if [ -e ~/.miria-url ]; then
|
||||
miria_url="$(cat ~/.miria-url)"
|
||||
if [ -e ~/.miria ]; then
|
||||
miria_url="$(grep -E ' *url +' ~/.miria | awk '{print $2}')"
|
||||
else
|
||||
miria_error 'file ~/.miria-url not found'
|
||||
miria_error 'file ~/.miria not found'
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
#######################################
|
||||
# Get Mira agent
|
||||
#
|
||||
# Arguments:
|
||||
# None
|
||||
# Output:
|
||||
# miria_agent : Miria agent name
|
||||
#######################################
|
||||
miria_get_agent() {
|
||||
if [ -e ~/.miria ]; then
|
||||
miria_agent="$(grep -E ' *agent +' ~/.miria | awk '{print $2}')"
|
||||
else
|
||||
miria_error 'file ~/.miria not found'
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
@ -56,6 +75,8 @@ miria_get_url() {
|
||||
# miria_last_status : last return code
|
||||
# miria_last_error : last error message
|
||||
#######################################
|
||||
miria_api_error_fatal='true'
|
||||
|
||||
miria_api_cmd() {
|
||||
local url_args=()
|
||||
local cmd="$1"
|
||||
@ -63,13 +84,13 @@ miria_api_cmd() {
|
||||
miria_get_url
|
||||
shift
|
||||
for a in "$@"; do
|
||||
url_args+=('--data-urlencode')
|
||||
url_args+=('--data')
|
||||
url_args+=("${a}")
|
||||
done
|
||||
miria_last_xml="$(curl -sG "${url_args[@]}" "${miria_url}/${cmd}")"
|
||||
miria_last_status="$(miria_xml_get_attribute "${miria_last_xml}" '//ReturnCode' 'ADARetCode')"
|
||||
miria_last_error="$(miria_xml_get_string "${miria_last_xml}" '//ErrorMsg')"
|
||||
if [[ "${miria_last_status}" != "1" ]]; then
|
||||
if [[ "${miria_last_status}" != '1' ]] && [[ "${miria_api_error_fatal}" == 'true' ]]; then
|
||||
miria_error "Miria API call returned status ${miria_last_status}"
|
||||
miria_error "${miria_last_error}"
|
||||
exit 1
|
||||
|
Loading…
Reference in New Issue
Block a user