-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ncr: TM-597: add automation scripts for nomis reporting (#1063)
* add helper script for querying restful api * - * add scripts
- Loading branch information
1 parent
c1c502f
commit 8fd2330
Showing
8 changed files
with
913 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,3 +113,5 @@ sap_web_apps: | |
- clientapi | ||
- dswsbobje | ||
- webi-websetup | ||
|
||
sap_bip_rws_url: "{{ sap_bip_conf.sap_bip_rws_url }}" |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
#!/bin/bash | ||
# Wrapper for logging in and querying biprws endpoint | ||
|
||
set -e | ||
|
||
BIPRWS='{{ sap_bip_rws_url }}' | ||
AUTH=secEnterprise | ||
USERNAME=Administrator | ||
DEBUG=${DEBUG:-0} | ||
|
||
usage() { | ||
echo "Usage: $0 <query>" | ||
echo | ||
echo "e.g. $0 'SELECT * FROM CI_SYSTEMOBJECTS'" | ||
} | ||
|
||
login() { | ||
local logon | ||
local token | ||
|
||
logon='{"username": "'$USERNAME'", "password": "'$PASSWORD'", "auth": "'$AUTH'"}' | ||
[[ $DEBUG != 0 ]] && echo "logon: $logon" >&2 | ||
token=$(curl -Ss -H "Content-Type: application/json" -H "Accept: application/json" --data "$logon" "$BIPRWS/v1/logon/long") | ||
jq -r ".logontoken" <<< "$token" | ||
} | ||
|
||
cms_query() { | ||
local query | ||
local token | ||
local uri | ||
local query_debug | ||
|
||
token="$1" | ||
query_escaped=$(jq -R <<< "$2") | ||
query='{"query":'$query_escaped'}' | ||
uri="$3" | ||
query_debug="$4" | ||
[[ $query_debug != 0 ]] && echo "query: $query" >&2 | ||
curl -Ss -H "Content-Type: application/json" -H "Accept: application/json" -H "X-SAP-LogonToken: $token" --data "$query" "$uri" | ||
} | ||
|
||
join_cms_queries() { | ||
local query_debug | ||
local token | ||
local query | ||
local uri | ||
local page | ||
local json | ||
local nexturi | ||
local lasturi | ||
|
||
token="$1" | ||
query="$2" | ||
uri="$3" | ||
protocol=$(cut -d: -f1 <<< "$uri") | ||
query_debug=$DEBUG | ||
page=1 | ||
|
||
while true; do | ||
echo "uri $page: $uri" >&2 | ||
json=$(cms_query "$token" "$query" "$uri" "$query_debug") | ||
query_debug=0 | ||
[[ $DEBUG == 2 ]] && echo "$json" > debug.$page.json | ||
error_code=$(jq -r .error_code <<< "$json") | ||
message=$(jq -r .message <<< "$json") | ||
if [[ $error_code != 'null' ]]; then | ||
echo "error: $error_code: $message" >&2 | ||
exit 2 | ||
fi | ||
nexturi=$(jq -r .next.__deferred.uri <<< "$json" | sed "s/http:/${protocol}:/g") | ||
lasturi=$(jq -r .last.__deferred.uri <<< "$json" | sed "s/http:/${protocol}:/g") | ||
jq '.entries[]' <<< "$json" | ||
if [[ "$uri" == "$lasturi" || "$nexturi" == "null" ]]; then | ||
break | ||
fi | ||
if [[ "$uri" == "$nexturi" ]]; then | ||
echo "error: unexpected nexturi: $nexturi" >&2 | ||
exit 2 | ||
fi | ||
if (( page == 1000 )); then | ||
echo "error: reached page 1000" | ||
exit 2 | ||
fi | ||
uri="$nexturi" | ||
page=$((page + 1)) | ||
done | ||
} | ||
|
||
if [[ -z $1 ]]; then | ||
usage >&2 | ||
exit 1 | ||
fi | ||
|
||
if [[ -z $PASSWORD ]]; then | ||
echo "Please enter password for $USERNAME: " >&2 | ||
read -rs PASSWORD | ||
fi | ||
|
||
query="$1" | ||
uri="$BIPRWS/v1/cmsquery" | ||
token="\"$(login)\"" | ||
[[ $DEBUG != 0 ]] && echo "token: $token" >&2 | ||
|
||
join_cms_queries "$token" "$query" "$uri" | jq -s |
Oops, something went wrong.