Commit 00152eb8 authored by Luca Dietiker's avatar Luca Dietiker
Browse files

Merge branch 'callback-logger' into 'main'

Callback logger

See merge request ralf.winkelmann/ssi-infrastructure-playground!1
parents 512c8823 91eeee68
......@@ -48,4 +48,11 @@ npm run swagger-autogen
## Jolocom with arm64 Macbook
Jolocom currently doesn't support the architecture arm64 of the new M1 processor. To use Jolocom with arm64, use the following guide:
[How to setup Node.js on Apple M1 Machine](https://www.jurnalanas.com/node-js-mac-m1/)
\ No newline at end of file
[How to setup Node.js on Apple M1 Machine](https://www.jurnalanas.com/node-js-mac-m1/)
## Callback Logger Deployment
Run the following command:
```terminal
gcloud builds submit --region=europe-west1 --project=dotted-byway-356119
```
\ No newline at end of file
FROM amd64/node:14
WORKDIR /usr/src/app
ENV PORT 3501
# Copy and install dependencies
COPY package*.json ./
RUN npm install
# Copy app data
COPY app ./app
COPY swagger.js ./
COPY swagger-output.json ./
EXPOSE 3501
CMD [ "npm", "run", "start-prod"]
\ No newline at end of file
import express from 'express';
import cors from 'cors';
import bodyParser from 'body-parser';
import { readFileSync } from 'fs';
import swaggerUi from 'swagger-ui-express';
const swaggerFile = JSON.parse(readFileSync('./swagger-output.json'));
const app = express();
// middleware
app.use(bodyParser.json());
app.use(cors());
// endpoints
app.post('/callback/:requestId', async (req, res) => {
// #swagger.parameters['requestId'] = { description: 'Generated id for request' }
/* #swagger.parameters['token'] = {
in: 'body',
description: 'Token sent back by Jolocom Wallet'
} */
// log callback data
console.log('\n----- NEW CALLBACK TO LOG -----\n');
console.log('Request Id: ', req.params.requestId);
console.log('Request Headers: ', JSON.stringify(req.headers));
console.log('Request Body: ', req.body);
console.log('\n----- LOGGING FINISHED -----\n\n');
return res.sendStatus(200);
});
// API Doc
app.use('/doc', swaggerUi.serve, swaggerUi.setup(swaggerFile))
const backendPort = 3501;
app.listen(backendPort, () => {
console.log(`Backend is running: http://localhost:${backendPort}/doc`)
});
\ No newline at end of file
steps:
# Build the container image
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '-t', 'gcr.io/dotted-byway-356119/callback-logger-image', '.']
# Push the container image to Container Registry
- name: 'gcr.io/cloud-builders/docker'
args: ['push', 'gcr.io/dotted-byway-356119/callback-logger-image']
# Deploy container image to Cloud Run
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
entrypoint: gcloud
args: ['run', 'deploy', 'callback-logger', '--image', 'gcr.io/dotted-byway-356119/callback-logger-image', '--region', 'europe-west1', '--port', '3501']
images:
- gcr.io/dotted-byway-356119/callback-logger-image
\ No newline at end of file
This diff is collapsed.
{
"name": "callback-logger",
"version": "1.0.0",
"type": "module",
"private": true,
"license": "UNLICENSED",
"description": "REST API to log callbacks from Jolocom wallet.",
"scripts": {
"start": "nodemon ./app/app.js",
"start-prod": "NODE_ENV=production node ./app/app.js",
"swagger-autogen": "node ./swagger.js"
},
"author": "Luca Dietiker, Ralf Winkelmann",
"dependencies": {
"body-parser": "^1.20.0",
"cors": "^2.8.5",
"express": "^4.18.1",
"swagger-ui-express": "^4.4.0"
},
"devDependencies": {
"nodemon": "^2.0.16",
"swagger-autogen": "^2.21.3"
}
}
{
"swagger": "2.0",
"info": {
"title": "Callback Logger",
"description": "Provides endpoint to be used as callback for Jolocom Wallet and log output.",
"version": "1.0.0"
},
"host": "localhost:3501",
"basePath": "/",
"schemes": [
"http"
],
"paths": {
"/callback/{requestId}": {
"post": {
"description": "",
"parameters": [
{
"name": "requestId",
"in": "path",
"required": true,
"type": "string",
"description": "Generated id for request"
},
{
"name": "token",
"in": "body",
"description": "Token sent back by Jolocom Wallet",
"schema": {
"type": "object",
"properties": {}
}
}
],
"responses": {
"200": {
"description": "OK"
}
}
}
}
}
}
\ No newline at end of file
import swaggerAutogen from 'swagger-autogen';
const doc = {
info: {
title: 'Callback Logger',
description: 'Provides endpoint to be used as callback for Jolocom Wallet and log output.',
version: '1.0.0'
},
host: `localhost:3501`,
};
const outputFile = './swagger-output.json';
const endpointsFiles = ['./app/app.js'];
swaggerAutogen()(outputFile, endpointsFiles, doc);
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment