-
Notifications
You must be signed in to change notification settings - Fork 7
/
watch.js
46 lines (40 loc) · 1.21 KB
/
watch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright 2020 Canonical Ltd.
// Licensed under the LGPLv3, see LICENSE.txt file for details.
// Allow connecting endpoints using self-signed certs.
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
import websocket from "websocket";
import * as jujulib from "../api/client.js";
import AllWatcherV1 from "../api/facades/all-watcher/AllWatcherV1.js";
import ClientV2 from "../api/facades/client/ClientV2.js";
const url =
"wss://10.223.241.216:17070/model/7236b7b8-5458-4d3e-8a9a-1c8f1a0046b1/api";
const options = {
debug: true,
facades: [AllWatcherV1, ClientV2],
wsclass: websocket.w3cwebsocket,
};
async function watch() {
try {
const juju = await jujulib.connect(url, options);
const conn = await juju.login({
username: "admin",
password: "ca83f25a8fd8e162641b60f7a5fd1049",
});
const handle = conn.facades.client.watch((err, result) => {
if (err) {
console.log("cannot watch model:", err);
process.exit(1);
}
console.log(result);
});
setTimeout(() => {
handle.stop((_err) => {
console.log("watcher stopped");
});
}, 10000);
} catch (error) {
console.log("cannot connect:", error);
process.exit(1);
}
}
watch();