diff --git a/api/src/util/bash/client.sh b/api/src/util/bash/client.sh index d17a28d..19fb1e1 100755 --- a/api/src/util/bash/client.sh +++ b/api/src/util/bash/client.sh @@ -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 .