un-cli 0.0.68 → 0.0.69
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cmd.txt +1 -1
- package/index.mjs +67 -61
- package/package.json +1 -1
package/cmd.txt
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
export subnetworks --all
|
|
2
2
|
exit
|
package/index.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import { AdminLog } from "./adminlog.mjs"
|
|
|
7
7
|
import { logger } from "./logger.mjs"
|
|
8
8
|
import fetch from "node-fetch"
|
|
9
9
|
//update version
|
|
10
|
-
let version = "0.0.
|
|
10
|
+
let version = "0.0.69";
|
|
11
11
|
const GENERATE_TOKEN_TIME_MIN = 30;
|
|
12
12
|
|
|
13
13
|
let rl = null;
|
|
@@ -394,8 +394,7 @@ const inputs = {
|
|
|
394
394
|
console.log("Updating Subnetwork " + v(f.attributes,"subnetworkName"));
|
|
395
395
|
|
|
396
396
|
const fromDate = new Date();
|
|
397
|
-
|
|
398
|
-
|
|
397
|
+
|
|
399
398
|
const subnetworkResult = await un.updateSubnetworks(v(f.attributes,"domainNetworkName"), v(f.attributes,"tierName"), v(f.attributes,"subnetworkName"),false);
|
|
400
399
|
|
|
401
400
|
//code
|
|
@@ -410,26 +409,30 @@ const inputs = {
|
|
|
410
409
|
},
|
|
411
410
|
|
|
412
411
|
"^update subnetworks --all$" : async () => {
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
412
|
+
|
|
413
|
+
do {
|
|
414
|
+
console.log("Querying all subnetworks that are dirty.");
|
|
415
|
+
let subnetworks = await un.queryDistinct(500002, "domainnetworkname,tiername,subnetworkname", "isdirty=1", "domainnetworkname,tiername,subnetworkname");
|
|
416
|
+
console.log(`Discovered ${subnetworks.features.length} dirty subnetworks.`);
|
|
417
|
+
|
|
418
|
+
for (let i = 0; i < subnetworks.features.length; i++) {
|
|
419
|
+
const f = subnetworks.features[i]
|
|
420
|
+
console.log("Updating Subnetwork " + v(f.attributes,"subnetworkName"));
|
|
421
|
+
|
|
422
|
+
const fromDate = new Date();
|
|
423
|
+
|
|
424
|
+
const subnetworkResult = await un.updateSubnetworks(v(f.attributes,"domainNetworkName"), v(f.attributes,"tierName"), v(f.attributes,"subnetworkName"),false);
|
|
425
|
+
|
|
426
|
+
const toDate = new Date();
|
|
427
|
+
const timeEnable = toDate.getTime() - fromDate.getTime();
|
|
428
|
+
subnetworkResult.duration = numberWithCommas(Math.round(timeEnable)) + " ms"
|
|
429
|
+
|
|
430
|
+
console.log(`Result ${JSON.stringify(subnetworkResult)}`)
|
|
431
|
+
}
|
|
430
432
|
|
|
431
|
-
|
|
432
|
-
|
|
433
|
+
}
|
|
434
|
+
while (subnetworks.features.length > 0)
|
|
435
|
+
|
|
433
436
|
},
|
|
434
437
|
"^update subnetworks --all --async$" : async () => {
|
|
435
438
|
console.log("Querying all subnetworks that are dirty.");
|
|
@@ -443,8 +446,7 @@ const inputs = {
|
|
|
443
446
|
}
|
|
444
447
|
},
|
|
445
448
|
"^export subnetworks --all --folder .*$|^export subnetworks --all$" : async input => {
|
|
446
|
-
|
|
447
|
-
|
|
449
|
+
|
|
448
450
|
//create folder
|
|
449
451
|
const file = input.match(/--folder .*/gm)
|
|
450
452
|
let inputDir = "Exported"
|
|
@@ -452,45 +454,49 @@ const inputs = {
|
|
|
452
454
|
inputDir = file[0].replace("--folder ", "")
|
|
453
455
|
//create directory if doesn't exists
|
|
454
456
|
if (!fs.existsSync(inputDir)) fs.mkdirSync(inputDir)
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
457
|
+
|
|
458
|
+
do {
|
|
459
|
+
|
|
460
|
+
console.log("Querying all subnetworks that are clean.");
|
|
461
|
+
let subnetworks = await un.queryDistinct(500002, "domainnetworkname,tiername,subnetworkname", "isdirty=0","domainnetworkname,tiername,subnetworkname");
|
|
462
|
+
console.log(`Discovered ${subnetworks.features.length} subnetworks that can be exported.`);
|
|
463
|
+
for (let i = 0; i < subnetworks.features.length; i++) {
|
|
464
|
+
const f = subnetworks.features[i]
|
|
465
|
+
const subnetworkName = v(f.attributes,"subnetworkName")
|
|
466
|
+
console.log("Exporting subnetworks " + v(f.attributes,"subnetworkName"));
|
|
467
|
+
|
|
468
|
+
const fromDate = new Date();
|
|
469
|
+
|
|
470
|
+
const subnetworkResult = await un.exportSubnetworks(v(f.attributes,"domainNetworkName"), v(f.attributes,"tierName"), v(f.attributes,"subnetworkName"),false);
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
//code
|
|
474
|
+
|
|
475
|
+
const toDate = new Date();
|
|
476
|
+
const timeEnable = toDate.getTime() - fromDate.getTime();
|
|
477
|
+
subnetworkResult.duration = numberWithCommas(timeEnable) + " ms"
|
|
478
|
+
//if undefined exit
|
|
479
|
+
if (!subnetworkResult.url)
|
|
480
|
+
{
|
|
481
|
+
console.log("Export subnetwork failed " + JSON.stringify(subnetworkResult))
|
|
482
|
+
continue;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
//fetch the json and write it to disk
|
|
486
|
+
const subContent = await fetch(subnetworkResult.url);
|
|
487
|
+
//check if the response is 200 only then attempt to parse to json
|
|
488
|
+
//although the response is json, its easier to treat it as text (handle error cases) since we will only write it to disk.
|
|
489
|
+
// if we want to do something with the response then make it json
|
|
490
|
+
const jsonExport = await subContent.text();
|
|
491
|
+
fs.writeFileSync(`${inputDir}/${subnetworkName}.json`, jsonExport)
|
|
492
|
+
|
|
493
|
+
|
|
494
|
+
console.log(`Result ${JSON.stringify(subnetworkResult)} written to file ${process.cwd()}/${inputDir}/${subnetworkName}.json`)
|
|
495
|
+
|
|
480
496
|
}
|
|
481
|
-
|
|
482
|
-
//fetch the json and write it to disk
|
|
483
|
-
const subContent = await fetch(subnetworkResult.url);
|
|
484
|
-
//check if the response is 200 only then attempt to parse to json
|
|
485
|
-
//although the response is json, its easier to treat it as text (handle error cases) since we will only write it to disk.
|
|
486
|
-
// if we want to do something with the response then make it json
|
|
487
|
-
const jsonExport = await subContent.text();
|
|
488
|
-
fs.writeFileSync(`${inputDir}/${subnetworkName}.json`, jsonExport)
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
console.log(`Result ${JSON.stringify(subnetworkResult)} written to file ${process.cwd()}/${inputDir}/${subnetworkName}.json`)
|
|
492
|
-
|
|
493
497
|
}
|
|
498
|
+
while (subnetworks.features.length > 0)
|
|
499
|
+
|
|
494
500
|
},
|
|
495
501
|
|
|
496
502
|
|