Skip to content

Commit

Permalink
feat(2151): helm-release-v12.1.0 (#843)
Browse files Browse the repository at this point in the history
- Aligned requestLoggers to Central-Ledger
- Added populateTestData test script to register oracles and create participant-party link
- Minor alignment to error Loggers
  • Loading branch information
mdebarros committed May 28, 2021
1 parent fd70ab6 commit 8eca992
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 13 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@
"mysql": "2.18.1",
"npm-run-all": "4.1.5",
"parse-strings-in-object": "2.0.0",
"rc": "1.2.8"
"rc": "1.2.8",
"uuid4": "2.0.2"
},
"devDependencies": {
"@types/jest": "26.0.23",
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/participants/{Type}/{ID}.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ module.exports = {
participants.getParticipantsByTypeAndID(request.headers, request.params, request.method, request.query, span)
histTimerEnd({ success: true })
} catch (err) {
Logger.error(`ERROR - ${metadata}: ${err}`)
Logger.error(`ERROR - ${metadata}: ${err.stack}`)
histTimerEnd({ success: false })
throw ErrorHandler.Factory.reformatFSPIOPError(err)
}
Expand Down
18 changes: 10 additions & 8 deletions src/lib/requestLogger.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,27 @@ const Logger = require('@mojaloop/central-services-logger')
const Util = require('util')

const logRequest = function (request) {
Logger.debug(`ALS-Trace - Method: ${request.method} Path: ${request.url.path} Query: ${JSON.stringify(request.query)}`)
Logger.debug(`ALS-Trace - Headers: ${JSON.stringify(request.headers)}`)
if (request.body) {
Logger.debug(`ALS-Trace - Body: ${request.body}`)
const traceId = request.headers.traceid
Logger.isDebugEnabled && Logger.debug(`ALS-Trace=${traceId} - Method: ${request.method} Path: ${request.path} Query: ${JSON.stringify(request.query)}`)
Logger.isDebugEnabled && Logger.debug(`ALS-Trace=${traceId} - Headers: ${JSON.stringify(request.headers, null, 2)}`)
if (request.payload) {
Logger.isDebugEnabled && Logger.debug(`ALS-Trace=${traceId} - Body: ${JSON.stringify(request.payload, null, 2)}`)
}
}

const logResponse = function (request) {
const traceId = request.headers.traceid
if (request.response) {
let response
try {
response = JSON.stringify(request.response.source)
response = JSON.stringify(request.response, null, 2)
} catch (e) {
response = Util.inspect(request.response.source)
response = Util.inspect(request.response)
}
if (!response) {
Logger.info(`ALS-Trace - Response: ${request.response}`)
Logger.isDebugEnabled && Logger.debug(`ALS-Trace=${traceId} - Response: ${request.response}`)
} else {
Logger.info(`ALS-Trace - Response: ${response} Status: ${request.response.statusCode}`)
Logger.isDebugEnabled && Logger.debug(`ALS-Trace=${traceId} - Response: ${response} Status: ${request.response.statusCode || request.response.httpStatusCode}, Stack: ${request.response.stack}`)
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

const Hapi = require('@hapi/hapi')
const Boom = require('@hapi/boom')
const Uuid = require('uuid4')
const ParticipantEndpointCache = require('@mojaloop/central-services-shared').Util.Endpoints
const OpenapiBackend = require('@mojaloop/central-services-shared').Util.OpenapiBackend
const HeaderValidator = require('@mojaloop/central-services-shared').Util.Hapi.FSPIOPHeaderValidation
Expand Down Expand Up @@ -81,16 +82,17 @@ const createServer = async (port, api, routes, isAdmin) => {
])
await server.ext([
{
type: 'onRequest',
type: 'onPostAuth',
method: (request, h) => {
request.headers.traceid = request.headers.traceid || Uuid()
RequestLogger.logRequest(request)
return h.continue
}
},
{
type: 'onPreResponse',
method: (request, h) => {
RequestLogger.logResponse(request.response)
RequestLogger.logResponse(request)
return h.continue
}
}
Expand Down
16 changes: 15 additions & 1 deletion test/util/scripts/env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,18 @@
export MOCKSERVER_ID=mockserver
export SLEEP_FACTOR_IN_SECONDS=5
export DB_ID=mysql
export DBPASS=password
export DBPASS=password

# Admin API
export ACCOUNT_LOOKUP_ADMIN_URI_PREFIX=http
export ACCOUNT_LOOKUP_ADMIN_HOST=localhost
export ACCOUNT_LOOKUP_ADMIN_PORT=4001
export ACCOUNT_LOOKUP_ADMIN_BASE=/

# FSPIOP API
export ACCOUNT_LOOKUP_FSPIOP_URI_PREFIX=http
export ACCOUNT_LOOKUP_FSPIOP_HOST=localhost
export ACCOUNT_LOOKUP_FSPIOP_PORT=4002
export ACCOUNT_LOOKUP_FSPIOP_BASE=/

export PAYEE_PARTICIPANT_LIST=("27713803912")
62 changes: 62 additions & 0 deletions test/util/scripts/populateTestData.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env bash
echo "---------------------------------------------------------------------"
echo "Starting script to populate test data.."
echo "---------------------------------------------------------------------"
echo

CWD="${0%/*}"

if [[ "$CWD" =~ ^(.*)\.sh$ ]];
then
CWD="."
fi

echo "Loading env vars..."
source $CWD/env.sh

echo "---------------------------------------------------------------------"
echo "Registering Oracles for MSISDNs."
echo "---------------------------------------------------------------------"
curl --location ${ACCOUNT_LOOKUP_ADMIN_URI_PREFIX}://${ACCOUNT_LOOKUP_ADMIN_HOST}:${ACCOUNT_LOOKUP_ADMIN_PORT}${ACCOUNT_LOOKUP_ADMIN_BASE}oracles \
--header 'Cache-Control: no-cache' \
--header 'Content-Type: application/json' \
--header 'cache-control: no-cache' \
--header 'FSPIOP-Source: populateTestData.sh' \
--header 'Date: Thu, 24 Jan 2019 10:22:12 GMT' \
--data-raw '{
"oracleIdType": "MSISDN",
"endpoint": {
"value": "http://localhost:8444/oracle",
"endpointType": "URL"
},
"currency": "USD",
"isDefault": true
}'

echo
echo "---------------------------------------------------------------------"
echo " Creating TestData for $FSPList"
echo "---------------------------------------------------------------------"
echo " Prerequisites for Central-Ledger:"
echo " 1. Ensure you run 'npm run migrate'"
echo " 2. The below requests only work for the 'ADMIN' API"

for PAYEE_PARTICIPANT in "${PAYEE_PARTICIPANT_LIST[@]}"
do
echo ''
echo "*********************************************************************"
echo ''
echo
echo "Creating participants '$PAYEE_PARTICIPANT'"
echo "---------------------------------------------------------------------"
curl --location ${ACCOUNT_LOOKUP_FSPIOP_URI_PREFIX}://${ACCOUNT_LOOKUP_FSPIOP_HOST}:${ACCOUNT_LOOKUP_FSPIOP_PORT}${ACCOUNT_LOOKUP_FSPIOP_BASE}participants/MSISDN/${PAYEE_PARTICIPANT} \
--header 'Cache-Control: no-cache' \
--header 'Content-Type: application/vnd.interoperability.participants+json;version=1.0' \
--header 'Date: Thu, 24 Jan 2019 10:22:12 GMT' \
--header 'FSPIOP-Source: payeefsp' \
--header 'Accept: application/vnd.interoperability.participants+json;version=1.0' \
--data-binary '{
"fspId": "payeefsp",
"currency": "USD"
}'
done

0 comments on commit 8eca992

Please sign in to comment.