You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ngcp-panel/tools_bin/ngcp-api-patch

69 lines
1.1 KiB

#!/bin/bash
CURL="/usr/bin/curl"
CREDS="$HOME/.ngcp-api"
TOOLS="/usr/share/ngcp-panel-tools/ngcp-api.inc"
usage () {
cat << EOF
Usage: $0 [OPTIONS] <url>
sends a patch request to NGCP REST API
OPTIONS:
-h this help
-v verbose mode
-f read the input info from a file instead of read stdin
-m use Header 'Refer: return=minimal'
EOF
exit 1
}
if [ -z "$APIUSER" ] ; then
if [ -f "$TOOLS" ] ; then
source "$TOOLS"
importcreds "$CREDS"
else
APIUSER="administrator:administrator"
fi
fi
INPUT=(-T -)
CTYPE="application/json-patch+json"
PREFER="representation"
while getopts "mf:hv" OPTION
do
case $OPTION in
h)
usage
;;
f)
INPUT=()
FILE_INPUT=(--data-binary @$OPTARG)
if [ ! -f "$OPTARG" ]; then
echo "No '$OPTARG' file found"
usage
fi
;;
m)
PREFER="minimal"
;;
v)
VERBOSE="--verbose"
;;
?)
usage
;;
esac
done
shift $((OPTIND - 1))
URL="$1"
if [ -z "$URL" ] ; then
usage
fi
${CURL} -i ${VERBOSE} -X PATCH \
-H 'Connection: close' -H "Prefer: return=$PREFER" \
-H "Content-Type: $CTYPE" \
--user "$APIUSER" --insecure "${FILE_INPUT[@]}" "$URL" "${INPUT[@]}"