api: Refresh the API CLI wrapper script.
This commit is contained in:
parent
3844e97c48
commit
2fd45ac35c
@ -1,24 +1,37 @@
|
||||
#!/bin/bash
|
||||
|
||||
api_base_url="${PM_API_BASE_URL:-http://localhost:8081}"
|
||||
api_base_url="${PM_API_BASE_URL:-http://localhost:8100/v0}"
|
||||
if [ $# -eq 1 ]; then
|
||||
url="$1"
|
||||
method="GET"
|
||||
data=""
|
||||
elif [ $# -eq 2 ]; then
|
||||
method="$1"
|
||||
url="$2"
|
||||
data=""
|
||||
else
|
||||
if [ $1 == "auth-token" ]; then
|
||||
curl -s -X POST \
|
||||
-H "Origin: https://curl.localhost" \
|
||||
"${api_base_url}/auth-token" \
|
||||
-d "$2" \
|
||||
| xargs printf "Bearer %s" \
|
||||
> credential
|
||||
|
||||
exit 0
|
||||
else
|
||||
method="$1"
|
||||
url="$2"
|
||||
data=""
|
||||
fi
|
||||
else
|
||||
method="$1"
|
||||
url="$2"
|
||||
data="$3"
|
||||
fi
|
||||
|
||||
if [[ ! $url = /* ]]; then url="/$url"; fi
|
||||
|
||||
curl -s -X "$method" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: $(cat credential)" \
|
||||
-H "Origin: https://curl.localhost" \
|
||||
"${api_base_url}/api/$url" \
|
||||
"${api_base_url}$url" \
|
||||
-d "$data" \
|
||||
-v
|
||||
| jq .
|
||||
|
Loading…
x
Reference in New Issue
Block a user