node-opcua-samples 2.64.1 → 2.66.0
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/bin/server_with_push_certificate.ts +1 -1
- package/bin/simple_client.js +1 -1
- package/bin/simple_client_ts.ts +28 -31
- package/bin/simple_server_with_custom_extension_objects.ts +1 -1
- package/dist/get_endpoints.d.ts +2 -2
- package/dist/get_endpoints.js +141 -141
- package/dist/mini_server.d.ts +1 -1
- package/dist/mini_server.js +88 -88
- package/dist/server_with_push_certificate.d.ts +2 -2
- package/dist/server_with_push_certificate.js +82 -82
- package/dist/server_with_push_certificate.js.map +1 -1
- package/dist/simple_client_ts.d.ts +2 -2
- package/dist/simple_client_ts.js +660 -663
- package/dist/simple_client_ts.js.map +1 -1
- package/dist/simple_findservers.d.ts +2 -2
- package/dist/simple_findservers.js +48 -48
- package/dist/simple_secure_server.d.ts +2 -2
- package/dist/simple_secure_server.js +121 -121
- package/dist/simple_server_with_custom_extension_objects.d.ts +2 -2
- package/dist/simple_server_with_custom_extension_objects.js +81 -81
- package/dist/simple_server_with_custom_extension_objects.js.map +1 -1
- package/dist/stressing_client.d.ts +1 -1
- package/dist/stressing_client.js +36 -36
- package/package.json +8 -8
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env ts-node
|
|
2
2
|
/* eslint no-process-exit: 0 */
|
|
3
3
|
// tslint:disable:no-console
|
|
4
|
+
import * as path from "path";
|
|
4
5
|
import * as chalk from "chalk";
|
|
5
6
|
|
|
6
7
|
import { nodesets, OPCUACertificateManager, OPCUAServer } from "node-opcua";
|
|
7
8
|
import { CertificateManager } from "node-opcua-pki";
|
|
8
9
|
import { installPushCertificateManagement } from "node-opcua-server-configuration";
|
|
9
|
-
import * as path from "path";
|
|
10
10
|
import * as yargs from "yargs";
|
|
11
11
|
|
|
12
12
|
const rootFolder = path.join(__dirname, "../../..");
|
package/bin/simple_client.js
CHANGED
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
// PLEASE use simple_client_ts.ts , simple_client_ts presents a more modern approach...*
|
|
5
5
|
const fs = require("fs");
|
|
6
6
|
const path = require("path");
|
|
7
|
+
const util = require("util");
|
|
7
8
|
const treeify = require("treeify");
|
|
8
9
|
const chalk = require("chalk");
|
|
9
10
|
const Table = require("easy-table");
|
|
10
|
-
const util = require("util");
|
|
11
11
|
const {
|
|
12
12
|
ApplicationType,
|
|
13
13
|
assert,
|
package/bin/simple_client_ts.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env ts-node
|
|
2
|
+
/* eslint-disable complexity */
|
|
3
|
+
/* eslint-disable max-statements */
|
|
2
4
|
// tslint:disable:no-console
|
|
3
|
-
import * as chalk from "chalk";
|
|
4
5
|
import * as fs from "fs";
|
|
5
6
|
import * as path from "path";
|
|
6
7
|
import * as util from "util";
|
|
7
8
|
import * as yargs from "yargs";
|
|
9
|
+
import * as chalk from "chalk";
|
|
8
10
|
|
|
9
11
|
import {
|
|
10
12
|
ApplicationType,
|
|
@@ -108,7 +110,7 @@ async function enumerateAllAlarmAndConditionInstances(session: ClientSession): P
|
|
|
108
110
|
const found: any = [];
|
|
109
111
|
|
|
110
112
|
function isConditionEventType(nodeId: NodeId): boolean {
|
|
111
|
-
return
|
|
113
|
+
return Object.prototype.hasOwnProperty.call(conditions, nodeId.toString());
|
|
112
114
|
}
|
|
113
115
|
|
|
114
116
|
async function exploreForObjectOfType(session1: ClientSession, nodeId: NodeId) {
|
|
@@ -197,7 +199,7 @@ function getTick() {
|
|
|
197
199
|
return Date.now();
|
|
198
200
|
}
|
|
199
201
|
|
|
200
|
-
let
|
|
202
|
+
let theSubscription: ClientSubscription | null;
|
|
201
203
|
let the_session: ClientSession;
|
|
202
204
|
let client: OPCUAClient;
|
|
203
205
|
|
|
@@ -611,32 +613,32 @@ async function main() {
|
|
|
611
613
|
requestedPublishingInterval: 2000
|
|
612
614
|
};
|
|
613
615
|
|
|
614
|
-
|
|
616
|
+
theSubscription = await the_session.createSubscription2(parameters);
|
|
615
617
|
|
|
616
618
|
let t = getTick();
|
|
617
619
|
|
|
618
|
-
console.log("started subscription :",
|
|
620
|
+
console.log("started subscription :", theSubscription!.subscriptionId);
|
|
619
621
|
console.log(" revised parameters ");
|
|
620
622
|
console.log(
|
|
621
623
|
" revised maxKeepAliveCount ",
|
|
622
|
-
|
|
624
|
+
theSubscription!.maxKeepAliveCount,
|
|
623
625
|
" ( requested ",
|
|
624
626
|
parameters.requestedMaxKeepAliveCount + ")"
|
|
625
627
|
);
|
|
626
628
|
console.log(
|
|
627
629
|
" revised lifetimeCount ",
|
|
628
|
-
|
|
630
|
+
theSubscription!.lifetimeCount,
|
|
629
631
|
" ( requested ",
|
|
630
632
|
parameters.requestedLifetimeCount + ")"
|
|
631
633
|
);
|
|
632
634
|
console.log(
|
|
633
635
|
" revised publishingInterval ",
|
|
634
|
-
|
|
636
|
+
theSubscription!.publishingInterval,
|
|
635
637
|
" ( requested ",
|
|
636
638
|
parameters.requestedPublishingInterval + ")"
|
|
637
639
|
);
|
|
638
640
|
|
|
639
|
-
|
|
641
|
+
theSubscription
|
|
640
642
|
.on("internal_error", (err: Error) => {
|
|
641
643
|
console.log(" received internal error", err.message);
|
|
642
644
|
})
|
|
@@ -649,7 +651,7 @@ async function main() {
|
|
|
649
651
|
span / 1000,
|
|
650
652
|
"sec",
|
|
651
653
|
" pending request on server = ",
|
|
652
|
-
(
|
|
654
|
+
(theSubscription as any).getPublishEngine().nbPendingPublishRequests
|
|
653
655
|
);
|
|
654
656
|
})
|
|
655
657
|
.on("terminated", () => {
|
|
@@ -657,7 +659,7 @@ async function main() {
|
|
|
657
659
|
});
|
|
658
660
|
|
|
659
661
|
try {
|
|
660
|
-
const results1 = await
|
|
662
|
+
const results1 = await theSubscription.getMonitoredItems();
|
|
661
663
|
console.log("MonitoredItems clientHandles", results1.clientHandles);
|
|
662
664
|
console.log("MonitoredItems serverHandles", results1.serverHandles);
|
|
663
665
|
} catch (err) {
|
|
@@ -675,7 +677,7 @@ async function main() {
|
|
|
675
677
|
// ---------------------------------------------------------------
|
|
676
678
|
console.log(" Monitoring node ", monitored_node.toString());
|
|
677
679
|
const monitoredItem = ClientMonitoredItem.create(
|
|
678
|
-
|
|
680
|
+
theSubscription,
|
|
679
681
|
{
|
|
680
682
|
attributeId: AttributeIds.Value,
|
|
681
683
|
nodeId: monitored_node
|
|
@@ -697,7 +699,7 @@ async function main() {
|
|
|
697
699
|
console.log(monitoredItem.itemToMonitor.nodeId.toString(), chalk.red(" ERROR"), err_message);
|
|
698
700
|
});
|
|
699
701
|
|
|
700
|
-
const results = await
|
|
702
|
+
const results = await theSubscription.getMonitoredItems();
|
|
701
703
|
console.log("MonitoredItems clientHandles", results.clientHandles);
|
|
702
704
|
console.log("MonitoredItems serverHandles", results.serverHandles);
|
|
703
705
|
|
|
@@ -752,7 +754,7 @@ async function main() {
|
|
|
752
754
|
const eventFilter = constructEventFilter(fields, [resolveNodeId("ConditionType")]);
|
|
753
755
|
|
|
754
756
|
const event_monitoringItem = ClientMonitoredItem.create(
|
|
755
|
-
|
|
757
|
+
theSubscription,
|
|
756
758
|
{
|
|
757
759
|
attributeId: AttributeIds.EventNotifier,
|
|
758
760
|
nodeId: serverObjectId
|
|
@@ -777,7 +779,7 @@ async function main() {
|
|
|
777
779
|
|
|
778
780
|
console.log("--------------------------------------------- Monitoring alarms");
|
|
779
781
|
const alarmNodeId = coerceNodeId("ns=2;s=1:Colours/EastTank?Green");
|
|
780
|
-
await monitorAlarm(
|
|
782
|
+
await monitorAlarm(theSubscription, alarmNodeId);
|
|
781
783
|
|
|
782
784
|
console.log("Starting timer ", timeout);
|
|
783
785
|
if (timeout > 0) {
|
|
@@ -796,12 +798,12 @@ async function main() {
|
|
|
796
798
|
await new Promise<void>((resolve) => {
|
|
797
799
|
setTimeout(async () => {
|
|
798
800
|
console.log("time out => shutting down ");
|
|
799
|
-
if (!
|
|
801
|
+
if (!theSubscription) {
|
|
800
802
|
return resolve();
|
|
801
803
|
}
|
|
802
|
-
if (
|
|
803
|
-
const s =
|
|
804
|
-
|
|
804
|
+
if (theSubscription) {
|
|
805
|
+
const s = theSubscription;
|
|
806
|
+
theSubscription = null;
|
|
805
807
|
await s.terminate();
|
|
806
808
|
await the_session.close();
|
|
807
809
|
await client.disconnect();
|
|
@@ -824,25 +826,20 @@ async function main() {
|
|
|
824
826
|
console.log("success !! ");
|
|
825
827
|
}
|
|
826
828
|
|
|
827
|
-
|
|
828
|
-
process.on("SIGINT", async () => {
|
|
829
|
+
process.once("SIGINT", async () => {
|
|
829
830
|
console.log(" user interruption ...");
|
|
830
831
|
|
|
831
|
-
|
|
832
|
-
if (user_interruption_count >= 3) {
|
|
833
|
-
process.exit(1);
|
|
834
|
-
}
|
|
835
|
-
if (the_subscription) {
|
|
832
|
+
if (theSubscription) {
|
|
836
833
|
console.log(chalk.red.bold(" Received client interruption from user "));
|
|
837
834
|
console.log(chalk.red.bold(" shutting down ..."));
|
|
838
|
-
const subscription =
|
|
839
|
-
|
|
835
|
+
const subscription = theSubscription;
|
|
836
|
+
theSubscription = null;
|
|
840
837
|
|
|
841
838
|
await subscription.terminate();
|
|
842
|
-
await the_session.close();
|
|
843
|
-
await client.disconnect();
|
|
844
|
-
process.exit(0);
|
|
845
839
|
}
|
|
840
|
+
await the_session.close();
|
|
841
|
+
await client.disconnect();
|
|
842
|
+
process.exit(0);
|
|
846
843
|
});
|
|
847
844
|
|
|
848
845
|
main();
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env ts-node
|
|
2
2
|
/* eslint no-process-exit: 0 */
|
|
3
3
|
// tslint:disable:no-console
|
|
4
|
+
import * as path from "path";
|
|
4
5
|
import * as chalk from "chalk";
|
|
5
6
|
import { nodesets, OPCUAServer } from "node-opcua";
|
|
6
|
-
import * as path from "path";
|
|
7
7
|
import * as yargs from "yargs";
|
|
8
8
|
import { Argv } from "yargs";
|
|
9
9
|
|
package/dist/get_endpoints.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
#!/usr/bin/env ts-node
|
|
2
|
-
export {};
|
|
1
|
+
#!/usr/bin/env ts-node
|
|
2
|
+
export {};
|
package/dist/get_endpoints.js
CHANGED
|
@@ -1,142 +1,142 @@
|
|
|
1
|
-
#!/usr/bin/env ts-node
|
|
2
|
-
"use strict";
|
|
3
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
-
});
|
|
11
|
-
};
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
// tslint:disable:no-console
|
|
14
|
-
const chalk = require("chalk");
|
|
15
|
-
const fs = require("fs");
|
|
16
|
-
const path = require("path");
|
|
17
|
-
const yargs = require("yargs");
|
|
18
|
-
const node_opcua_1 = require("node-opcua");
|
|
19
|
-
const node_opcua_crypto_1 = require("node-opcua-crypto");
|
|
20
|
-
// tslint:disable:no-var-requires
|
|
21
|
-
const Table = require("easy-table");
|
|
22
|
-
const treeify = require("treeify");
|
|
23
|
-
// eslint-disable-next-line max-statements
|
|
24
|
-
function main() {
|
|
25
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
-
// ts-node bin/simple_client.ts --endpoint opc.tcp://localhost:53530/OPCUA/SimulationServer --node "ns=5;s=Sinusoid1"
|
|
27
|
-
const argv = yield yargs(process.argv)
|
|
28
|
-
.wrap(132)
|
|
29
|
-
.option("endpoint", {
|
|
30
|
-
alias: "e",
|
|
31
|
-
demandOption: true,
|
|
32
|
-
describe: "the end point to connect to "
|
|
33
|
-
})
|
|
34
|
-
.option("securityMode", {
|
|
35
|
-
alias: "s",
|
|
36
|
-
default: "None",
|
|
37
|
-
describe: "the security mode ( None Sign SignAndEncrypt )"
|
|
38
|
-
})
|
|
39
|
-
.option("securityPolicy", {
|
|
40
|
-
alias: "P",
|
|
41
|
-
default: "None",
|
|
42
|
-
describe: "the policy mode : (" + Object.keys(node_opcua_1.SecurityPolicy).join(" - ") + ")"
|
|
43
|
-
})
|
|
44
|
-
.option("discovery", {
|
|
45
|
-
alias: "D",
|
|
46
|
-
describe: "specify the endpoint uri of discovery server (by default same as server endpoint uri)"
|
|
47
|
-
})
|
|
48
|
-
.example("get_endpoints --endpoint opc.tcp://localhost:49230", "").argv;
|
|
49
|
-
const securityMode = (0, node_opcua_1.coerceMessageSecurityMode)(argv.securityMode);
|
|
50
|
-
if (securityMode === node_opcua_1.MessageSecurityMode.Invalid) {
|
|
51
|
-
throw new Error("Invalid Security mode");
|
|
52
|
-
}
|
|
53
|
-
const securityPolicy = (0, node_opcua_1.coerceSecurityPolicy)(argv.securityPolicy);
|
|
54
|
-
if (securityPolicy === node_opcua_1.SecurityPolicy.Invalid) {
|
|
55
|
-
throw new Error("Invalid securityPolicy");
|
|
56
|
-
}
|
|
57
|
-
console.log(chalk.cyan("securityMode = "), securityMode.toString());
|
|
58
|
-
console.log(chalk.cyan("securityPolicy = "), securityPolicy.toString());
|
|
59
|
-
const endpointUrl = argv.endpoint;
|
|
60
|
-
if (!endpointUrl) {
|
|
61
|
-
yargs.showHelp();
|
|
62
|
-
process.exit(0);
|
|
63
|
-
}
|
|
64
|
-
const discoveryUrl = argv.discovery ? argv.discovery : endpointUrl;
|
|
65
|
-
const optionsInitial = {
|
|
66
|
-
securityMode,
|
|
67
|
-
securityPolicy,
|
|
68
|
-
endpointMustExist: false,
|
|
69
|
-
connectionStrategy: {
|
|
70
|
-
initialDelay: 2000,
|
|
71
|
-
maxDelay: 10 * 1000,
|
|
72
|
-
maxRetry: 10
|
|
73
|
-
},
|
|
74
|
-
discoveryUrl
|
|
75
|
-
};
|
|
76
|
-
const client = node_opcua_1.OPCUAClient.create(optionsInitial);
|
|
77
|
-
client.on("backoff", (retry, delay) => {
|
|
78
|
-
console.log(chalk.bgWhite.yellow("backoff attempt #"), retry, " retrying in ", delay / 1000.0, " seconds");
|
|
79
|
-
});
|
|
80
|
-
console.log(" connecting to ", chalk.cyan.bold(endpointUrl));
|
|
81
|
-
console.log(" strategy", client.connectionStrategy);
|
|
82
|
-
try {
|
|
83
|
-
yield client.connect(endpointUrl);
|
|
84
|
-
}
|
|
85
|
-
catch (err) {
|
|
86
|
-
console.log(chalk.red(" Cannot connect to ") + endpointUrl);
|
|
87
|
-
if (err instanceof Error) {
|
|
88
|
-
console.log(" Error = ", err.message);
|
|
89
|
-
}
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
const endpoints = yield client.getEndpoints();
|
|
93
|
-
if (argv.debug) {
|
|
94
|
-
fs.writeFileSync("tmp/endpoints.log", JSON.stringify(endpoints, null, " "));
|
|
95
|
-
console.log(treeify.asTree(endpoints, true));
|
|
96
|
-
}
|
|
97
|
-
const table = new Table();
|
|
98
|
-
let serverCertificate;
|
|
99
|
-
let i = 0;
|
|
100
|
-
for (const endpoint of endpoints) {
|
|
101
|
-
table.cell("endpoint", endpoint.endpointUrl + "");
|
|
102
|
-
table.cell("Application URI", endpoint.server.applicationUri);
|
|
103
|
-
table.cell("Product URI", endpoint.server.productUri);
|
|
104
|
-
table.cell("Application Name", endpoint.server.applicationName.text);
|
|
105
|
-
table.cell("securityLevel", endpoint.securityLevel);
|
|
106
|
-
table.cell("Security Mode", chalk.cyan(node_opcua_1.MessageSecurityMode[endpoint.securityMode].toString()));
|
|
107
|
-
table.cell("securityPolicyUri", chalk.cyan(endpoint.securityPolicyUri));
|
|
108
|
-
table.cell("Type", node_opcua_1.ApplicationType[endpoint.server.applicationType]);
|
|
109
|
-
table.cell("certificate", "..." /*endpoint.serverCertificate*/);
|
|
110
|
-
endpoint.server.discoveryUrls = endpoint.server.discoveryUrls || [];
|
|
111
|
-
table.cell("discoveryUrls", endpoint.server.discoveryUrls.join(" - "));
|
|
112
|
-
serverCertificate = endpoint.serverCertificate;
|
|
113
|
-
const certificate_filename = path.join(__dirname, "../certificates/PKI/server_certificate" + i + ".pem");
|
|
114
|
-
if (serverCertificate) {
|
|
115
|
-
fs.writeFile(certificate_filename, (0, node_opcua_crypto_1.toPem)(serverCertificate, "CERTIFICATE"), () => {
|
|
116
|
-
/**/
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
table.newRow();
|
|
120
|
-
i++;
|
|
121
|
-
}
|
|
122
|
-
console.log(table.toString());
|
|
123
|
-
for (const endpoint of endpoints) {
|
|
124
|
-
console.log("Identify Token for : Security Mode=", chalk.cyan(node_opcua_1.MessageSecurityMode[endpoint.securityMode].toString()), " Policy=", chalk.cyan(endpoint.securityPolicyUri));
|
|
125
|
-
const table2 = new Table();
|
|
126
|
-
for (const token of endpoint.userIdentityTokens) {
|
|
127
|
-
table2.cell("policyId", token.policyId);
|
|
128
|
-
table2.cell("tokenType", node_opcua_1.UserTokenType[token.tokenType]);
|
|
129
|
-
table2.cell("issuedTokenType", token.issuedTokenType);
|
|
130
|
-
table2.cell("issuerEndpointUrl", token.issuerEndpointUrl);
|
|
131
|
-
table2.cell("securityPolicyUri", token.securityPolicyUri);
|
|
132
|
-
table2.newRow();
|
|
133
|
-
}
|
|
134
|
-
console.log(table2.toString());
|
|
135
|
-
}
|
|
136
|
-
yield client.disconnect();
|
|
137
|
-
console.log("success !! ");
|
|
138
|
-
process.exit(0);
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
main();
|
|
1
|
+
#!/usr/bin/env ts-node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
// tslint:disable:no-console
|
|
14
|
+
const chalk = require("chalk");
|
|
15
|
+
const fs = require("fs");
|
|
16
|
+
const path = require("path");
|
|
17
|
+
const yargs = require("yargs");
|
|
18
|
+
const node_opcua_1 = require("node-opcua");
|
|
19
|
+
const node_opcua_crypto_1 = require("node-opcua-crypto");
|
|
20
|
+
// tslint:disable:no-var-requires
|
|
21
|
+
const Table = require("easy-table");
|
|
22
|
+
const treeify = require("treeify");
|
|
23
|
+
// eslint-disable-next-line max-statements
|
|
24
|
+
function main() {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
// ts-node bin/simple_client.ts --endpoint opc.tcp://localhost:53530/OPCUA/SimulationServer --node "ns=5;s=Sinusoid1"
|
|
27
|
+
const argv = yield yargs(process.argv)
|
|
28
|
+
.wrap(132)
|
|
29
|
+
.option("endpoint", {
|
|
30
|
+
alias: "e",
|
|
31
|
+
demandOption: true,
|
|
32
|
+
describe: "the end point to connect to "
|
|
33
|
+
})
|
|
34
|
+
.option("securityMode", {
|
|
35
|
+
alias: "s",
|
|
36
|
+
default: "None",
|
|
37
|
+
describe: "the security mode ( None Sign SignAndEncrypt )"
|
|
38
|
+
})
|
|
39
|
+
.option("securityPolicy", {
|
|
40
|
+
alias: "P",
|
|
41
|
+
default: "None",
|
|
42
|
+
describe: "the policy mode : (" + Object.keys(node_opcua_1.SecurityPolicy).join(" - ") + ")"
|
|
43
|
+
})
|
|
44
|
+
.option("discovery", {
|
|
45
|
+
alias: "D",
|
|
46
|
+
describe: "specify the endpoint uri of discovery server (by default same as server endpoint uri)"
|
|
47
|
+
})
|
|
48
|
+
.example("get_endpoints --endpoint opc.tcp://localhost:49230", "").argv;
|
|
49
|
+
const securityMode = (0, node_opcua_1.coerceMessageSecurityMode)(argv.securityMode);
|
|
50
|
+
if (securityMode === node_opcua_1.MessageSecurityMode.Invalid) {
|
|
51
|
+
throw new Error("Invalid Security mode");
|
|
52
|
+
}
|
|
53
|
+
const securityPolicy = (0, node_opcua_1.coerceSecurityPolicy)(argv.securityPolicy);
|
|
54
|
+
if (securityPolicy === node_opcua_1.SecurityPolicy.Invalid) {
|
|
55
|
+
throw new Error("Invalid securityPolicy");
|
|
56
|
+
}
|
|
57
|
+
console.log(chalk.cyan("securityMode = "), securityMode.toString());
|
|
58
|
+
console.log(chalk.cyan("securityPolicy = "), securityPolicy.toString());
|
|
59
|
+
const endpointUrl = argv.endpoint;
|
|
60
|
+
if (!endpointUrl) {
|
|
61
|
+
yargs.showHelp();
|
|
62
|
+
process.exit(0);
|
|
63
|
+
}
|
|
64
|
+
const discoveryUrl = argv.discovery ? argv.discovery : endpointUrl;
|
|
65
|
+
const optionsInitial = {
|
|
66
|
+
securityMode,
|
|
67
|
+
securityPolicy,
|
|
68
|
+
endpointMustExist: false,
|
|
69
|
+
connectionStrategy: {
|
|
70
|
+
initialDelay: 2000,
|
|
71
|
+
maxDelay: 10 * 1000,
|
|
72
|
+
maxRetry: 10
|
|
73
|
+
},
|
|
74
|
+
discoveryUrl
|
|
75
|
+
};
|
|
76
|
+
const client = node_opcua_1.OPCUAClient.create(optionsInitial);
|
|
77
|
+
client.on("backoff", (retry, delay) => {
|
|
78
|
+
console.log(chalk.bgWhite.yellow("backoff attempt #"), retry, " retrying in ", delay / 1000.0, " seconds");
|
|
79
|
+
});
|
|
80
|
+
console.log(" connecting to ", chalk.cyan.bold(endpointUrl));
|
|
81
|
+
console.log(" strategy", client.connectionStrategy);
|
|
82
|
+
try {
|
|
83
|
+
yield client.connect(endpointUrl);
|
|
84
|
+
}
|
|
85
|
+
catch (err) {
|
|
86
|
+
console.log(chalk.red(" Cannot connect to ") + endpointUrl);
|
|
87
|
+
if (err instanceof Error) {
|
|
88
|
+
console.log(" Error = ", err.message);
|
|
89
|
+
}
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const endpoints = yield client.getEndpoints();
|
|
93
|
+
if (argv.debug) {
|
|
94
|
+
fs.writeFileSync("tmp/endpoints.log", JSON.stringify(endpoints, null, " "));
|
|
95
|
+
console.log(treeify.asTree(endpoints, true));
|
|
96
|
+
}
|
|
97
|
+
const table = new Table();
|
|
98
|
+
let serverCertificate;
|
|
99
|
+
let i = 0;
|
|
100
|
+
for (const endpoint of endpoints) {
|
|
101
|
+
table.cell("endpoint", endpoint.endpointUrl + "");
|
|
102
|
+
table.cell("Application URI", endpoint.server.applicationUri);
|
|
103
|
+
table.cell("Product URI", endpoint.server.productUri);
|
|
104
|
+
table.cell("Application Name", endpoint.server.applicationName.text);
|
|
105
|
+
table.cell("securityLevel", endpoint.securityLevel);
|
|
106
|
+
table.cell("Security Mode", chalk.cyan(node_opcua_1.MessageSecurityMode[endpoint.securityMode].toString()));
|
|
107
|
+
table.cell("securityPolicyUri", chalk.cyan(endpoint.securityPolicyUri));
|
|
108
|
+
table.cell("Type", node_opcua_1.ApplicationType[endpoint.server.applicationType]);
|
|
109
|
+
table.cell("certificate", "..." /*endpoint.serverCertificate*/);
|
|
110
|
+
endpoint.server.discoveryUrls = endpoint.server.discoveryUrls || [];
|
|
111
|
+
table.cell("discoveryUrls", endpoint.server.discoveryUrls.join(" - "));
|
|
112
|
+
serverCertificate = endpoint.serverCertificate;
|
|
113
|
+
const certificate_filename = path.join(__dirname, "../certificates/PKI/server_certificate" + i + ".pem");
|
|
114
|
+
if (serverCertificate) {
|
|
115
|
+
fs.writeFile(certificate_filename, (0, node_opcua_crypto_1.toPem)(serverCertificate, "CERTIFICATE"), () => {
|
|
116
|
+
/**/
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
table.newRow();
|
|
120
|
+
i++;
|
|
121
|
+
}
|
|
122
|
+
console.log(table.toString());
|
|
123
|
+
for (const endpoint of endpoints) {
|
|
124
|
+
console.log("Identify Token for : Security Mode=", chalk.cyan(node_opcua_1.MessageSecurityMode[endpoint.securityMode].toString()), " Policy=", chalk.cyan(endpoint.securityPolicyUri));
|
|
125
|
+
const table2 = new Table();
|
|
126
|
+
for (const token of endpoint.userIdentityTokens) {
|
|
127
|
+
table2.cell("policyId", token.policyId);
|
|
128
|
+
table2.cell("tokenType", node_opcua_1.UserTokenType[token.tokenType]);
|
|
129
|
+
table2.cell("issuedTokenType", token.issuedTokenType);
|
|
130
|
+
table2.cell("issuerEndpointUrl", token.issuerEndpointUrl);
|
|
131
|
+
table2.cell("securityPolicyUri", token.securityPolicyUri);
|
|
132
|
+
table2.newRow();
|
|
133
|
+
}
|
|
134
|
+
console.log(table2.toString());
|
|
135
|
+
}
|
|
136
|
+
yield client.disconnect();
|
|
137
|
+
console.log("success !! ");
|
|
138
|
+
process.exit(0);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
main();
|
|
142
142
|
//# sourceMappingURL=get_endpoints.js.map
|
package/dist/mini_server.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|