22 |
23 |
24 |
25 |
26 | Block Id |
27 | Fingerprint |
28 | Block Info |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/containers/blockchain/testApplication/public/scripts/events.js:
--------------------------------------------------------------------------------
1 | /*eslint no-undef:0*/
2 | class Events {
3 | constructor() {
4 | var self = this;
5 | self.block = io.connect('http://localhost:3030/block');
6 | self.block.on('block', (data) => {
7 | console.log(data);
8 | self.update(JSON.parse(data));
9 | });
10 | self.block.on('connect', () => {
11 | console.log("Connected");
12 | });
13 | self.requestBlocks();
14 | }
15 | requestBlocks() {
16 | var query = {
17 | type: "blocks",
18 | queue: "seller_queue",
19 | params: {
20 | "noOfLastBlocks": "20"
21 | }
22 | };
23 | var self = this;
24 | $.ajax({
25 | url: "http://localhost:3000/api/execute",
26 | type: "POST",
27 | data: JSON.stringify(query),
28 | dataType: 'json',
29 | contentType: 'application/json; charset=utf-8',
30 | success: function (data) {
31 | data = typeof data !== "string" ? data : JSON.parse(data);
32 | console.log(" Result ID " + data.resultId);
33 | self.getResults(data.resultId, 0, self);
34 | },
35 | error: function (jqXHR, textStatus, errorThrown) {
36 | console.log(errorThrown);
37 | console.log(textStatus);
38 | console.log(jqXHR);
39 | }
40 | });
41 | }
42 | getResults(resultId, attemptNo, self) {
43 | if(attemptNo < 60) {
44 | //console.log("Attempt no " + attemptNo);
45 | $.get("http://localhost:3000/api/results/" + resultId).done(function (data) {
46 | data = typeof data !== "string" ? data : JSON.parse(data);
47 | //console.log(" Status " + data.status);
48 | if(data.status === "done") {
49 | self.loadBlocks(JSON.parse(data.result));
50 | } else {
51 | setTimeout(function () {
52 | self.getResults(resultId, attemptNo + 1, self);
53 | }, 3000);
54 | }
55 | }).fail(function () {
56 | console.log("error");
57 | });
58 | } else {
59 | console.error("exceeded Number of attempts");
60 | }
61 | }
62 | update(eventData) {
63 | var rowData = "
" + eventData["id"] + " | " + eventData["fingerprint"] + " | " + JSON.stringify(eventData["transactions"]) + " |
";
64 | $(rowData).hide().prependTo('#table_view tbody').fadeIn("slow").addClass('normal');
65 | }
66 | loadBlocks(data) {
67 | //console.log(data);
68 | data = data === "string" ? JSON.parse(data) : data;
69 | data = data.result.sort((a, b) => a.id > b.id);
70 | data.forEach(function (eventData) {
71 | var rowData = "
" + eventData["id"] + " | " + eventData["fingerprint"] + " | " + JSON.stringify(eventData["transactions"]) + " |
";
72 | $(rowData).hide().prependTo('#table_view tbody').fadeIn("slow").addClass('normal');
73 | });
74 | }
75 | }
76 | new Events();
--------------------------------------------------------------------------------
/containers/blockchain/testApplication/public/scripts/message.js:
--------------------------------------------------------------------------------
1 | /*eslint no-undef:0 */
2 | class ReqEvents {
3 | constructor() {}
4 | requestServer(params) {
5 | var self = this;
6 | $.ajax({
7 | url: "http://localhost:3000/api/execute",
8 | type: "POST",
9 | data: JSON.stringify(params),
10 | dataType: 'json',
11 | contentType: 'application/json; charset=utf-8',
12 | success: function (data) {
13 | data = typeof data !== "string" ? data : JSON.parse(data);
14 | //console.log(" Result ID " + data.resultId);
15 | self.getResults(data.resultId, 0, self);
16 | },
17 | error: function (jqXHR, textStatus, errorThrown) {
18 | console.log(errorThrown);
19 | console.log(textStatus);
20 | console.log(jqXHR);
21 | }
22 | });
23 | }
24 | getResults(resultId, attemptNo, self) {
25 | if(attemptNo < 60) {
26 | //console.log("Attempt no " + attemptNo);
27 | $.get("http://localhost:3000/api/results/" + resultId).done(function (data) {
28 | data = typeof data !== "string" ? data : JSON.parse(data);
29 | //console.log(" Status " + data.status);
30 | if(data.status === "done") {
31 | self.update(JSON.parse(data.result));
32 | } else {
33 | setTimeout(function () {
34 | self.getResults(resultId, attemptNo + 1, self);
35 | }, 3000);
36 | }
37 | }).fail(function () {
38 | console.log("error");
39 | });
40 | } else {
41 | console.error("exceeded Number of attempts");
42 | }
43 | }
44 | update(eventData) {
45 | var rowData = "
" + JSON.stringify(eventData) + " |
";
46 | $(rowData).hide().prependTo('#results_table tbody').fadeIn("slow").addClass('normal');
47 | }
48 | }
49 | var requestEvents = new ReqEvents();
50 | /*
51 | {
52 | type: "invoke",
53 | params: {
54 | "userId": "admin",
55 | "fcn": "move",
56 | "args": ["a", "b", "10"]
57 | }
58 | }
59 | */
60 | function amqpFunc() {
61 | var type = $('#type').val();
62 | var userId = $('#userId').val();
63 | var fcn = $('#fcn').val();
64 | var args = $('#argsValues').val().split(',');
65 | var input = {
66 | type: type,
67 | queue: "user_queue",
68 | params: {
69 | userId: userId,
70 | fcn: fcn,
71 | args: args
72 | }
73 | };
74 | requestEvents.requestServer(input);
75 | }
76 | document.getElementById("request_server").addEventListener("click", amqpFunc);
--------------------------------------------------------------------------------
/containers/blockchain/testApplication/public/test.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
Blockchain History of Events
6 |
7 |
12 |
13 |
14 |
21 |
22 |
56 |
57 |
58 |
59 |
60 |
61 | Query Results
62 | |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
--------------------------------------------------------------------------------
/containers/blockchain/ubuntu/configtxgen:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IBM/android-kubernetes-blockchain/5d6caeccd1888992f98fdd80eb27f993cd3945a1/containers/blockchain/ubuntu/configtxgen
--------------------------------------------------------------------------------
/containers/blockchain/ubuntu/cryptogen:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IBM/android-kubernetes-blockchain/5d6caeccd1888992f98fdd80eb27f993cd3945a1/containers/blockchain/ubuntu/cryptogen
--------------------------------------------------------------------------------
/containers/gravatar.yaml:
--------------------------------------------------------------------------------
1 | ---
2 | apiVersion: v1
3 | kind: Service
4 | metadata:
5 | name: gravatar
6 | labels:
7 | app: gravatar
8 | spec:
9 | ports:
10 | - port: 80
11 | protocol: TCP
12 | targetPort: 8080
13 | type: ClusterIP
14 | selector:
15 | app: gravatar
16 | ---
17 | apiVersion: extensions/v1beta1
18 | kind: Deployment
19 | metadata:
20 | name: gravatar-deployment
21 | labels:
22 | app: gravatar
23 | spec:
24 | strategy:
25 | type: Recreate
26 | template:
27 | metadata:
28 | labels:
29 | app: gravatar
30 | spec:
31 | containers:
32 | - image: anthonyamanse/gravatar:1.0
33 | imagePullPolicy: Always
34 | name: gravatar
35 | ports:
36 | - containerPort: 8080
37 |
--------------------------------------------------------------------------------
/containers/gravatar/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM node:8-onbuild
2 |
3 | # Install Node.js
4 | # RUN apt-get update
5 | # RUN apt-get install --yes curl
6 | # RUN curl --silent --location https://deb.nodesource.com/setup_8.x | bash -
7 | # RUN apt-get install --yes nodejs
8 | # RUN apt-get install --yes build-essential
9 |
10 | RUN node -v
11 |
12 | COPY app.js /
13 | COPY package.json /
14 |
15 | RUN npm install
16 | RUN npm rebuild
17 |
18 | EXPOSE 8080
19 |
20 | CMD ["node", "app.js"]
21 |
--------------------------------------------------------------------------------
/containers/gravatar/app.js:
--------------------------------------------------------------------------------
1 | const express = require('express');
2 | const minifig = require('minifig');
3 | const svg2png = require('svg2png');
4 | const random_name = require('node-random-name')
5 | const app = express();
6 |
7 | app.get('/gravatar/new', function(req, res) {
8 |
9 | minifig.makeSVG(function(svg) {
10 | var pngBuffer = svg2png.sync(new Buffer(svg),{width:300,height:300});
11 |
12 | res.send({name:random_name(),png:pngBuffer.toString('base64')})
13 | });
14 |
15 | });
16 |
17 | let port = process.env.PORT || 8080;
18 | app.listen(port, function() {
19 | console.log("To view your app, open this link in your browser: http://localhost:" + port);
20 | });
21 |
--------------------------------------------------------------------------------
/containers/gravatar/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "gravatar",
3 | "main": "app.js",
4 | "description": "gravatar",
5 | "version": "1.0.0",
6 | "private": false,
7 | "engines": {
8 | "node": "8.*"
9 | },
10 | "repository": {
11 | "type": "git",
12 | "url": "https://github.com/AnthonyAmanse/fitcoin-android"
13 | },
14 | "dependencies": {
15 | "body-parser": "^1.17.x",
16 | "express": "^4.15.x",
17 | "minifig": "^1.4.0",
18 | "node-random-name": "^1.0.1",
19 | "svg2png": "^4.1.1"
20 | },
21 | "author": "Anthony Amanse",
22 | "license": "Apache-2.0"
23 | }
24 |
--------------------------------------------------------------------------------
/containers/ingress-prod.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: extensions/v1beta1
2 | kind: Ingress
3 | metadata:
4 | annotations:
5 | ingress.kubernetes.io/rewrite-target: /
6 | name: ingress
7 | spec:
8 | tls:
9 | - hosts:
10 | - YOUR_INGRESS_URL
11 | secretName: YOUR_INGRESS_SECRET
12 | backend:
13 | serviceName: mobile-assets
14 | servicePort: 80
15 | rules:
16 | - host: YOUR_INGRESS_URL
17 | http:
18 | paths:
19 | - path: /api
20 | backend:
21 | serviceName: rabbitclient-api
22 | servicePort: 3000
23 | - path: /registerees
24 | backend:
25 | serviceName: registeree-api
26 | servicePort: 80
27 | - path: /leaderboard
28 | backend:
29 | serviceName: leaderboard-api
30 | servicePort: 80
31 |
--------------------------------------------------------------------------------
/containers/leaderboard-api.yaml:
--------------------------------------------------------------------------------
1 | ---
2 | apiVersion: v1
3 | kind: Service
4 | metadata:
5 | name: leaderboard-api
6 | labels:
7 | app: leaderboard-api
8 | spec:
9 | ports:
10 | - port: 80
11 | protocol: TCP
12 | targetPort: 8080
13 | type: ClusterIP
14 | selector:
15 | app: leaderboard-api
16 | ---
17 | apiVersion: extensions/v1beta1
18 | kind: Deployment
19 | metadata:
20 | name: leaderboard-api-deployment
21 | labels:
22 | app: leaderboard-api
23 | spec:
24 | strategy:
25 | type: Recreate
26 | template:
27 | metadata:
28 | labels:
29 | app: leaderboard-api
30 | spec:
31 | containers:
32 | - image: DOCKERHUB_USERNAME/codepattern-leaderboard:latest
33 | imagePullPolicy: Always
34 | name: leaderboard-api
35 | env:
36 | - name: MONGODB_URL
37 | value: ''
38 | ports:
39 | - containerPort: 8080
40 |
--------------------------------------------------------------------------------
/containers/leaderboard/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM node:8-alpine
2 |
3 | COPY app.js /
4 | COPY package.json /
5 | COPY routes /routes
6 | COPY models /models
7 |
8 | RUN npm install
9 |
10 | EXPOSE 8080
11 |
12 | CMD ["node", "app.js"]
13 |
--------------------------------------------------------------------------------
/containers/leaderboard/app.js:
--------------------------------------------------------------------------------
1 | const express = require("express");
2 | const app = express();
3 | const mongoose = require("mongoose");
4 | const assert = require("assert");
5 | const fs = require("fs");
6 | const cors = require("cors");
7 |
8 | const leaderboardRoute = require("./routes/leaderboard");
9 |
10 | const mongoDbUrl = process.env.MONGODB_URL;
11 | let ca;
12 | if (process.env.MONGODB_CERT_BASE64) { // if encoded certificate is set in ENV, use it.
13 | ca = new Buffer(process.env.MONGODB_CERT_BASE64, "base64");
14 | } else if (fs.existsSync("/etc/ssl/mongo.cert")) { // if mongo.cert exists, use it
15 | ca = [fs.readFileSync("/etc/ssl/mongo.cert")];
16 | } else if (process.env.UNIT_TEST == "test") { // if a test, don't do anything.
17 | console.log("This is a test. Run a local mongoDB.");
18 | } else {
19 | console.log("No certificate provided!");
20 | }
21 |
22 | let mongoDbOptions = {
23 | mongos: {
24 | useMongoClient: true,
25 | ssl: true,
26 | sslValidate: true,
27 | sslCA: ca,
28 | },
29 | };
30 |
31 | mongoose.connection.on("error", function(err) {
32 | console.log("Mongoose default connection error: " + err);
33 | });
34 |
35 | mongoose.connection.on("open", function(err) {
36 | console.log("CONNECTED...");
37 | assert.equal(null, err);
38 | });
39 |
40 | if (process.env.UNIT_TEST == "test") {
41 | mongoDbOptions = {
42 | useMongoClient: true,
43 | };
44 | mongoose.connect("mongodb://localhost/test", mongoDbOptions);
45 | }
46 | else {
47 | mongoose.connect(mongoDbUrl, mongoDbOptions);
48 | }
49 |
50 | app.use(require("body-parser").json());
51 | app.use(cors());
52 |
53 | app.use(express.static(__dirname + "/public"));
54 |
55 | app.use("/leaderboard", leaderboardRoute);
56 |
57 | let port = process.env.PORT || 8080;
58 | app.listen(port, function() {
59 | console.log("To view your app, open this link in your browser: http://localhost:" + port);
60 | });
61 |
62 | module.exports = app;
63 |
--------------------------------------------------------------------------------
/containers/leaderboard/models/registeree.js:
--------------------------------------------------------------------------------
1 | const mongoose = require("mongoose");
2 |
3 | // eslint-disable-next-line
4 | let registereeSchema = mongoose.Schema({
5 | registereeId: {type: String, unique: true},
6 | calories: Number,
7 | steps: {type: Number, required: true},
8 | name: String,
9 | png: String
10 | });
11 |
12 | module.exports = mongoose.model("Registeree", registereeSchema);
13 |
--------------------------------------------------------------------------------
/containers/leaderboard/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "fitcoin-android",
3 | "main": "app.js",
4 | "description": "fitcoin-android",
5 | "version": "1.0.0",
6 | "private": false,
7 | "engines": {
8 | "node": "8.*"
9 | },
10 | "repository": {
11 | "type": "git",
12 | "url": "https://github.com/AnthonyAmanse/fitcoin-android"
13 | },
14 | "dependencies": {
15 | "assert": "^1.4.x",
16 | "body-parser": "^1.17.x",
17 | "cors": "^2.8.x",
18 | "express": "^4.15.x",
19 | "fs": "~0.0.1",
20 | "mongoose": "^5.3.x",
21 | "router": "^1.3.2"
22 | },
23 | "author": "Anthony Amanse",
24 | "license": "Apache-2.0"
25 | }
26 |
--------------------------------------------------------------------------------
/containers/leaderboard/routes/leaderboard.js:
--------------------------------------------------------------------------------
1 | const express = require("express");
2 | const router = express.Router();
3 |
4 | const Registerees = require("../models/registeree");
5 |
6 | // endpoints for registeree
7 | router.get("/all", function(req, res) {
8 | Registerees.find({}, 'registereeId name steps -_id', {sort:{steps:-1}},function(err, registerees) {
9 | if (err) {
10 | res.send(err);
11 | }
12 | else {
13 | res.send(registerees);
14 | }
15 | });
16 | });
17 |
18 | router.get("/top/:number", function(req, res) {
19 | Registerees.find({}, 'registereeId name steps png -_id',{limit:parseInt(req.params.number),sort:{steps:-1}}, function(err, registerees) {
20 | if (err) {
21 | res.send(err);
22 | }
23 | else {
24 | res.send(registerees);
25 | }
26 | });
27 | });
28 |
29 | router.get("/position/steps/:userSteps", function(req, res) {
30 | Registerees.count({steps:{$gt:parseInt(req.params.userSteps)}}, function(err, position) {
31 | if (err) {
32 | res.send(err);
33 | }
34 | else {
35 | res.send({userPosition: position+1});
36 | }
37 | });
38 | });
39 |
40 | router.get("/position/user/:registereeId", function(req, res) {
41 | Registerees.findOne(req.params, function(err, registeree) {
42 | if (err){
43 | res.send(err);
44 | } else if (registeree) {
45 | Registerees.count({steps:{$gt:parseInt(registeree.steps)}}, function(err, position) {
46 | if (err) {
47 | res.send(err)
48 | } else {
49 | Registerees.count(function(err, count) {
50 | if (err) {
51 | res.send(err);
52 | }
53 | else {
54 | res.send({"userPosition":position+1, "count":count, "steps": registeree.steps});
55 | }
56 | });
57 | }
58 | })
59 | } else {
60 | res.send('Registeree not found...');
61 | }
62 | });
63 | });
64 |
65 | module.exports = router;
66 |
--------------------------------------------------------------------------------
/containers/mobile-assets.yaml:
--------------------------------------------------------------------------------
1 | ---
2 | apiVersion: v1
3 | kind: Service
4 | metadata:
5 | name: mobile-assets
6 | labels:
7 | app: mobile-assets
8 | spec:
9 | ports:
10 | - port: 80
11 | protocol: TCP
12 | targetPort: 8080
13 | type: ClusterIP
14 | selector:
15 | app: mobile-assets
16 | ---
17 | apiVersion: extensions/v1beta1
18 | kind: Deployment
19 | metadata:
20 | name: mobile-assets-deployment
21 | labels:
22 | app: mobile-assets
23 | spec:
24 | strategy:
25 | type: Recreate
26 | template:
27 | metadata:
28 | labels:
29 | app: mobile-assets
30 | spec:
31 | containers:
32 | - image: DOCKERHUB_USERNAME/codepattern-mobile-assets:latest
33 | imagePullPolicy: Always
34 | name: mobile-assets
35 | env:
36 | - name: MONGODB_URL
37 | value: ''
38 | ports:
39 | - containerPort: 8080
40 |
--------------------------------------------------------------------------------
/containers/mobile-assets/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM node:8-alpine
2 |
3 | COPY app.js /
4 | COPY package.json /
5 | COPY routes /routes
6 | COPY models /models
7 | COPY public /public
8 |
9 | RUN npm install
10 |
11 | EXPOSE 8080
12 |
13 | CMD ["node", "app.js"]
14 |
--------------------------------------------------------------------------------
/containers/mobile-assets/app.js:
--------------------------------------------------------------------------------
1 | const express = require("express");
2 | const app = express();
3 | const mongoose = require("mongoose");
4 | const assert = require("assert");
5 | const fs = require("fs");
6 | const cors = require("cors");
7 |
8 | const pagesRoute = require("./routes/pages");
9 |
10 | const mongoDbUrl = process.env.MONGODB_URL;
11 | let ca;
12 | if (process.env.MONGODB_CERT_BASE64) { // if encoded certificate is set in ENV, use it.
13 | ca = new Buffer(process.env.MONGODB_CERT_BASE64, "base64");
14 | } else if (fs.existsSync("/etc/ssl/mongo.cert")) { // if mongo.cert exists, use it
15 | ca = [fs.readFileSync("/etc/ssl/mongo.cert")];
16 | } else if (process.env.UNIT_TEST == "test") { // if a test, don't do anything.
17 | console.log("This is a test. Run a local mongoDB.");
18 | } else {
19 | console.log("No certificate provided!");
20 | }
21 |
22 | let mongoDbOptions = {
23 | mongos: {
24 | useMongoClient: true,
25 | ssl: true,
26 | sslValidate: true,
27 | sslCA: ca,
28 | },
29 | };
30 |
31 | mongoose.connection.on("error", function(err) {
32 | console.log("Mongoose default connection error: " + err);
33 | });
34 |
35 | mongoose.connection.on("open", function(err) {
36 | console.log("CONNECTED...");
37 | assert.equal(null, err);
38 | });
39 |
40 | if (process.env.UNIT_TEST == "test") {
41 | mongoDbOptions = {
42 | useMongoClient: true,
43 | };
44 | mongoose.connect("mongodb://localhost/test", mongoDbOptions);
45 | }
46 | else {
47 | mongoose.connect(mongoDbUrl, mongoDbOptions);
48 | }
49 |
50 | app.use(require("body-parser").json());
51 | app.use(cors());
52 |
53 | app.use(express.static(__dirname + "/public"));
54 |
55 | app.use("/pages", pagesRoute);
56 |
57 | let port = process.env.PORT || 8080;
58 | app.listen(port, function() {
59 | console.log("To view your app, open this link in your browser: http://localhost:" + port);
60 | });
61 |
62 | module.exports = app;
63 |
--------------------------------------------------------------------------------
/containers/mobile-assets/models/page.js:
--------------------------------------------------------------------------------
1 | const mongoose = require("mongoose");
2 |
3 | // eslint-disable-next-line
4 | let pageSchema = mongoose.Schema({
5 | page: {type: Number, unique: true},
6 | title: String,
7 | subtitle: String,
8 | subtext: String,
9 | description: String,
10 | image: String,
11 | imageEncoded: String,
12 | });
13 |
14 | module.exports = mongoose.model("Page", pageSchema);
15 |
--------------------------------------------------------------------------------
/containers/mobile-assets/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "fitcoin-android",
3 | "main": "app.js",
4 | "description": "fitcoin-android",
5 | "version": "1.0.0",
6 | "private": false,
7 | "engines": {
8 | "node": "8.*"
9 | },
10 | "repository": {
11 | "type": "git",
12 | "url": "https://github.com/AnthonyAmanse/fitcoin-android"
13 | },
14 | "dependencies": {
15 | "assert": "^1.4.x",
16 | "body-parser": "^1.17.x",
17 | "cors": "^2.8.x",
18 | "express": "^4.15.x",
19 | "fs": "~0.0.1",
20 | "mongoose": "^5.3.x",
21 | "router": "^1.3.2"
22 | },
23 | "author": "Anthony Amanse",
24 | "license": "Apache-2.0"
25 | }
26 |
--------------------------------------------------------------------------------
/containers/mobile-assets/public/bee_sticker.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IBM/android-kubernetes-blockchain/5d6caeccd1888992f98fdd80eb27f993cd3945a1/containers/mobile-assets/public/bee_sticker.png
--------------------------------------------------------------------------------
/containers/mobile-assets/public/em_sticker.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IBM/android-kubernetes-blockchain/5d6caeccd1888992f98fdd80eb27f993cd3945a1/containers/mobile-assets/public/em_sticker.png
--------------------------------------------------------------------------------
/containers/mobile-assets/public/eye_sticker.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IBM/android-kubernetes-blockchain/5d6caeccd1888992f98fdd80eb27f993cd3945a1/containers/mobile-assets/public/eye_sticker.png
--------------------------------------------------------------------------------
/containers/mobile-assets/routes/pages.js:
--------------------------------------------------------------------------------
1 | const express = require("express");
2 | const router = express.Router();
3 |
4 | const Pages = require("../models/page");
5 |
6 | // endpoints for pages
7 | router.post("/add", function(req, res) {
8 | // JSON in req.body
9 | // Insert input validation
10 | let addPage = new Pages(req.body);
11 | addPage.save(function(err) {
12 | if (err) {
13 | res.send(err);
14 | } else {
15 | res.send("Saved booklet page.");
16 | }
17 | });
18 | });
19 |
20 | router.get("/", function(req, res) {
21 | Pages.find({},{},{sort: { page: 1 }},function(err, pages) {
22 | if (err) {
23 | res.send(err);
24 | } else {
25 | res.send(pages);
26 | }
27 | });
28 | });
29 |
30 | router.get("/:page", function(req, res) {
31 | Pages.findOne({"page": parseInt(req.params.page)}, function(err, page) {
32 | if (err) {
33 | res.send(err);
34 | } else if (page) {
35 | if (req.params.page.split(".").pop() == "png") {
36 | res.contentType("image/png");
37 | res.send(new Buffer(page.imageEncoded, "base64"));
38 | }
39 | else {
40 | res.send(page);
41 | }
42 | } else {
43 | res.send("Page not found...");
44 | }
45 | });
46 | });
47 |
48 | module.exports = router;
49 |
--------------------------------------------------------------------------------
/containers/mongo-cert-secret.yaml:
--------------------------------------------------------------------------------
1 | ---
2 | apiVersion: v1
3 | kind: Secret
4 | metadata:
5 | name: mongodb-cert-secret
6 | type: Opaque
7 | data:
8 | mongo.cert: ''
9 |
--------------------------------------------------------------------------------
/containers/registeree-api.yaml:
--------------------------------------------------------------------------------
1 | ---
2 | apiVersion: v1
3 | kind: Service
4 | metadata:
5 | name: registeree-api
6 | labels:
7 | app: registeree-api
8 | spec:
9 | ports:
10 | - port: 80
11 | protocol: TCP
12 | targetPort: 8080
13 | type: ClusterIP
14 | selector:
15 | app: registeree-api
16 | ---
17 | apiVersion: extensions/v1beta1
18 | kind: Deployment
19 | metadata:
20 | name: registeree-api-deployment
21 | labels:
22 | app: registeree-api
23 | spec:
24 | strategy:
25 | type: Recreate
26 | template:
27 | metadata:
28 | labels:
29 | app: registeree-api
30 | spec:
31 | containers:
32 | - image: DOCKERHUB_USERNAME/codepattern-registeree-api:latest
33 | imagePullPolicy: Always
34 | name: registeree-api
35 | env:
36 | - name: CLOUDFUNCTION_AVATAR
37 | value: 'https://service.us.apiconnect.ibmcloud.com/gws/apigateway/api/0c8f59e1d1d5405e25c88917bb965b2defd073b8ed3b5717183d253c13758c1a/api2/generateAvatar'
38 | - name: MONGODB_URL
39 | value: ''
40 | ports:
41 | - containerPort: 8080
42 |
--------------------------------------------------------------------------------
/containers/registeree-api/.npmrc:
--------------------------------------------------------------------------------
1 | optional=false
2 | package-lock=false
--------------------------------------------------------------------------------
/containers/registeree-api/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM node:8-onbuild
2 |
3 | COPY app.js /
4 | COPY package.json /
5 | COPY public /public
6 | COPY routes /routes
7 | COPY models /models
8 |
9 | RUN npm install
10 | RUN npm rebuild
11 |
12 | EXPOSE 8080
13 |
14 | CMD ["node", "app.js"]
15 |
--------------------------------------------------------------------------------
/containers/registeree-api/app.js:
--------------------------------------------------------------------------------
1 | const express = require("express");
2 | const app = express();
3 | const mongoose = require("mongoose");
4 | const assert = require("assert");
5 | const fs = require("fs");
6 | const cors = require("cors");
7 |
8 | const registereeRoute = require("./routes/registerees");
9 |
10 | const mongoDbUrl = process.env.MONGODB_URL;
11 | let ca;
12 | if (process.env.MONGODB_CERT_BASE64) { // if encoded certificate is set in ENV, use it.
13 | ca = new Buffer(process.env.MONGODB_CERT_BASE64, "base64");
14 | } else if (fs.existsSync("/etc/ssl/mongo.cert")) { // if mongo.cert exists, use it
15 | ca = [fs.readFileSync("/etc/ssl/mongo.cert")];
16 | } else if (process.env.UNIT_TEST == "test") { // if a test, don't do anything.
17 | console.log("This is a test. Run a local mongoDB.");
18 | } else {
19 | console.log("No certificate provided!");
20 | }
21 |
22 | let mongoDbOptions = {
23 | mongos: {
24 | useMongoClient: true,
25 | ssl: true,
26 | sslValidate: true,
27 | sslCA: ca,
28 | },
29 | };
30 |
31 | mongoose.connection.on("error", function(err) {
32 | console.log("Mongoose default connection error: " + err);
33 | });
34 |
35 | mongoose.connection.on("open", function(err) {
36 | console.log("CONNECTED...");
37 | assert.equal(null, err);
38 | });
39 |
40 | if (process.env.UNIT_TEST == "test") {
41 | mongoDbOptions = {
42 | useMongoClient: true,
43 | };
44 | mongoose.connect("mongodb://localhost/test", mongoDbOptions);
45 | }
46 | else {
47 | mongoose.connect(mongoDbUrl, mongoDbOptions);
48 | }
49 |
50 | app.use(require("body-parser").json());
51 | app.use(cors());
52 |
53 | app.use(express.static(__dirname + "/public"));
54 |
55 | app.use("/registerees", registereeRoute);
56 |
57 | let port = process.env.PORT || 8080;
58 | app.listen(port, function() {
59 | console.log("To view your app, open this link in your browser: http://localhost:" + port);
60 | });
61 |
62 | module.exports = app;
63 |
--------------------------------------------------------------------------------
/containers/registeree-api/models/registeree.js:
--------------------------------------------------------------------------------
1 | const mongoose = require("mongoose");
2 |
3 | // eslint-disable-next-line
4 | let registereeSchema = mongoose.Schema({
5 | registereeId: {type: String, unique: true},
6 | calories: Number,
7 | steps: {type: Number, required: true},
8 | name: String,
9 | png: String,
10 | device: String
11 | });
12 |
13 | module.exports = mongoose.model("Registeree", registereeSchema);
14 |
--------------------------------------------------------------------------------
/containers/registeree-api/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "secret-map-dashboard",
3 | "main": "app.js",
4 | "description": "secret-map-dashboard",
5 | "version": "1.0.0",
6 | "private": false,
7 | "engines": {
8 | "node": "6.*"
9 | },
10 | "scripts": {
11 | "start": "node app.js",
12 | "test": "mocha --timeout 600000",
13 | "lint": "eslint ."
14 | },
15 | "repository": {
16 | "type": "git",
17 | "url": "https://github.com/IBM/secret-map-dashboard"
18 | },
19 | "dependencies": {
20 | "assert": "^1.4.x",
21 | "body-parser": "^1.17.x",
22 | "cors": "^2.8.x",
23 | "express": "^4.15.x",
24 | "fs": "~0.0.1",
25 | "mongoose": "^5.3.x",
26 | "request": "^2.85.0",
27 | "router": "^1.3.2",
28 | "svg2png": "^4.1.1"
29 | },
30 | "devDependencies": {
31 | "chai": "^3.5.0",
32 | "chai-http": "^2.0.1",
33 | "eslint": "^4.18.2",
34 | "mocha": "^2.4.5"
35 | },
36 | "author": "Darryl Balderas",
37 | "license": "Apache-2.0"
38 | }
39 |
--------------------------------------------------------------------------------
/containers/registeree-api/public/css/style.css:
--------------------------------------------------------------------------------
1 | input {
2 | display: block;
3 | }
4 |
--------------------------------------------------------------------------------
/containers/registeree-api/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
Main Page
4 |
5 |
6 |
Hello, World!
7 |
Endpoints
8 |
GET
9 |
10 | - /registerees
11 | - /registerees/:registereeId
12 | - /registerees/totalSteps
13 | - /registerees/totalCalories
14 | - /footprints
15 |
16 |
POST
17 |
18 | - /registerees/add
19 | - /footprints/add
20 | - /footprints/remove/:footprintId
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/docs/android-screen.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IBM/android-kubernetes-blockchain/5d6caeccd1888992f98fdd80eb27f993cd3945a1/docs/android-screen.png
--------------------------------------------------------------------------------
/docs/architecture.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IBM/android-kubernetes-blockchain/5d6caeccd1888992f98fdd80eb27f993cd3945a1/docs/architecture.png
--------------------------------------------------------------------------------
/docs/java-files.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IBM/android-kubernetes-blockchain/5d6caeccd1888992f98fdd80eb27f993cd3945a1/docs/java-files.png
--------------------------------------------------------------------------------
/docs/mongo-certificate.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IBM/android-kubernetes-blockchain/5d6caeccd1888992f98fdd80eb27f993cd3945a1/docs/mongo-certificate.png
--------------------------------------------------------------------------------
/docs/mongo-credentials.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IBM/android-kubernetes-blockchain/5d6caeccd1888992f98fdd80eb27f993cd3945a1/docs/mongo-credentials.png
--------------------------------------------------------------------------------
/docs/rabbit-credentials.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IBM/android-kubernetes-blockchain/5d6caeccd1888992f98fdd80eb27f993cd3945a1/docs/rabbit-credentials.png
--------------------------------------------------------------------------------
/docs/redis-credentials.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IBM/android-kubernetes-blockchain/5d6caeccd1888992f98fdd80eb27f993cd3945a1/docs/redis-credentials.png
--------------------------------------------------------------------------------