scripts to set CS public or delete CS
authorJakob <jakob-ingenfeld@gmx.de>
Wed, 20 Jan 2021 15:36:23 +0000 (16:36 +0100)
committerJakob <jakob-ingenfeld@gmx.de>
Wed, 20 Jan 2021 15:36:23 +0000 (16:36 +0100)
.gitignore
package-lock.json
package.json
src/scripts/deleteChargingStations.ts [new file with mode: 0644]
src/scripts/scriptConfig-template.json [new file with mode: 0644]
src/scripts/setCSPublicFlag.ts [new file with mode: 0644]

index 2b4ebbd73117cb2c27b7b62ab3bfac0a7ca9449f..3a622e5d9846860203ea9f46b6870000015570fa 100644 (file)
@@ -86,3 +86,4 @@ Thumbs.db
 # MTA
 *.mta
 mta_archives/
+src/scripts/scriptConfig.json
index 209b0e9a33753995caf7d55e30254edda297dc4d..c5dd1f8650e2ee68f42874e82b6eca0385743a85 100644 (file)
       "integrity": "sha1-DGwfq+KyPRcXPZpht7cJPrnhdp4=",
       "dev": true
     },
+    "bl": {
+      "version": "2.2.1",
+      "resolved": "https://registry.npmjs.org/bl/-/bl-2.2.1.tgz",
+      "integrity": "sha512-6Pesp1w0DEX1N550i/uGV/TqucVL4AM/pgThFSN/Qq9si1/DF9aIHs1BxD8V/QU0HoeHO6cQRTAuYnLPKq1e4g==",
+      "requires": {
+        "readable-stream": "^2.3.5",
+        "safe-buffer": "^5.1.1"
+      }
+    },
     "bluebird": {
       "version": "3.7.2",
       "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz",
         "pako": "~1.0.5"
       }
     },
+    "bson": {
+      "version": "1.1.5",
+      "resolved": "https://registry.npmjs.org/bson/-/bson-1.1.5.tgz",
+      "integrity": "sha512-kDuEzldR21lHciPQAIulLs1LZlCXdLziXI6Mb/TDkwXhb//UORJNPXgcRs2CuO4H0DcMkpfT3/ySsP3unoZjBg=="
+    },
     "buffer": {
       "version": "5.2.1",
       "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.2.1.tgz",
       "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=",
       "dev": true
     },
+    "denque": {
+      "version": "1.5.0",
+      "resolved": "https://registry.npmjs.org/denque/-/denque-1.5.0.tgz",
+      "integrity": "sha512-CYiCSgIF1p6EUByQPlGkKnP1M9g0ZV3qMIrqMqZqdwazygIA/YP2vrbcyl1h/WppKJTdl1F85cXIle+394iDAQ=="
+    },
     "depcheck": {
       "version": "0.8.3",
       "resolved": "https://registry.npmjs.org/depcheck/-/depcheck-0.8.3.tgz",
         "safe-buffer": "^5.1.2"
       }
     },
+    "memory-pager": {
+      "version": "1.5.0",
+      "resolved": "https://registry.npmjs.org/memory-pager/-/memory-pager-1.5.0.tgz",
+      "integrity": "sha512-ZS4Bp4r/Zoeq6+NLJpP+0Zzm0pR8whtGPf1XExKLJBAczGMnSi3It14OiNCStjQjM6NU1okjQGSxgEZN8eBYKg==",
+      "optional": true
+    },
     "meow": {
       "version": "3.7.0",
       "resolved": "https://registry.npmjs.org/meow/-/meow-3.7.0.tgz",
       "resolved": "https://registry.npmjs.org/moment/-/moment-2.29.1.tgz",
       "integrity": "sha512-kHmoybcPV8Sqy59DwNDY3Jefr64lK/by/da0ViFcuA4DH0vQg5Q6Ze5VimxkfQNSC+Mls/Kx53s7TjP1RhFEDQ=="
     },
+    "mongodb": {
+      "version": "3.6.3",
+      "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.6.3.tgz",
+      "integrity": "sha512-rOZuR0QkodZiM+UbQE5kDsJykBqWi0CL4Ec2i1nrGrUI3KO11r6Fbxskqmq3JK2NH7aW4dcccBuUujAP0ERl5w==",
+      "requires": {
+        "bl": "^2.2.1",
+        "bson": "^1.1.4",
+        "denque": "^1.4.1",
+        "require_optional": "^1.0.1",
+        "safe-buffer": "^5.1.2",
+        "saslprep": "^1.0.0"
+      }
+    },
     "morphdom": {
       "version": "2.6.1",
       "resolved": "https://registry.npmjs.org/morphdom/-/morphdom-2.6.1.tgz",
       "version": "2.3.6",
       "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz",
       "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==",
-      "dev": true,
       "requires": {
         "core-util-is": "~1.0.0",
         "inherits": "~2.0.3",
       "integrity": "sha1-wR6XJ2tluOKSP3Xav1+y7ww4Qbk=",
       "dev": true
     },
+    "require_optional": {
+      "version": "1.0.1",
+      "resolved": "https://registry.npmjs.org/require_optional/-/require_optional-1.0.1.tgz",
+      "integrity": "sha512-qhM/y57enGWHAe3v/NcwML6a3/vfESLe/sGM2dII+gEO0BpKRUkWZow/tyloNqJyN6kXSl3RyyM8Ll5D/sJP8g==",
+      "requires": {
+        "resolve-from": "^2.0.0",
+        "semver": "^5.1.0"
+      },
+      "dependencies": {
+        "resolve-from": {
+          "version": "2.0.0",
+          "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-2.0.0.tgz",
+          "integrity": "sha1-lICrIOlP+h2egKgEx+oUdhGWa1c="
+        }
+      }
+    },
     "resolve": {
       "version": "1.10.0",
       "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.10.0.tgz",
       "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==",
       "dev": true
     },
+    "saslprep": {
+      "version": "1.0.3",
+      "resolved": "https://registry.npmjs.org/saslprep/-/saslprep-1.0.3.tgz",
+      "integrity": "sha512-/MY/PEMbk2SuY5sScONwhUDsV2p77Znkb/q3nSVstq/yQzYJOH/Azh29p9oJLsl3LnQwSvZDKagDGBsBwSooag==",
+      "optional": true,
+      "requires": {
+        "sparse-bitfield": "^3.0.3"
+      }
+    },
     "sax": {
       "version": "1.2.4",
       "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz",
     "semver": {
       "version": "5.6.0",
       "resolved": "https://registry.npmjs.org/semver/-/semver-5.6.0.tgz",
-      "integrity": "sha512-RS9R6R35NYgQn++fkDWaOmqGoj4Ek9gGs+DPxNUZKuwE183xjJroKvyo1IzVFeXvUrvmALy6FWD5xrdJT25gMg==",
-      "dev": true
+      "integrity": "sha512-RS9R6R35NYgQn++fkDWaOmqGoj4Ek9gGs+DPxNUZKuwE183xjJroKvyo1IzVFeXvUrvmALy6FWD5xrdJT25gMg=="
     },
     "semver-compare": {
       "version": "1.0.0",
       "integrity": "sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA==",
       "dev": true
     },
+    "sparse-bitfield": {
+      "version": "3.0.3",
+      "resolved": "https://registry.npmjs.org/sparse-bitfield/-/sparse-bitfield-3.0.3.tgz",
+      "integrity": "sha1-/0rm5oZWBWuks+eSqzM004JzyhE=",
+      "optional": true,
+      "requires": {
+        "memory-pager": "^1.0.2"
+      }
+    },
     "spdx-correct": {
       "version": "3.1.0",
       "resolved": "https://registry.npmjs.org/spdx-correct/-/spdx-correct-3.1.0.tgz",
index b2605fb125566d0a257516e47c38e37678b54aca..9274de943c7b6b4581c427b24fdedf485b0ec568 100644 (file)
@@ -45,6 +45,7 @@
     "git:spush": "git push --recurse-submodules=on-demand"
   },
   "dependencies": {
+    "mongodb": "^3.6.3",
     "source-map-support": "^0.5.19",
     "tslib": "^2.1.0",
     "uuid": "^8.3.2",
diff --git a/src/scripts/deleteChargingStations.ts b/src/scripts/deleteChargingStations.ts
new file mode 100644 (file)
index 0000000..db07c6c
--- /dev/null
@@ -0,0 +1,29 @@
+var MongoClient = require('mongodb');
+var fs = require('fs');
+
+// This script deletes charging stations
+// Filter charging stations by id pattern
+
+// Use Case: ev-simulator creates thousands of charging stations, which are not longer needed.
+// Delete these charging stations all at once
+
+// Config
+var config = JSON.parse(fs.readFileSync('scriptConfig.json', 'utf8'));
+
+// Mongo Connection and Query
+if (config && config.mongoConnectionString) {
+  MongoClient.connect(config.mongoConnectionString, {
+    useUnifiedTopology: true,
+    useNewUrlParser: true
+    }, async function(err, client) {
+    const db = client.db('evse');
+
+    for await (const tenantID of config.tenantIDs) {
+      let response = await db.collection(tenantID + '.chargingstations').deleteMany(
+        { _id: {'$regex': config.idPattern} }
+      );
+      console.log(response.deletedCount, `Charging Stations with id = %${config.idPattern}% deleted. TenantID =`, tenantID);
+    }
+    client.close();
+  });
+}
diff --git a/src/scripts/scriptConfig-template.json b/src/scripts/scriptConfig-template.json
new file mode 100644 (file)
index 0000000..fb911ff
--- /dev/null
@@ -0,0 +1,6 @@
+{
+  "publicFlag": true,
+  "tenantIDs": [""],
+  "idPattern": "",
+  "mongoConnectionString": "mongodb://..."
+}
diff --git a/src/scripts/setCSPublicFlag.ts b/src/scripts/setCSPublicFlag.ts
new file mode 100644 (file)
index 0000000..2bc6b7e
--- /dev/null
@@ -0,0 +1,31 @@
+var MongoClient = require('mongodb');
+var fs = require('fs');
+
+// This script sets charging stations public or private
+// Filter charging stations by id pattern
+
+// Use case: simulate charging station for roaming tests
+// charging stations are private by default
+// set public = true
+
+// Config
+var config = JSON.parse(fs.readFileSync('scriptConfig.json', 'utf8'));
+
+// Mongo Connection and Query
+if (config && config.mongoConnectionString) {
+  MongoClient.connect(config.mongoConnectionString, {
+    useUnifiedTopology: true,
+    useNewUrlParser: true
+    }, async function(err, client) {
+    const db = client.db('evse');
+
+    for await (const tenantID of config.tenantIDs) {
+      let response = await db.collection(tenantID + '.chargingstations').updateMany(
+        { _id: {'$regex': config.idPattern} },
+        { $set: { public : config.publicFlag } }
+      );
+      console.log(response.modifiedCount, `Charging Stations with id = %${config.idPattern}% updated. TenantID =`, tenantID);
+    }
+    client.close();
+  });
+}