mirror of
https://github.com/aljazceru/cyphernode.git
synced 2026-01-28 08:44:28 +01:00
OTS info first draft
This commit is contained in:
@@ -9,8 +9,12 @@ serve_ots_stamp() {
|
||||
local request=${1}
|
||||
local hash=$(echo "${request}" | jq -r ".hash")
|
||||
trace "[serve_ots_stamp] hash=${hash}"
|
||||
local callbackUrl=$(echo "${request}" | jq -r ".callbackUrl")
|
||||
[ "${callbackUrl}" = "null" ] && callbackUrl=
|
||||
local callbackUrl
|
||||
callbackUrl=$(echo "${request}" | jq -er ".callbackUrl")
|
||||
if [ "$?" -ne "0" ]; then
|
||||
# callbackUrl tag null, so there's no callbackUrl provided
|
||||
callbackUrl=
|
||||
fi
|
||||
trace "[serve_ots_stamp] callbackUrl=${callbackUrl}"
|
||||
|
||||
local result
|
||||
@@ -204,7 +208,7 @@ serve_ots_backoffice() {
|
||||
trace "[serve_ots_backoffice] url=${url}"
|
||||
|
||||
# Call back newly upgraded stamps if url provided
|
||||
if [ ${#url} -gt 0 ]; then
|
||||
if [ -n ${url} ]; then
|
||||
trace "[serve_ots_backoffice] url is not empty, now trying to call it!"
|
||||
|
||||
notify_web "${url}"
|
||||
@@ -301,3 +305,88 @@ request_ots_verify() {
|
||||
echo "${result}"
|
||||
return ${returncode}
|
||||
}
|
||||
|
||||
serve_ots_info() {
|
||||
|
||||
trace "Entering serve_ots_info()..."
|
||||
|
||||
local request=${1}
|
||||
local hash
|
||||
hash=$(echo "${request}" | jq -e ".hash" | tr -d '"')
|
||||
if [ "$?" -ne "0" ]; then
|
||||
# Hash tag null, so there's no hash provided
|
||||
hash=
|
||||
fi
|
||||
trace "[serve_ots_info] hash=${hash}"
|
||||
local base64otsfile
|
||||
base64otsfile=$(echo "${request}" | jq -e ".base64otsfile" | tr -d '"')
|
||||
if [ "$?" -ne "0" ]; then
|
||||
# base64otsfile tag null, so there's no base64otsfile provided
|
||||
base64otsfile=
|
||||
fi
|
||||
trace "[serve_ots_info] base64otsfile=${base64otsfile}"
|
||||
|
||||
# If file is provided, we will execute info on it
|
||||
# If file not provided, we will check for hash.ots in our folder and execute info on it
|
||||
if [ -z "${base64otsfile}" ]; then
|
||||
if [ -f otsfiles/${hash}.ots ]; then
|
||||
trace "[serve_ots_info] Constructing base64otsfile from provided hash, file otsfiles/${hash}.ots"
|
||||
base64otsfile=$(cat otsfiles/${hash}.ots | base64 | tr -d '\n')
|
||||
else
|
||||
trace "[serve_ots_info] File otsfiles/${hash}.ots does not exists!"
|
||||
echo "{\"method\":\"ots_info\",\"result\":\"error\",\"message\":\"OTS File not found\"}"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
local result
|
||||
local message
|
||||
local returncode
|
||||
|
||||
trace "[serve_ots_info] request_ots_info \"${base64otsfile}\""
|
||||
result=$(request_ots_info "${base64otsfile}")
|
||||
returncode=$?
|
||||
trace_rc ${returncode}
|
||||
|
||||
if [ "${returncode}" -eq "0" ]; then
|
||||
result=$(echo ${result} | jq ".result")
|
||||
result="{\"method\":\"ots_info\",\"result\":\"success\",\"message\":${result}}"
|
||||
else
|
||||
result="{\"method\":\"ots_info\",\"result\":\"error\",\"message\":${result}}"
|
||||
fi
|
||||
|
||||
trace "[serve_ots_info] result=${result}"
|
||||
|
||||
# Output response to stdout before exiting with return code
|
||||
echo "${result}"
|
||||
|
||||
return ${returncode}
|
||||
}
|
||||
|
||||
request_ots_info() {
|
||||
# Request the OTS server to verify
|
||||
|
||||
local base64otsfile=${1}
|
||||
trace "[request_ots_info] base64otsfile=${base64otsfile}"
|
||||
local returncode
|
||||
local result
|
||||
local data
|
||||
|
||||
# BODY {"base64otsfile":"AE9wZW5UaW1lc3RhbXBzAABQcm9vZ...gABYiWDXPXGQEDxNch"}
|
||||
data="{\"base64otsfile\":\"${base64otsfile}\"}"
|
||||
trace "[request_ots_info] data=${data}"
|
||||
|
||||
trace "[request_ots_info] Parsing..."
|
||||
trace "[request_ots_info] curl -s -d \"${data}\" ${OTSCLIENT_CONTAINER}/info"
|
||||
result=$(curl -s -d "${data}" ${OTSCLIENT_CONTAINER}/info)
|
||||
returncode=$?
|
||||
trace_rc ${returncode}
|
||||
trace "[request_ots_info] OTS info result=${result}"
|
||||
|
||||
if [ "${returncode}" -ne 0 ]; then
|
||||
trace "[request_ots_info] OTS info error"
|
||||
fi
|
||||
|
||||
echo "${result}"
|
||||
return ${returncode}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user