@brimble/consul 0.0.1
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/LICENSE +19 -0
- package/README.md +2423 -0
- package/lib/acl/legacy.d.ts +75 -0
- package/lib/acl/legacy.js +167 -0
- package/lib/acl.d.ts +37 -0
- package/lib/acl.js +49 -0
- package/lib/agent/check.d.ts +113 -0
- package/lib/agent/check.js +164 -0
- package/lib/agent/service.d.ts +63 -0
- package/lib/agent/service.js +113 -0
- package/lib/agent.d.ts +77 -0
- package/lib/agent.js +162 -0
- package/lib/catalog/connect.d.ts +11 -0
- package/lib/catalog/connect.js +37 -0
- package/lib/catalog/node.d.ts +30 -0
- package/lib/catalog/node.js +57 -0
- package/lib/catalog/service.d.ts +32 -0
- package/lib/catalog/service.js +61 -0
- package/lib/catalog.d.ts +118 -0
- package/lib/catalog.js +113 -0
- package/lib/constants.js +21 -0
- package/lib/consul.d.ts +93 -0
- package/lib/consul.js +98 -0
- package/lib/errors.js +29 -0
- package/lib/event.d.ts +43 -0
- package/lib/event.js +91 -0
- package/lib/health.d.ts +77 -0
- package/lib/health.js +126 -0
- package/lib/index.d.ts +18 -0
- package/lib/index.js +3 -0
- package/lib/intention.d.ts +73 -0
- package/lib/intention.js +180 -0
- package/lib/kv.d.ts +80 -0
- package/lib/kv.js +180 -0
- package/lib/query.d.ts +84 -0
- package/lib/query.js +244 -0
- package/lib/resolver/algorithms.js +127 -0
- package/lib/resolver/dns.js +182 -0
- package/lib/resolver/health.js +51 -0
- package/lib/resolver/metrics.js +199 -0
- package/lib/resolver/scoring.js +95 -0
- package/lib/resolver/types.js +28 -0
- package/lib/resolver.d.ts +76 -0
- package/lib/resolver.js +290 -0
- package/lib/session.d.ts +92 -0
- package/lib/session.js +164 -0
- package/lib/status.d.ts +19 -0
- package/lib/status.js +43 -0
- package/lib/transaction.d.ts +50 -0
- package/lib/transaction.js +58 -0
- package/lib/utils.js +655 -0
- package/lib/watch.d.ts +22 -0
- package/lib/watch.js +183 -0
- package/package.json +55 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
const errors = require("../errors");
|
|
2
|
+
const utils = require("../utils");
|
|
3
|
+
|
|
4
|
+
class AgentService {
|
|
5
|
+
constructor(consul) {
|
|
6
|
+
this.consul = consul;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Returns the services local agent is managing
|
|
11
|
+
*/
|
|
12
|
+
async list(opts) {
|
|
13
|
+
opts = utils.normalizeKeys(opts);
|
|
14
|
+
opts = utils.defaults(opts, this.consul._defaults);
|
|
15
|
+
|
|
16
|
+
const req = {
|
|
17
|
+
name: "agent.service.list",
|
|
18
|
+
path: "/agent/services",
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
utils.options(req, opts);
|
|
22
|
+
|
|
23
|
+
return await this.consul._get(req, utils.body);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Registers a new local service
|
|
28
|
+
*/
|
|
29
|
+
async register(opts) {
|
|
30
|
+
if (typeof opts === "string") {
|
|
31
|
+
opts = { name: opts };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
opts = utils.normalizeKeys(opts);
|
|
35
|
+
opts = utils.defaults(opts, this.consul._defaults);
|
|
36
|
+
|
|
37
|
+
const req = {
|
|
38
|
+
name: "agent.service.register",
|
|
39
|
+
path: "/agent/service/register",
|
|
40
|
+
type: "json",
|
|
41
|
+
body: {},
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
if (!opts.name) {
|
|
45
|
+
throw this.consul._err(errors.Validation("name required"), req);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
req.body = utils.createService(opts);
|
|
50
|
+
} catch (err) {
|
|
51
|
+
throw this.consul._err(errors.Validation(err.message), req);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
utils.options(req, opts);
|
|
55
|
+
|
|
56
|
+
return await this.consul._put(req, utils.empty);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Deregister a local service
|
|
61
|
+
*/
|
|
62
|
+
async deregister(opts) {
|
|
63
|
+
if (typeof opts === "string") {
|
|
64
|
+
opts = { id: opts };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
opts = utils.normalizeKeys(opts);
|
|
68
|
+
opts = utils.defaults(opts, this.consul._defaults);
|
|
69
|
+
|
|
70
|
+
const req = {
|
|
71
|
+
name: "agent.service.deregister",
|
|
72
|
+
path: "/agent/service/deregister/{id}",
|
|
73
|
+
params: { id: opts.id },
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
if (!opts.id) {
|
|
77
|
+
throw this.consul._err(errors.Validation("id required"), req);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
utils.options(req, opts);
|
|
81
|
+
|
|
82
|
+
return await this.consul._put(req, utils.empty);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Manages node maintenance mode
|
|
87
|
+
*/
|
|
88
|
+
async maintenance(opts) {
|
|
89
|
+
opts = utils.normalizeKeys(opts);
|
|
90
|
+
opts = utils.defaults(opts, this.consul._defaults);
|
|
91
|
+
|
|
92
|
+
const req = {
|
|
93
|
+
name: "agent.service.maintenance",
|
|
94
|
+
path: "/agent/service/maintenance/{id}",
|
|
95
|
+
params: { id: opts.id },
|
|
96
|
+
query: { enable: opts.enable },
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
if (!opts.id) {
|
|
100
|
+
throw this.consul._err(errors.Validation("id required"), req);
|
|
101
|
+
}
|
|
102
|
+
if (typeof opts.enable !== "boolean") {
|
|
103
|
+
throw this.consul._err(errors.Validation("enable required"), req);
|
|
104
|
+
}
|
|
105
|
+
if (opts.reason) req.query.reason = opts.reason;
|
|
106
|
+
|
|
107
|
+
utils.options(req, opts);
|
|
108
|
+
|
|
109
|
+
return await this.consul._put(req, utils.empty);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
exports.AgentService = AgentService;
|
package/lib/agent.d.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { CommonOptions, Consul } from "./consul";
|
|
2
|
+
import {
|
|
3
|
+
AgentCheck,
|
|
4
|
+
ListOptions as CheckListOptions,
|
|
5
|
+
ListResult as CheckListResult,
|
|
6
|
+
} from "./agent/check";
|
|
7
|
+
import {
|
|
8
|
+
AgentService,
|
|
9
|
+
ListOptions as ServiceListOptions,
|
|
10
|
+
ListResult as ServiceListResult,
|
|
11
|
+
} from "./agent/service";
|
|
12
|
+
|
|
13
|
+
interface MembersOptions extends CommonOptions {
|
|
14
|
+
wan?: boolean;
|
|
15
|
+
segment?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
type MembersResult = any[];
|
|
19
|
+
|
|
20
|
+
interface ReloadOptions extends CommonOptions {}
|
|
21
|
+
|
|
22
|
+
type ReloadResult = any;
|
|
23
|
+
|
|
24
|
+
interface SelfOptions extends CommonOptions {}
|
|
25
|
+
|
|
26
|
+
type SelfResult = any;
|
|
27
|
+
|
|
28
|
+
interface MaintenanceOptions extends CommonOptions {
|
|
29
|
+
enable: boolean;
|
|
30
|
+
reason?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
type MaintenanceResult = any;
|
|
34
|
+
|
|
35
|
+
interface JoinOptions extends CommonOptions {
|
|
36
|
+
address: string;
|
|
37
|
+
wan?: boolean;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
type JoinResult = any;
|
|
41
|
+
|
|
42
|
+
interface ForceLeaveOptions extends CommonOptions {
|
|
43
|
+
node: string;
|
|
44
|
+
prune?: boolean;
|
|
45
|
+
wan?: boolean;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
type ForceLeaveResult = any;
|
|
49
|
+
|
|
50
|
+
declare class Agent {
|
|
51
|
+
constructor(consul: Consul);
|
|
52
|
+
|
|
53
|
+
consul: Consul;
|
|
54
|
+
check: AgentCheck;
|
|
55
|
+
service: AgentService;
|
|
56
|
+
|
|
57
|
+
static Check: typeof AgentCheck;
|
|
58
|
+
static Service: typeof AgentService;
|
|
59
|
+
|
|
60
|
+
checks(options?: CheckListOptions): Promise<CheckListResult>;
|
|
61
|
+
|
|
62
|
+
services(options?: ServiceListOptions): Promise<ServiceListResult>;
|
|
63
|
+
|
|
64
|
+
members(options?: MembersOptions): Promise<MembersResult>;
|
|
65
|
+
|
|
66
|
+
reload(options?: ReloadOptions): Promise<ReloadResult>;
|
|
67
|
+
|
|
68
|
+
self(options?: SelfOptions): Promise<SelfResult>;
|
|
69
|
+
|
|
70
|
+
maintenance(options: MaintenanceOptions): Promise<MaintenanceResult>;
|
|
71
|
+
maintenance(enable: boolean): Promise<MaintenanceResult>;
|
|
72
|
+
|
|
73
|
+
join(options: JoinOptions): Promise<JoinResult>;
|
|
74
|
+
join(address: string): Promise<JoinResult>;
|
|
75
|
+
|
|
76
|
+
forceLeave(options: ForceLeaveOptions | string): Promise<ForceLeaveResult>;
|
|
77
|
+
}
|
package/lib/agent.js
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
const AgentCheck = require("./agent/check").AgentCheck;
|
|
2
|
+
const AgentService = require("./agent/service").AgentService;
|
|
3
|
+
const errors = require("./errors");
|
|
4
|
+
const utils = require("./utils");
|
|
5
|
+
|
|
6
|
+
class Agent {
|
|
7
|
+
constructor(consul) {
|
|
8
|
+
this.consul = consul;
|
|
9
|
+
this.check = new Agent.Check(consul);
|
|
10
|
+
this.service = new Agent.Service(consul);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Returns the checks the local agent is managing
|
|
15
|
+
*/
|
|
16
|
+
checks() {
|
|
17
|
+
return this.check.list.apply(this.check, arguments);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Returns the services local agent is managing
|
|
22
|
+
*/
|
|
23
|
+
services() {
|
|
24
|
+
return this.service.list.apply(this.service, arguments);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Returns the members as seen by the local consul agent
|
|
29
|
+
*/
|
|
30
|
+
async members(opts) {
|
|
31
|
+
opts = utils.normalizeKeys(opts);
|
|
32
|
+
opts = utils.defaults(opts, this.consul._defaults);
|
|
33
|
+
|
|
34
|
+
const req = {
|
|
35
|
+
name: "agent.members",
|
|
36
|
+
path: "/agent/members",
|
|
37
|
+
query: {},
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
utils.options(req, opts);
|
|
41
|
+
|
|
42
|
+
return await this.consul._get(req, utils.body);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Reload agent configuration
|
|
47
|
+
*/
|
|
48
|
+
async reload(opts) {
|
|
49
|
+
opts = utils.normalizeKeys(opts);
|
|
50
|
+
opts = utils.defaults(opts, this.consul._defaults);
|
|
51
|
+
|
|
52
|
+
const req = {
|
|
53
|
+
name: "agent.reload",
|
|
54
|
+
path: "/agent/reload",
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
utils.options(req, opts);
|
|
58
|
+
|
|
59
|
+
return await this.consul._put(req, utils.empty);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Returns the local node configuration
|
|
64
|
+
*/
|
|
65
|
+
async self(opts) {
|
|
66
|
+
opts = utils.normalizeKeys(opts);
|
|
67
|
+
opts = utils.defaults(opts, this.consul._defaults);
|
|
68
|
+
|
|
69
|
+
const req = {
|
|
70
|
+
name: "agent.self",
|
|
71
|
+
path: "/agent/self",
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
utils.options(req, opts);
|
|
75
|
+
|
|
76
|
+
return await this.consul._get(req, utils.body);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Manages node maintenance mode
|
|
81
|
+
*/
|
|
82
|
+
async maintenance(opts) {
|
|
83
|
+
if (typeof opts === "boolean") {
|
|
84
|
+
opts = { enable: opts };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
opts = utils.normalizeKeys(opts);
|
|
88
|
+
opts = utils.defaults(opts, this.consul._defaults);
|
|
89
|
+
|
|
90
|
+
const req = {
|
|
91
|
+
name: "agent.maintenance",
|
|
92
|
+
path: "/agent/maintenance",
|
|
93
|
+
query: { enable: opts.enable },
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
if (typeof opts.enable !== "boolean") {
|
|
97
|
+
throw this.consul._err(errors.Validation("enable required"), req);
|
|
98
|
+
}
|
|
99
|
+
if (opts.reason) req.query.reason = opts.reason;
|
|
100
|
+
|
|
101
|
+
utils.options(req, opts);
|
|
102
|
+
|
|
103
|
+
return await this.consul._put(req, utils.empty);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Trigger local agent to join a node
|
|
108
|
+
*/
|
|
109
|
+
async join(opts) {
|
|
110
|
+
if (typeof opts === "string") {
|
|
111
|
+
opts = { address: opts };
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
opts = utils.normalizeKeys(opts);
|
|
115
|
+
opts = utils.defaults(opts, this.consul._defaults);
|
|
116
|
+
|
|
117
|
+
const req = {
|
|
118
|
+
name: "agent.join",
|
|
119
|
+
path: "/agent/join/{address}",
|
|
120
|
+
params: { address: opts.address },
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
if (!opts.address) {
|
|
124
|
+
throw this.consul._err(errors.Validation("address required"), req);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
utils.options(req, opts);
|
|
128
|
+
|
|
129
|
+
return await this.consul._put(req, utils.empty);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Force remove node
|
|
134
|
+
*/
|
|
135
|
+
async forceLeave(opts) {
|
|
136
|
+
if (typeof opts === "string") {
|
|
137
|
+
opts = { node: opts };
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
opts = utils.normalizeKeys(opts);
|
|
141
|
+
opts = utils.defaults(opts, this.consul._defaults);
|
|
142
|
+
|
|
143
|
+
const req = {
|
|
144
|
+
name: "agent.forceLeave",
|
|
145
|
+
path: "/agent/force-leave/{node}",
|
|
146
|
+
params: { node: opts.node },
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
if (!opts.node) {
|
|
150
|
+
throw this.consul._err(errors.Validation("node required"), req);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
utils.options(req, opts);
|
|
154
|
+
|
|
155
|
+
return await this.consul._put(req, utils.empty);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
Agent.Check = AgentCheck;
|
|
160
|
+
Agent.Service = AgentService;
|
|
161
|
+
|
|
162
|
+
exports.Agent = Agent;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Consul } from "../consul";
|
|
2
|
+
import { NodesOptions, NodesResult } from "./service";
|
|
3
|
+
|
|
4
|
+
declare class CatalogConnect {
|
|
5
|
+
constructor(consul: Consul);
|
|
6
|
+
|
|
7
|
+
consul: Consul;
|
|
8
|
+
|
|
9
|
+
nodes(options: NodesOptions): Promise<NodesResult>;
|
|
10
|
+
nodes(service: string): Promise<NodesResult>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const errors = require("../errors");
|
|
2
|
+
const utils = require("../utils");
|
|
3
|
+
|
|
4
|
+
class CatalogConnect {
|
|
5
|
+
constructor(consul) {
|
|
6
|
+
this.consul = consul;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Lists the nodes in a given Connect-capable service
|
|
11
|
+
*/
|
|
12
|
+
async nodes(opts) {
|
|
13
|
+
if (typeof opts === "string") {
|
|
14
|
+
opts = { service: opts };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
opts = utils.normalizeKeys(opts);
|
|
18
|
+
opts = utils.defaults(opts, this.consul._defaults);
|
|
19
|
+
|
|
20
|
+
const req = {
|
|
21
|
+
name: "catalog.connect.nodes",
|
|
22
|
+
path: "/catalog/connect/{service}",
|
|
23
|
+
params: { service: opts.service },
|
|
24
|
+
query: {},
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
if (!opts.service) {
|
|
28
|
+
throw this.consul._err(errors.Validation("service required"), req);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
utils.options(req, opts);
|
|
32
|
+
|
|
33
|
+
return await this.consul._get(req, utils.body);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
exports.CatalogConnect = CatalogConnect;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { CommonOptions, Consul } from "../consul";
|
|
2
|
+
|
|
3
|
+
interface ListOptions extends CommonOptions {
|
|
4
|
+
dc?: string;
|
|
5
|
+
near?: string;
|
|
6
|
+
filter?: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
type ListResult = any[];
|
|
10
|
+
|
|
11
|
+
interface ServicesOptions extends CommonOptions {
|
|
12
|
+
node: string;
|
|
13
|
+
dc?: string;
|
|
14
|
+
filter?: string;
|
|
15
|
+
ns?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
type ServicesResult = any;
|
|
19
|
+
|
|
20
|
+
declare class CatalogNode {
|
|
21
|
+
constructor(consul: Consul);
|
|
22
|
+
|
|
23
|
+
consul: Consul;
|
|
24
|
+
|
|
25
|
+
list(options?: ListOptions): Promise<ListResult>;
|
|
26
|
+
list(dc: string): Promise<ListResult>;
|
|
27
|
+
|
|
28
|
+
services(options: ServicesOptions): Promise<ServicesResult>;
|
|
29
|
+
services(node: string): Promise<ServicesResult>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
const errors = require("../errors");
|
|
2
|
+
const utils = require("../utils");
|
|
3
|
+
|
|
4
|
+
class CatalogNode {
|
|
5
|
+
constructor(consul) {
|
|
6
|
+
this.consul = consul;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Lists nodes in a given DC
|
|
11
|
+
*/
|
|
12
|
+
async list(opts) {
|
|
13
|
+
if (typeof opts === "string") {
|
|
14
|
+
opts = { dc: opts };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
opts = utils.normalizeKeys(opts);
|
|
18
|
+
opts = utils.defaults(opts, this.consul._defaults);
|
|
19
|
+
|
|
20
|
+
const req = {
|
|
21
|
+
name: "catalog.node.list",
|
|
22
|
+
path: "/catalog/nodes",
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
utils.options(req, opts);
|
|
26
|
+
|
|
27
|
+
return await this.consul._get(req, utils.body);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Lists the services provided by a node
|
|
32
|
+
*/
|
|
33
|
+
async services(opts) {
|
|
34
|
+
if (typeof opts === "string") {
|
|
35
|
+
opts = { node: opts };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
opts = utils.normalizeKeys(opts);
|
|
39
|
+
opts = utils.defaults(opts, this.consul._defaults);
|
|
40
|
+
|
|
41
|
+
const req = {
|
|
42
|
+
name: "catalog.node.services",
|
|
43
|
+
path: "/catalog/node/{node}",
|
|
44
|
+
params: { node: opts.node },
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
if (!opts.node) {
|
|
48
|
+
throw this.consul._err(errors.Validation("node required"), req);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
utils.options(req, opts);
|
|
52
|
+
|
|
53
|
+
return await this.consul._get(req, utils.body);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
exports.CatalogNode = CatalogNode;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { CommonOptions, Consul } from "../consul";
|
|
2
|
+
|
|
3
|
+
interface ListOptions extends CommonOptions {
|
|
4
|
+
dc?: string;
|
|
5
|
+
ns?: string;
|
|
6
|
+
filter?: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
type ListResult = Record<string, string[]>;
|
|
10
|
+
|
|
11
|
+
interface NodesOptions extends CommonOptions {
|
|
12
|
+
service: string;
|
|
13
|
+
dc?: string;
|
|
14
|
+
tag?: string;
|
|
15
|
+
near?: string;
|
|
16
|
+
filter?: string;
|
|
17
|
+
ns?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
type NodesResult = any[];
|
|
21
|
+
|
|
22
|
+
declare class CatalogService {
|
|
23
|
+
constructor(consul: Consul);
|
|
24
|
+
|
|
25
|
+
consul: Consul;
|
|
26
|
+
|
|
27
|
+
list(options?: ListOptions): Promise<ListResult>;
|
|
28
|
+
list(dc: string): Promise<ListResult>;
|
|
29
|
+
|
|
30
|
+
nodes(options: NodesOptions): Promise<NodesResult>;
|
|
31
|
+
nodes(service: string): Promise<NodesResult>;
|
|
32
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
const errors = require("../errors");
|
|
2
|
+
const utils = require("../utils");
|
|
3
|
+
|
|
4
|
+
class CatalogService {
|
|
5
|
+
constructor(consul) {
|
|
6
|
+
this.consul = consul;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Lists services in a given DC
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
async list(opts) {
|
|
14
|
+
if (typeof opts === "string") {
|
|
15
|
+
opts = { dc: opts };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
opts = utils.normalizeKeys(opts);
|
|
19
|
+
opts = utils.defaults(opts, this.consul._defaults);
|
|
20
|
+
|
|
21
|
+
const req = {
|
|
22
|
+
name: "catalog.service.list",
|
|
23
|
+
path: "/catalog/services",
|
|
24
|
+
query: {},
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
utils.options(req, opts);
|
|
28
|
+
|
|
29
|
+
return await this.consul._get(req, utils.body);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Lists the nodes in a given service
|
|
34
|
+
*/
|
|
35
|
+
async nodes(opts) {
|
|
36
|
+
if (typeof opts === "string") {
|
|
37
|
+
opts = { service: opts };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
opts = utils.normalizeKeys(opts);
|
|
41
|
+
opts = utils.defaults(opts, this.consul._defaults);
|
|
42
|
+
|
|
43
|
+
const req = {
|
|
44
|
+
name: "catalog.service.nodes",
|
|
45
|
+
path: "/catalog/service/{service}",
|
|
46
|
+
params: { service: opts.service },
|
|
47
|
+
query: {},
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
if (!opts.service) {
|
|
51
|
+
throw this.consul._err(errors.Validation("service required"), req);
|
|
52
|
+
}
|
|
53
|
+
if (opts.tag) req.query.tag = opts.tag;
|
|
54
|
+
|
|
55
|
+
utils.options(req, opts);
|
|
56
|
+
|
|
57
|
+
return await this.consul._get(req, utils.body);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
exports.CatalogService = CatalogService;
|
package/lib/catalog.d.ts
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { CommonOptions, Consul } from "./consul";
|
|
2
|
+
import { CatalogConnect } from "./catalog/connect";
|
|
3
|
+
import {
|
|
4
|
+
CatalogNode,
|
|
5
|
+
ListOptions as NodeListOptions,
|
|
6
|
+
ListResult as NodeListResult,
|
|
7
|
+
} from "./catalog/node";
|
|
8
|
+
import {
|
|
9
|
+
CatalogService,
|
|
10
|
+
ListOptions as ServiceListOptions,
|
|
11
|
+
ListResult as ServiceListResult,
|
|
12
|
+
} from "./catalog/service";
|
|
13
|
+
|
|
14
|
+
interface DatacentersOptions extends CommonOptions {}
|
|
15
|
+
|
|
16
|
+
type DatacentersResult = string[];
|
|
17
|
+
|
|
18
|
+
type NodesOptions = NodeListOptions;
|
|
19
|
+
|
|
20
|
+
type NodesResult = NodeListResult;
|
|
21
|
+
|
|
22
|
+
interface RegisterService {
|
|
23
|
+
id?: string;
|
|
24
|
+
service: string;
|
|
25
|
+
address?: string;
|
|
26
|
+
port?: number;
|
|
27
|
+
tags?: string[];
|
|
28
|
+
meta?: Record<string, string>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface RegisterCheckHealthDefinitionBase {
|
|
32
|
+
intervalduration: string;
|
|
33
|
+
timeoutduration?: string;
|
|
34
|
+
deregistercriticalserviceafterduration?: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
interface RegisterCheckHealthDefinitionHttp
|
|
38
|
+
extends RegisterCheckHealthDefinitionBase {
|
|
39
|
+
http: string;
|
|
40
|
+
tlsskipverify?: boolean;
|
|
41
|
+
tlsservername?: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
interface RegisterCheckHealthDefinitionTcp
|
|
45
|
+
extends RegisterCheckHealthDefinitionBase {
|
|
46
|
+
tcp: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
type RegisterCheckHealthDefinition =
|
|
50
|
+
| RegisterCheckHealthDefinitionHttp
|
|
51
|
+
| RegisterCheckHealthDefinitionTcp;
|
|
52
|
+
|
|
53
|
+
interface RegisterCheck {
|
|
54
|
+
node?: string;
|
|
55
|
+
name?: string;
|
|
56
|
+
checkid?: string;
|
|
57
|
+
serviceid?: string;
|
|
58
|
+
notes?: string;
|
|
59
|
+
status?: "passing" | "warning" | "critical";
|
|
60
|
+
definition?: RegisterCheckHealthDefinition;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
interface RegisterOptions extends CommonOptions {
|
|
64
|
+
id?: string;
|
|
65
|
+
node: string;
|
|
66
|
+
address: string;
|
|
67
|
+
datacenter?: string;
|
|
68
|
+
taggedaddresses?: Record<string, string>;
|
|
69
|
+
nodemeta?: Record<string, string>;
|
|
70
|
+
service?: RegisterService;
|
|
71
|
+
check?: RegisterCheck;
|
|
72
|
+
checks?: RegisterCheck[];
|
|
73
|
+
skipnodeupdate?: boolean;
|
|
74
|
+
namespace?: string;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
type RegisterResult = any;
|
|
78
|
+
|
|
79
|
+
interface DeregisterOptions extends CommonOptions {
|
|
80
|
+
node: string;
|
|
81
|
+
datacenter?: string;
|
|
82
|
+
checkid?: string;
|
|
83
|
+
serviceid?: string;
|
|
84
|
+
namespace?: string;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
type DeregisterResult = any;
|
|
88
|
+
|
|
89
|
+
type ServicesOptions = ServiceListOptions;
|
|
90
|
+
|
|
91
|
+
type ServicesResult = ServiceListResult;
|
|
92
|
+
|
|
93
|
+
declare class Catalog {
|
|
94
|
+
constructor(consul: Consul);
|
|
95
|
+
|
|
96
|
+
consul: Consul;
|
|
97
|
+
connect: CatalogConnect;
|
|
98
|
+
node: CatalogNode;
|
|
99
|
+
service: CatalogService;
|
|
100
|
+
|
|
101
|
+
static Connect: typeof CatalogConnect;
|
|
102
|
+
static Node: typeof CatalogNode;
|
|
103
|
+
static Service: typeof CatalogService;
|
|
104
|
+
|
|
105
|
+
datacenters(options?: DatacentersOptions): Promise<DatacentersResult>;
|
|
106
|
+
|
|
107
|
+
nodes(options: NodesOptions): Promise<NodesResult>;
|
|
108
|
+
nodes(service: string): Promise<NodesResult>;
|
|
109
|
+
|
|
110
|
+
register(options: RegisterOptions): Promise<RegisterResult>;
|
|
111
|
+
register(node: string): Promise<RegisterResult>;
|
|
112
|
+
|
|
113
|
+
deregister(options: DeregisterOptions): Promise<DeregisterResult>;
|
|
114
|
+
deregister(node: string): Promise<DeregisterResult>;
|
|
115
|
+
|
|
116
|
+
services(options?: ServicesOptions): Promise<ServicesResult>;
|
|
117
|
+
services(dc: string): Promise<ServicesResult>;
|
|
118
|
+
}
|