From 0f6753060f6f06393cf542049b8a224976d26846 Mon Sep 17 00:00:00 2001 From: maksimchepelev Date: Tue, 6 Nov 2018 16:17:05 +0300 Subject: [PATCH 1/4] get fog list params in query --- package.json | 3 +- src/controllers/iofog-controller.js | 8 +-- src/routes/iofog.js | 4 +- ...Controller Testing.postman_collection.json | 49 +++++++++++-------- 4 files changed, 38 insertions(+), 26 deletions(-) diff --git a/package.json b/package.json index 2d32ad068..f3ba2e25d 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,8 @@ "umzug": "^2.1.0", "underscore": "^1.9.1", "winston": "^3.1.0", - "xss-clean": "^0.1.1" + "xss-clean": "^0.1.1", + "qs": "^6.5.2" }, "devDependencies": { "eslint": "^5.6.1" diff --git a/src/controllers/iofog-controller.js b/src/controllers/iofog-controller.js index 99832bc59..a037cbd15 100644 --- a/src/controllers/iofog-controller.js +++ b/src/controllers/iofog-controller.js @@ -14,6 +14,8 @@ const logger = require('../logger'); const AuthDecorator = require('../decorators/authorization-decorator'); const FogService = require('../services/iofog-service'); +const querystring = require('querystring'); +const qs = require('qs'); async function _createFog(req, user) { logger.info("Parameters:" + JSON.stringify(req.body)); @@ -43,9 +45,9 @@ async function _getFog(req, user) { } async function _getFogList(req, user) { - logger.info("Parameters:" + JSON.stringify(req.body)); - const filters = Array.from(req.body); - return await FogService.getFogListWithTransaction(filters, user, false) + logger.info("Parameters:" + JSON.stringify(req.query)); + const query = qs.parse(req.query) + return await FogService.getFogListWithTransaction(query.filters, user, false) } async function _generateProvisioningKey(req, user) { diff --git a/src/routes/iofog.js b/src/routes/iofog.js index 9f987cd3a..2853e97ed 100644 --- a/src/routes/iofog.js +++ b/src/routes/iofog.js @@ -17,7 +17,7 @@ const Errors = require('../helpers/errors'); module.exports = [ { - method: 'post', + method: 'get', path: '/api/v3/iofog-list', middleware: async (req, res) => { const successCode = constants.HTTP_CODE_SUCCESS; @@ -154,7 +154,7 @@ module.exports = [ code: 404, errors: [Errors.NotFoundError] } - ] + ]; const generateFogProvisioningKey = ResponseDecorator.handleErrors(FogController.generateProvisioningKey, successCode, errCodes); const responseObject = await generateFogProvisioningKey(req); diff --git a/tests/Controller Testing.postman_collection.json b/tests/Controller Testing.postman_collection.json index f81b2f80b..05258cdf6 100644 --- a/tests/Controller Testing.postman_collection.json +++ b/tests/Controller Testing.postman_collection.json @@ -1,12 +1,13 @@ { "info": { - "_postman_id": "0c412a3a-7328-4c9e-8919-d2836adccfa1", + "_postman_id": "b585aece-cb86-4f3b-93f3-12552c1c90c5", "name": "Controller Testing", "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" }, "item": [ { "name": "User", + "description": null, "item": [ { "name": "Create user", @@ -509,6 +510,7 @@ }, { "name": "General", + "description": null, "item": [ { "name": "Status", @@ -631,6 +633,7 @@ }, { "name": "Agent", + "description": null, "item": [ { "name": "Create user", @@ -856,7 +859,6 @@ "method": "POST", "header": [ { - "disabled": false, "key": "Content-Type", "value": "application/json" } @@ -906,7 +908,6 @@ "method": "GET", "header": [ { - "disabled": false, "key": "Content-Type", "value": "application/json" }, @@ -954,7 +955,6 @@ "method": "PATCH", "header": [ { - "disabled": false, "key": "Content-Type", "value": "application/json" }, @@ -1008,7 +1008,6 @@ "method": "GET", "header": [ { - "disabled": false, "key": "Content-Type", "value": "application/json" }, @@ -1057,7 +1056,6 @@ "method": "PUT", "header": [ { - "disabled": false, "key": "Content-Type", "value": "application/json" }, @@ -1108,7 +1106,6 @@ "method": "GET", "header": [ { - "disabled": false, "key": "Content-Type", "value": "application/json" }, @@ -1159,7 +1156,6 @@ "method": "GET", "header": [ { - "disabled": false, "key": "Content-Type", "value": "application/json" }, @@ -1211,7 +1207,6 @@ "method": "GET", "header": [ { - "disabled": false, "key": "Content-Type", "value": "application/json" }, @@ -1262,7 +1257,6 @@ "method": "GET", "header": [ { - "disabled": false, "key": "Content-Type", "value": "application/json" }, @@ -1310,7 +1304,6 @@ "method": "GET", "header": [ { - "disabled": false, "key": "Content-Type", "value": "application/json" }, @@ -1361,7 +1354,6 @@ "method": "PUT", "header": [ { - "disabled": false, "key": "Content-Type", "value": "application/json" }, @@ -1412,7 +1404,6 @@ "method": "GET", "header": [ { - "disabled": false, "key": "Content-Type", "value": "application/json" }, @@ -1559,7 +1550,6 @@ "method": "GET", "header": [ { - "disabled": false, "key": "Content-Type", "value": "application/json" }, @@ -1657,7 +1647,6 @@ "method": "DELETE", "header": [ { - "disabled": false, "key": "Content-Type", "value": "application/json" }, @@ -1735,6 +1724,7 @@ }, { "name": "Flow", + "description": null, "item": [ { "name": "Create user", @@ -2121,6 +2111,7 @@ }, { "name": "Catalog", + "description": null, "item": [ { "name": "Create user", @@ -2516,6 +2507,7 @@ }, { "name": "Tunnel", + "description": null, "item": [ { "name": "Create user", @@ -2859,6 +2851,7 @@ }, { "name": "Microservices", + "description": null, "item": [ { "name": "Create user", @@ -3795,6 +3788,7 @@ }, { "name": "Diagnostics", + "description": null, "item": [ { "name": "Create user", @@ -4589,6 +4583,7 @@ }, { "name": "ioFog", + "description": null, "item": [ { "name": "Create user", @@ -4809,7 +4804,7 @@ } ], "request": { - "method": "POST", + "method": "GET", "header": [ { "key": "Content-Type", @@ -4817,16 +4812,15 @@ }, { "key": "Authorization", - "value": "{{user-token}}", - "type": "text" + "value": "{{user-token}}" } ], "body": { "mode": "raw", - "raw": "[\n {\n \"key\": \"uuid\",\n \"value\": \"{{node-id}}\",\n \"condition\": \"equals\"\n }\n]" + "raw": "" }, "url": { - "raw": "{{host}}/api/v3/iofog-list", + "raw": "{{host}}/api/v3/iofog-list?filters[0][key]=uuid&filters[0][value]={{node-id}}&filters[0][condition]=equals", "host": [ "{{host}}" ], @@ -4834,6 +4828,20 @@ "api", "v3", "iofog-list" + ], + "query": [ + { + "key": "filters[0][key]", + "value": "uuid" + }, + { + "key": "filters[0][value]", + "value": "{{node-id}}" + }, + { + "key": "filters[0][condition]", + "value": "equals" + } ] } }, @@ -5282,6 +5290,7 @@ }, { "name": "Registries", + "description": null, "item": [ { "name": "Create user", From 59e79dfea320bb7fdfd38479f96b937cb032dca5 Mon Sep 17 00:00:00 2001 From: maksimchepelev Date: Thu, 8 Nov 2018 12:29:03 +0300 Subject: [PATCH 2/4] preisntall and postinstal scripts --- package.json | 2 ++ scripts/postinstall.sh | 14 ++++++++++++++ scripts/preinstall.sh | 5 +++++ 3 files changed, 21 insertions(+) create mode 100644 scripts/postinstall.sh create mode 100644 scripts/preinstall.sh diff --git a/package.json b/package.json index f3ba2e25d..dbd1392f4 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,8 @@ "start": "NODE_ENV=production node ./src/main.js start", "start-dev": "NODE_ENV=development node ./src/main.js start", "build": "export NODE_ENV=production && cd src/sequelize && ../../node_modules/.bin/sequelize db:migrate && ../../node_modules/.bin/sequelize db:seed:all", + "preinstall": "bash scripts/preinstall.sh", + "postinstall": "bash scripts/postinstall.sh", "lint": "./node_modules/.bin/eslint \"**/*.js\"" }, "preferGlobal": true, diff --git a/scripts/postinstall.sh b/scripts/postinstall.sh new file mode 100644 index 000000000..f22769e82 --- /dev/null +++ b/scripts/postinstall.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +PREV_IOFOG_CONTROLLER_VER=$(grep prev_ver scripts/temp/variables | awk '{print $2}') + +echo ${PREV_IOFOG_CONTROLLER_VER} +if [[ "$PREV_IOFOG_CONTROLLER_VER" = "1.0.0" ]]; then + echo "Upgrading from ver 1.0.0" + sqlite3 src/sequelize/prod_database.sqlite "insert into SequelizeMeta (name) values ('20180928110125-insert-registry.js');" + sqlite3 src/sequelize/prod_database.sqlite "insert into SequelizeMeta (name) values ('20180928111532-insert-catalog-item.js');" + sqlite3 src/sequelize/prod_database.sqlite "insert into SequelizeMeta (name) values ('20180928112152-insert-iofog-type.js');" + sqlite3 src/sequelize/prod_database.sqlite "insert into SequelizeMeta (name) values ('20180928121334-insert-catalog-item-image.js');" +fi + +rm -rf scripts/temp \ No newline at end of file diff --git a/scripts/preinstall.sh b/scripts/preinstall.sh new file mode 100644 index 000000000..acae14ca6 --- /dev/null +++ b/scripts/preinstall.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +mkdir scripts/temp +export PREV_IOFOG_CONTROLLER_VER=$(npm list --depth=0 -g --silent | grep iofogcontroller | awk -F "@" '{print $2}') +printf 'prev_ver: '$PREV_IOFOG_CONTROLLER_VER > scripts/temp/variables \ No newline at end of file From e07abe5b81a8ef7cc84f4f4fee310df921fab6d4 Mon Sep 17 00:00:00 2001 From: maksimchepelev Date: Thu, 8 Nov 2018 12:35:42 +0300 Subject: [PATCH 3/4] merge cleanup --- ...Controller Testing.postman_collection.json | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/tests/Controller Testing.postman_collection.json b/tests/Controller Testing.postman_collection.json index 6a6fe0b9e..da25bb98c 100644 --- a/tests/Controller Testing.postman_collection.json +++ b/tests/Controller Testing.postman_collection.json @@ -1,13 +1,12 @@ { "info": { - "_postman_id": "b585aece-cb86-4f3b-93f3-12552c1c90c5", + "_postman_id": "0c412a3a-7328-4c9e-8919-d2836adccfa1", "name": "Controller Testing", "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" }, "item": [ { "name": "User", - "description": null, "item": [ { "name": "Create user", @@ -510,7 +509,6 @@ }, { "name": "General", - "description": null, "item": [ { "name": "Status", @@ -633,7 +631,6 @@ }, { "name": "Agent", - "description": null, "item": [ { "name": "Create user", @@ -859,6 +856,7 @@ "method": "POST", "header": [ { + "disabled": false, "key": "Content-Type", "value": "application/json" } @@ -908,6 +906,7 @@ "method": "GET", "header": [ { + "disabled": false, "key": "Content-Type", "value": "application/json" }, @@ -955,6 +954,7 @@ "method": "PATCH", "header": [ { + "disabled": false, "key": "Content-Type", "value": "application/json" }, @@ -1008,6 +1008,7 @@ "method": "GET", "header": [ { + "disabled": false, "key": "Content-Type", "value": "application/json" }, @@ -1056,6 +1057,7 @@ "method": "PUT", "header": [ { + "disabled": false, "key": "Content-Type", "value": "application/json" }, @@ -1106,6 +1108,7 @@ "method": "GET", "header": [ { + "disabled": false, "key": "Content-Type", "value": "application/json" }, @@ -1156,6 +1159,7 @@ "method": "GET", "header": [ { + "disabled": false, "key": "Content-Type", "value": "application/json" }, @@ -1207,6 +1211,7 @@ "method": "GET", "header": [ { + "disabled": false, "key": "Content-Type", "value": "application/json" }, @@ -1257,6 +1262,7 @@ "method": "GET", "header": [ { + "disabled": false, "key": "Content-Type", "value": "application/json" }, @@ -1304,6 +1310,7 @@ "method": "GET", "header": [ { + "disabled": false, "key": "Content-Type", "value": "application/json" }, @@ -1354,6 +1361,7 @@ "method": "PUT", "header": [ { + "disabled": false, "key": "Content-Type", "value": "application/json" }, @@ -1404,6 +1412,7 @@ "method": "GET", "header": [ { + "disabled": false, "key": "Content-Type", "value": "application/json" }, @@ -1550,6 +1559,7 @@ "method": "GET", "header": [ { + "disabled": false, "key": "Content-Type", "value": "application/json" }, @@ -1647,6 +1657,7 @@ "method": "DELETE", "header": [ { + "disabled": false, "key": "Content-Type", "value": "application/json" }, @@ -1724,7 +1735,6 @@ }, { "name": "Flow", - "description": null, "item": [ { "name": "Create user", @@ -2111,7 +2121,6 @@ }, { "name": "Catalog", - "description": null, "item": [ { "name": "Create user", @@ -2507,7 +2516,6 @@ }, { "name": "Tunnel", - "description": null, "item": [ { "name": "Create user", @@ -2851,7 +2859,6 @@ }, { "name": "Microservices", - "description": null, "item": [ { "name": "Create user", @@ -3788,7 +3795,6 @@ }, { "name": "Diagnostics", - "description": null, "item": [ { "name": "Create user", @@ -4587,7 +4593,6 @@ }, { "name": "ioFog", - "description": null, "item": [ { "name": "Create user", @@ -5294,7 +5299,6 @@ }, { "name": "Registries", - "description": null, "item": [ { "name": "Create user", From 0d9245be648664489f6dbe48c03024c724c3e4fd Mon Sep 17 00:00:00 2001 From: maksimchepelev Date: Thu, 8 Nov 2018 16:22:18 +0300 Subject: [PATCH 4/4] vars to /tmp folder correct comparison of versions --- scripts/postinstall.sh | 61 +++++++++++++++++++++++++++++++++++------- scripts/preinstall.sh | 3 +-- 2 files changed, 52 insertions(+), 12 deletions(-) diff --git a/scripts/postinstall.sh b/scripts/postinstall.sh index f22769e82..93412a368 100644 --- a/scripts/postinstall.sh +++ b/scripts/postinstall.sh @@ -1,14 +1,55 @@ #!/bin/bash -PREV_IOFOG_CONTROLLER_VER=$(grep prev_ver scripts/temp/variables | awk '{print $2}') - -echo ${PREV_IOFOG_CONTROLLER_VER} -if [[ "$PREV_IOFOG_CONTROLLER_VER" = "1.0.0" ]]; then - echo "Upgrading from ver 1.0.0" - sqlite3 src/sequelize/prod_database.sqlite "insert into SequelizeMeta (name) values ('20180928110125-insert-registry.js');" - sqlite3 src/sequelize/prod_database.sqlite "insert into SequelizeMeta (name) values ('20180928111532-insert-catalog-item.js');" - sqlite3 src/sequelize/prod_database.sqlite "insert into SequelizeMeta (name) values ('20180928112152-insert-iofog-type.js');" - sqlite3 src/sequelize/prod_database.sqlite "insert into SequelizeMeta (name) values ('20180928121334-insert-catalog-item-image.js');" +vercomp () { + if [[ $1 == $2 ]] + then + echo '=' + return + fi + local IFS=. + local i ver1=($1) ver2=($2) + # fill empty fields in ver1 with zeros + for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)) + do + ver1[i]=0 + done + for ((i=0; i<${#ver1[@]}; i++)) + do + if [[ -z ${ver2[i]} ]] + then + # fill empty fields in ver2 with zeros + ver2[i]=0 + fi + if ((10#${ver1[i]} > 10#${ver2[i]})) + then + echo '>' + return + fi + if ((10#${ver1[i]} < 10#${ver2[i]})) + then + echo '<' + return + fi + done + echo '=' + return +} + +PREV_IOFOG_CONTROLLER_VER=$(grep prev_ver /tmp/iofogcontroller_install_variables | awk '{print $2}') +echo "Prev ver: "${PREV_IOFOG_CONTROLLER_VER} + +if [[ -z "${PREV_IOFOG_CONTROLLER_VER// }" ]] +then + echo "No prev ver" +else + if [[ $(vercomp $PREV_IOFOG_CONTROLLER_VER 1.0.0) = '<' ]] || [[ $(vercomp $PREV_IOFOG_CONTROLLER_VER 1.0.0) = '=' ]] + then + echo "Upgrading from ver 1.0.0" + sqlite3 src/sequelize/prod_database.sqlite "insert into SequelizeMeta (name) values ('20180928110125-insert-registry.js');" + sqlite3 src/sequelize/prod_database.sqlite "insert into SequelizeMeta (name) values ('20180928111532-insert-catalog-item.js');" + sqlite3 src/sequelize/prod_database.sqlite "insert into SequelizeMeta (name) values ('20180928112152-insert-iofog-type.js');" + sqlite3 src/sequelize/prod_database.sqlite "insert into SequelizeMeta (name) values ('20180928121334-insert-catalog-item-image.js');" + fi fi -rm -rf scripts/temp \ No newline at end of file +rm -rf /tmp/iofogcontroller_install_variables \ No newline at end of file diff --git a/scripts/preinstall.sh b/scripts/preinstall.sh index acae14ca6..412b9e280 100644 --- a/scripts/preinstall.sh +++ b/scripts/preinstall.sh @@ -1,5 +1,4 @@ #!/bin/bash -mkdir scripts/temp export PREV_IOFOG_CONTROLLER_VER=$(npm list --depth=0 -g --silent | grep iofogcontroller | awk -F "@" '{print $2}') -printf 'prev_ver: '$PREV_IOFOG_CONTROLLER_VER > scripts/temp/variables \ No newline at end of file +printf 'prev_ver: '$PREV_IOFOG_CONTROLLER_VER > /tmp/iofogcontroller_install_variables \ No newline at end of file