Last active
December 28, 2024 16:03
-
-
Save hellt/b8e16b01fb6686f9c0bff7cbfc9093b7 to your computer and use it in GitHub Desktop.
nsp-curl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
while [ $# -gt 0 ]; do | |
case "$1" in | |
# IP address or the domain name of the NSP server (without http(s) schema) | |
--nsp_url=*) | |
NSP_URL="${1#*=}" | |
;; | |
# http proxy which will be used by curl if set | |
--proxy=*) | |
HTTP_PROXY="${1#*=}" | |
;; | |
--req=*) | |
REQ="${1#*=}" | |
;; | |
*) | |
printf "Unexpected Variable!" | |
exit 1 | |
;; | |
esac | |
shift | |
done | |
# when proxy address set, curl should use it | |
if [ -z "$HTTP_PROXY" ]; then | |
HTTP_PROXY_CMD="" | |
else | |
HTTP_PROXY_CMD="-x ${HTTP_PROXY}" | |
fi | |
if [ -z "$NSP_URL" ]; then | |
echo "ERROR: NSP URL should be set" | |
echo "usage: bash wf-sync.sh --nsp_url=<nsp_address> --wf_file=<path_to_workflow_file> --wf_id=<workflow_id> [--proxy=<http_proxy>]" | |
exit 1 | |
fi | |
function get_access_token() { | |
# get access_token | |
# echo "Getting access token..." | |
ACCESS_TOKEN=$(curl -skLN ${HTTP_PROXY_CMD} --request POST "https://${NSP_URL}/rest-gateway/rest/api/v1/auth/token" \ | |
--header 'Content-Type: application/json' \ | |
--header 'Authorization: Basic YWRtaW46Tm9raWFOc3AxIQ==' \ | |
--data '{ | |
"grant_type":"client_credentials" | |
}' | jq --raw-output '.access_token') | |
} | |
function revoke_access_token() { | |
# get access_token | |
# echo "Revoking access token..." | |
ACCESS_TOKEN=$( | |
curl -skLN ${HTTP_PROXY_CMD} --request POST "https://${NSP_URL}/rest-gateway/rest/api/v1/auth/revocation" \ | |
--header 'Authorization: Basic YWRtaW46Tm9raWFOc3AxIQ==' \ | |
--data-urlencode "token=${ACCESS_TOKEN}" \ | |
--data-urlencode 'token_type_hint=token' | |
) | |
} | |
get_access_token | |
curl -skL ${HTTP_PROXY_CMD} --header "Authorization: Bearer ${ACCESS_TOKEN}" ${REQ} | jq --raw-output | |
revoke_access_token |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment