-
Notifications
You must be signed in to change notification settings - Fork 142
/
Copy pathcluster.js
48 lines (43 loc) · 1.07 KB
/
cluster.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
47
48
'use strict';
const URI = require('urijs');
/**
* clusters:
* - cluster:
* certificate-authority: path/to/my/cafile
* server: https://horse.org:4443
* name: horse-cluster
* - cluster:
* insecure-skip-tls-verify: true
* server: https://pig.org:443
* name: pig-cluster
*/
class Cluster {
constructor({ server, name, 'insecure-skip-tls-verify': rejectUnauthorized,
'certificate-authority': cert , 'certificate-authority-data': certData }) {
if (typeof name !== 'undefined') {
this.name = name;
} else {
const { hostname, port } = Cluster.getUrlParts(server);
if (port) {
this.name = `${hostname}:${port}`;
} else {
this.name = hostname;
}
}
this.server = server;
this.rejectUnauthorized = rejectUnauthorized;
this.ca = cert;
this.certData = certData;
}
static getUrlParts(url) {
const uri = URI.parse(url);
let parts = {};
if (uri.protocol) {
parts = uri;
} else {
URI.parseHost(url, parts);
}
return parts;
}
}
module.exports = Cluster;