@brimble/consul 2.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 +2242 -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 +73 -0
- package/lib/consul.js +92 -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 +3 -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/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 +50 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Consul } from "../consul";
|
|
2
|
+
|
|
3
|
+
interface CreateOptions {
|
|
4
|
+
name?: string;
|
|
5
|
+
type?: "client" | "management";
|
|
6
|
+
rules?: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
type CreateResult = any;
|
|
10
|
+
|
|
11
|
+
interface UpdateOptions {
|
|
12
|
+
id: string;
|
|
13
|
+
name?: string;
|
|
14
|
+
type?: "client" | "management";
|
|
15
|
+
rules?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
type UpdateResult = any;
|
|
19
|
+
|
|
20
|
+
interface DestroyOptions {
|
|
21
|
+
id: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
type DestroyResult = any;
|
|
25
|
+
|
|
26
|
+
interface InfoOptions {
|
|
27
|
+
id: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface InfoResult {
|
|
31
|
+
CreateIndex: number;
|
|
32
|
+
ModifyIndex: number;
|
|
33
|
+
ID: string;
|
|
34
|
+
Name: string;
|
|
35
|
+
Type: "client" | "management";
|
|
36
|
+
Rules: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
type GetOptions = InfoOptions;
|
|
40
|
+
|
|
41
|
+
type GetResult = InfoResult;
|
|
42
|
+
|
|
43
|
+
interface CloneOptions {
|
|
44
|
+
id: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
type CloneResult = any;
|
|
48
|
+
|
|
49
|
+
interface ListOptions {}
|
|
50
|
+
|
|
51
|
+
type ListResult = GetResult[];
|
|
52
|
+
|
|
53
|
+
declare class AclLegacy {
|
|
54
|
+
constructor(consul: Consul);
|
|
55
|
+
|
|
56
|
+
consul: Consul;
|
|
57
|
+
|
|
58
|
+
create(options?: CreateOptions): Promise<CreateResult>;
|
|
59
|
+
|
|
60
|
+
update(options: UpdateOptions): Promise<UpdateResult>;
|
|
61
|
+
|
|
62
|
+
destroy(options: DestroyOptions): Promise<DestroyResult>;
|
|
63
|
+
destroy(id: string): Promise<DestroyResult>;
|
|
64
|
+
|
|
65
|
+
info(options: InfoOptions): Promise<InfoResult>;
|
|
66
|
+
info(id: string): Promise<InfoResult>;
|
|
67
|
+
|
|
68
|
+
get(options: GetOptions): Promise<GetResult>;
|
|
69
|
+
get(id: string): Promise<GetResult>;
|
|
70
|
+
|
|
71
|
+
clone(options: CloneOptions): Promise<CloneResult>;
|
|
72
|
+
clone(id: string): Promise<CloneResult>;
|
|
73
|
+
|
|
74
|
+
list(options?: ListOptions): Promise<ListResult>;
|
|
75
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
const errors = require("../errors");
|
|
2
|
+
const utils = require("../utils");
|
|
3
|
+
|
|
4
|
+
class AclLegacy {
|
|
5
|
+
constructor(consul) {
|
|
6
|
+
this.consul = consul;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Creates a new token with policy
|
|
11
|
+
*/
|
|
12
|
+
async create(opts) {
|
|
13
|
+
opts = utils.normalizeKeys(opts);
|
|
14
|
+
opts = utils.defaults(opts, this.consul._defaults);
|
|
15
|
+
|
|
16
|
+
const req = {
|
|
17
|
+
name: "acl.legacy.create",
|
|
18
|
+
path: "/acl/create",
|
|
19
|
+
query: {},
|
|
20
|
+
type: "json",
|
|
21
|
+
body: {},
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
if (opts.name) req.body.Name = opts.name;
|
|
25
|
+
if (opts.type) req.body.Type = opts.type;
|
|
26
|
+
if (opts.rules) req.body.Rules = opts.rules;
|
|
27
|
+
|
|
28
|
+
utils.options(req, opts);
|
|
29
|
+
|
|
30
|
+
return await this.consul._put(req, utils.body);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Update the policy of a token
|
|
35
|
+
*/
|
|
36
|
+
async update(opts) {
|
|
37
|
+
opts = utils.normalizeKeys(opts);
|
|
38
|
+
opts = utils.defaults(opts, this.consul._defaults);
|
|
39
|
+
|
|
40
|
+
const req = {
|
|
41
|
+
name: "acl.legacy.update",
|
|
42
|
+
path: "/acl/update",
|
|
43
|
+
query: {},
|
|
44
|
+
type: "json",
|
|
45
|
+
body: {},
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
if (!opts.id) {
|
|
49
|
+
throw this.consul._err(errors.Validation("id required"), req);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
req.body.ID = opts.id;
|
|
53
|
+
|
|
54
|
+
if (opts.name) req.body.Name = opts.name;
|
|
55
|
+
if (opts.type) req.body.Type = opts.type;
|
|
56
|
+
if (opts.rules) req.body.Rules = opts.rules;
|
|
57
|
+
|
|
58
|
+
utils.options(req, opts);
|
|
59
|
+
|
|
60
|
+
return await this.consul._put(req, utils.empty);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Destroys a given token
|
|
65
|
+
*/
|
|
66
|
+
async destroy(opts) {
|
|
67
|
+
if (typeof opts === "string") {
|
|
68
|
+
opts = { id: opts };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
opts = utils.normalizeKeys(opts);
|
|
72
|
+
opts = utils.defaults(opts, this.consul._defaults);
|
|
73
|
+
|
|
74
|
+
const req = {
|
|
75
|
+
name: "acl.legacy.destroy",
|
|
76
|
+
path: "/acl/destroy/{id}",
|
|
77
|
+
params: { id: opts.id },
|
|
78
|
+
query: {},
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
if (!opts.id) {
|
|
82
|
+
throw this.consul._err(errors.Validation("id required"), req);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
utils.options(req, opts);
|
|
86
|
+
|
|
87
|
+
return await this.consul._put(req, utils.empty);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Queries the policy of a given token
|
|
92
|
+
*/
|
|
93
|
+
async info(opts) {
|
|
94
|
+
if (typeof opts === "string") {
|
|
95
|
+
opts = { id: opts };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
opts = utils.normalizeKeys(opts);
|
|
99
|
+
opts = utils.defaults(opts, this.consul._defaults);
|
|
100
|
+
|
|
101
|
+
const req = {
|
|
102
|
+
name: "acl.legacy.info",
|
|
103
|
+
path: "/acl/info/{id}",
|
|
104
|
+
params: { id: opts.id },
|
|
105
|
+
query: {},
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
if (!opts.id) {
|
|
109
|
+
throw this.consul._err(errors.Validation("id required"), req);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
utils.options(req, opts);
|
|
113
|
+
|
|
114
|
+
return await this.consul._get(req, utils.bodyItem);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
get(...args) {
|
|
118
|
+
return this.info(...args);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Creates a new token by cloning an existing token
|
|
123
|
+
*/
|
|
124
|
+
async clone(opts) {
|
|
125
|
+
if (typeof opts === "string") {
|
|
126
|
+
opts = { id: opts };
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
opts = utils.normalizeKeys(opts);
|
|
130
|
+
opts = utils.defaults(opts, this.consul._defaults);
|
|
131
|
+
|
|
132
|
+
const req = {
|
|
133
|
+
name: "acl.legacy.clone",
|
|
134
|
+
path: "/acl/clone/{id}",
|
|
135
|
+
params: { id: opts.id },
|
|
136
|
+
query: {},
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
if (!opts.id) {
|
|
140
|
+
throw this.consul._err(errors.Validation("id required"), req);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
utils.options(req, opts);
|
|
144
|
+
|
|
145
|
+
return await this.consul._put(req, utils.body);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Lists all the active tokens
|
|
150
|
+
*/
|
|
151
|
+
async list(opts) {
|
|
152
|
+
opts = utils.normalizeKeys(opts);
|
|
153
|
+
opts = utils.defaults(opts, this.consul._defaults);
|
|
154
|
+
|
|
155
|
+
const req = {
|
|
156
|
+
name: "acl.legacy.list",
|
|
157
|
+
path: "/acl/list",
|
|
158
|
+
query: {},
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
utils.options(req, opts);
|
|
162
|
+
|
|
163
|
+
return await this.consul._get(req, utils.body);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
exports.AclLegacy = AclLegacy;
|
package/lib/acl.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { AclLegacy } from "./acl/legacy";
|
|
2
|
+
import { CommonOptions, Consul } from "./consul";
|
|
3
|
+
|
|
4
|
+
interface BootstrapOptions extends CommonOptions {
|
|
5
|
+
bootstrapsecret?: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
type BootstrapResult = any;
|
|
9
|
+
|
|
10
|
+
interface ReplicationOptions extends CommonOptions {
|
|
11
|
+
dc?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface ReplicationResult {
|
|
15
|
+
Enabled: boolean;
|
|
16
|
+
Running: boolean;
|
|
17
|
+
SourceDatacenter: string;
|
|
18
|
+
ReplicatedType: "policies" | "tokens";
|
|
19
|
+
ReplicatedIndex: number;
|
|
20
|
+
ReplicatedTokenIndex: number;
|
|
21
|
+
LastSuccess: string;
|
|
22
|
+
LastError: string;
|
|
23
|
+
LastErrorMessage: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
declare class Acl {
|
|
27
|
+
constructor(consul: Consul);
|
|
28
|
+
|
|
29
|
+
consul: Consul;
|
|
30
|
+
legacy: AclLegacy;
|
|
31
|
+
|
|
32
|
+
static Legacy: typeof AclLegacy;
|
|
33
|
+
|
|
34
|
+
bootstrap(options?: BootstrapOptions): Promise<BootstrapResult>;
|
|
35
|
+
|
|
36
|
+
replication(options?: ReplicationOptions): Promise<ReplicationResult>;
|
|
37
|
+
}
|
package/lib/acl.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const AclLegacy = require("./acl/legacy").AclLegacy;
|
|
2
|
+
const utils = require("./utils");
|
|
3
|
+
|
|
4
|
+
class Acl {
|
|
5
|
+
constructor(consul) {
|
|
6
|
+
this.consul = consul;
|
|
7
|
+
this.legacy = new Acl.Legacy(consul);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Creates one-time management token if not configured
|
|
12
|
+
*/
|
|
13
|
+
async bootstrap(opts) {
|
|
14
|
+
opts = utils.normalizeKeys(opts);
|
|
15
|
+
opts = utils.defaults(opts, this.consul._defaults);
|
|
16
|
+
|
|
17
|
+
const req = {
|
|
18
|
+
name: "acl.bootstrap",
|
|
19
|
+
path: "/acl/bootstrap",
|
|
20
|
+
type: "json",
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
utils.options(req, opts);
|
|
24
|
+
|
|
25
|
+
return await this.consul._put(req, utils.body);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Check ACL replication
|
|
30
|
+
*/
|
|
31
|
+
async replication(opts) {
|
|
32
|
+
opts = utils.normalizeKeys(opts);
|
|
33
|
+
opts = utils.defaults(opts, this.consul._defaults);
|
|
34
|
+
|
|
35
|
+
const req = {
|
|
36
|
+
name: "acl.replication",
|
|
37
|
+
path: "/acl/replication",
|
|
38
|
+
query: {},
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
utils.options(req, opts);
|
|
42
|
+
|
|
43
|
+
return await this.consul._get(req, utils.body);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
Acl.Legacy = AclLegacy;
|
|
48
|
+
|
|
49
|
+
exports.Acl = Acl;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { CommonOptions, Consul } from "../consul";
|
|
2
|
+
|
|
3
|
+
interface ListOptions extends CommonOptions {
|
|
4
|
+
filter?: string;
|
|
5
|
+
ns?: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
interface Check {
|
|
9
|
+
Node: string;
|
|
10
|
+
CheckID: string;
|
|
11
|
+
Name: string;
|
|
12
|
+
Status: "passing" | "warning" | "critical";
|
|
13
|
+
Notes: string;
|
|
14
|
+
Output: string;
|
|
15
|
+
ServiceID: string;
|
|
16
|
+
ServiceName: string;
|
|
17
|
+
ServiceTags: string[];
|
|
18
|
+
Interval: string;
|
|
19
|
+
Timeout: string;
|
|
20
|
+
Type: string;
|
|
21
|
+
ExposedPort: number;
|
|
22
|
+
Definition: any;
|
|
23
|
+
Namespace: string;
|
|
24
|
+
CreateIndex: number;
|
|
25
|
+
ModifyIndex: number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
type ListResult = Record<string, Check>;
|
|
29
|
+
|
|
30
|
+
export interface CheckOptions {
|
|
31
|
+
name: string;
|
|
32
|
+
checkid?: string;
|
|
33
|
+
serviceid?: string;
|
|
34
|
+
http?: string;
|
|
35
|
+
body?: string;
|
|
36
|
+
header?: Record<string, string>;
|
|
37
|
+
disableredirects?: boolean;
|
|
38
|
+
h2ping?: string;
|
|
39
|
+
h2pingusetls?: boolean;
|
|
40
|
+
tlsskipverify?: boolean;
|
|
41
|
+
tcp?: string;
|
|
42
|
+
udp?: string;
|
|
43
|
+
args?: string[];
|
|
44
|
+
script?: string;
|
|
45
|
+
dockercontainerid?: string;
|
|
46
|
+
grpc?: string;
|
|
47
|
+
grpcusetls?: boolean;
|
|
48
|
+
shell?: string;
|
|
49
|
+
timeout: string;
|
|
50
|
+
interval?: string;
|
|
51
|
+
ttl?: string;
|
|
52
|
+
aliasnode?: string;
|
|
53
|
+
aliasservice?: string;
|
|
54
|
+
notes?: string;
|
|
55
|
+
status?: string;
|
|
56
|
+
deregistercriticalserviceafter?: string;
|
|
57
|
+
failuresbeforewarning?: number;
|
|
58
|
+
successbeforepassing?: number;
|
|
59
|
+
failuresbeforecritical?: number;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
interface RegisterOptions extends CheckOptions, CommonOptions {}
|
|
63
|
+
|
|
64
|
+
type RegisterResult = any;
|
|
65
|
+
|
|
66
|
+
interface DeregisterOptions extends CommonOptions {
|
|
67
|
+
id: string;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
type DeregisterResult = any;
|
|
71
|
+
|
|
72
|
+
interface PassOptions extends CommonOptions {
|
|
73
|
+
id: string;
|
|
74
|
+
note?: string;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
type PassResult = any;
|
|
78
|
+
|
|
79
|
+
interface WarnOptions extends CommonOptions {
|
|
80
|
+
id: string;
|
|
81
|
+
note?: string;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
type WarnResult = any;
|
|
85
|
+
|
|
86
|
+
interface FailOptions extends CommonOptions {
|
|
87
|
+
id: string;
|
|
88
|
+
note?: string;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
type FailResult = any;
|
|
92
|
+
|
|
93
|
+
declare class AgentCheck {
|
|
94
|
+
constructor(consul: Consul);
|
|
95
|
+
|
|
96
|
+
consul: Consul;
|
|
97
|
+
|
|
98
|
+
list(options?: ListOptions): Promise<ListResult>;
|
|
99
|
+
|
|
100
|
+
register(options: RegisterOptions): Promise<RegisterResult>;
|
|
101
|
+
|
|
102
|
+
deregister(options: DeregisterOptions): Promise<DeregisterResult>;
|
|
103
|
+
deregister(id: string): Promise<DeregisterResult>;
|
|
104
|
+
|
|
105
|
+
pass(options: PassOptions): Promise<PassResult>;
|
|
106
|
+
pass(id: string): Promise<PassResult>;
|
|
107
|
+
|
|
108
|
+
warn(options: WarnOptions): Promise<WarnResult>;
|
|
109
|
+
warn(id: string): Promise<WarnResult>;
|
|
110
|
+
|
|
111
|
+
fail(options: FailOptions): Promise<FailResult>;
|
|
112
|
+
fail(id: string): Promise<FailResult>;
|
|
113
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
const errors = require("../errors");
|
|
2
|
+
const utils = require("../utils");
|
|
3
|
+
|
|
4
|
+
class AgentCheck {
|
|
5
|
+
constructor(consul) {
|
|
6
|
+
this.consul = consul;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Returns the checks the 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.check.list",
|
|
18
|
+
path: "/agent/checks",
|
|
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 check
|
|
28
|
+
*/
|
|
29
|
+
async register(opts) {
|
|
30
|
+
opts = utils.normalizeKeys(opts);
|
|
31
|
+
opts = utils.defaults(opts, this.consul._defaults);
|
|
32
|
+
|
|
33
|
+
const req = {
|
|
34
|
+
name: "agent.check.register",
|
|
35
|
+
path: "/agent/check/register",
|
|
36
|
+
type: "json",
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
req.body = utils.createCheck(opts);
|
|
41
|
+
} catch (err) {
|
|
42
|
+
throw this.consul._err(errors.Validation(err.message), req);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
utils.options(req, opts);
|
|
46
|
+
|
|
47
|
+
return await this.consul._put(req, utils.empty);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Deregister a local check
|
|
52
|
+
*/
|
|
53
|
+
async deregister(opts) {
|
|
54
|
+
if (typeof opts === "string") {
|
|
55
|
+
opts = { id: opts };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
opts = utils.normalizeKeys(opts);
|
|
59
|
+
opts = utils.defaults(opts, this.consul._defaults);
|
|
60
|
+
|
|
61
|
+
const req = {
|
|
62
|
+
name: "agent.check.deregister",
|
|
63
|
+
path: "/agent/check/deregister/{id}",
|
|
64
|
+
params: { id: opts.id },
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
if (!opts.id) {
|
|
68
|
+
throw this.consul._err(errors.Validation("id required"), req);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
utils.options(req, opts);
|
|
72
|
+
|
|
73
|
+
return await this.consul._put(req, utils.empty);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Mark a local test as passing
|
|
78
|
+
*/
|
|
79
|
+
async pass(opts) {
|
|
80
|
+
if (typeof opts === "string") {
|
|
81
|
+
opts = { id: opts };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
opts = utils.normalizeKeys(opts);
|
|
85
|
+
opts = utils.defaults(opts, this.consul._defaults);
|
|
86
|
+
|
|
87
|
+
const req = {
|
|
88
|
+
name: "agent.check.pass",
|
|
89
|
+
path: "/agent/check/pass/{id}",
|
|
90
|
+
params: { id: opts.id },
|
|
91
|
+
query: {},
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
if (!opts.id) {
|
|
95
|
+
throw this.consul._err(errors.Validation("id required"), req);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (opts.note) req.query.note = opts.note;
|
|
99
|
+
|
|
100
|
+
utils.options(req, opts);
|
|
101
|
+
|
|
102
|
+
return await this.consul._put(req, utils.empty);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Mark a local test as warning
|
|
107
|
+
*/
|
|
108
|
+
async warn(opts) {
|
|
109
|
+
if (typeof opts === "string") {
|
|
110
|
+
opts = { id: opts };
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
opts = utils.normalizeKeys(opts);
|
|
114
|
+
opts = utils.defaults(opts, this.consul._defaults);
|
|
115
|
+
|
|
116
|
+
const req = {
|
|
117
|
+
name: "agent.check.warn",
|
|
118
|
+
path: "/agent/check/warn/{id}",
|
|
119
|
+
params: { id: opts.id },
|
|
120
|
+
query: {},
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
if (!opts.id) {
|
|
124
|
+
throw this.consul._err(errors.Validation("id required"), req);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (opts.note) req.query.note = opts.note;
|
|
128
|
+
|
|
129
|
+
utils.options(req, opts);
|
|
130
|
+
|
|
131
|
+
return await this.consul._put(req, utils.empty);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Mark a local test as critical
|
|
136
|
+
*/
|
|
137
|
+
async fail(opts) {
|
|
138
|
+
if (typeof opts === "string") {
|
|
139
|
+
opts = { id: opts };
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
opts = utils.normalizeKeys(opts);
|
|
143
|
+
opts = utils.defaults(opts, this.consul._defaults);
|
|
144
|
+
|
|
145
|
+
const req = {
|
|
146
|
+
name: "agent.check.fail",
|
|
147
|
+
path: "/agent/check/fail/{id}",
|
|
148
|
+
params: { id: opts.id },
|
|
149
|
+
query: {},
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
if (!opts.id) {
|
|
153
|
+
throw this.consul._err(errors.Validation("id required"), req);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (opts.note) req.query.note = opts.note;
|
|
157
|
+
|
|
158
|
+
utils.options(req, opts);
|
|
159
|
+
|
|
160
|
+
return await this.consul._put(req, utils.empty);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
exports.AgentCheck = AgentCheck;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { CommonOptions, Consul } from "../consul";
|
|
2
|
+
import { CheckOptions } from "./check";
|
|
3
|
+
|
|
4
|
+
interface ListOptions extends CommonOptions {
|
|
5
|
+
filter?: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
type ListResult = Record<string, any>;
|
|
9
|
+
|
|
10
|
+
interface RegisterConnect {
|
|
11
|
+
native?: boolean;
|
|
12
|
+
proxy?: any;
|
|
13
|
+
sidecarservice: Record<string, any>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface RegisterOptions extends CommonOptions {
|
|
17
|
+
name: string;
|
|
18
|
+
id?: string;
|
|
19
|
+
tags?: string[];
|
|
20
|
+
address?: string;
|
|
21
|
+
taggedaddresses?: Record<string, any>;
|
|
22
|
+
meta?: Record<string, string>;
|
|
23
|
+
namespace?: string;
|
|
24
|
+
port?: number;
|
|
25
|
+
kind?: string;
|
|
26
|
+
proxy?: any;
|
|
27
|
+
connect?: RegisterConnect;
|
|
28
|
+
check?: CheckOptions;
|
|
29
|
+
checks?: CheckOptions[];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
type RegisterResult = any;
|
|
33
|
+
|
|
34
|
+
interface DeregisterOptions extends CommonOptions {
|
|
35
|
+
id: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
type DeregisterResult = any;
|
|
39
|
+
|
|
40
|
+
interface MaintenanceOptions extends CommonOptions {
|
|
41
|
+
id: string;
|
|
42
|
+
enable: boolean;
|
|
43
|
+
reason?: string;
|
|
44
|
+
ns?: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
type MaintenanceResult = any;
|
|
48
|
+
|
|
49
|
+
declare class AgentService {
|
|
50
|
+
constructor(consul: Consul);
|
|
51
|
+
|
|
52
|
+
consul: Consul;
|
|
53
|
+
|
|
54
|
+
list(options?: ListOptions): Promise<ListResult>;
|
|
55
|
+
|
|
56
|
+
register(options: RegisterOptions): Promise<RegisterResult>;
|
|
57
|
+
register(name: string): Promise<RegisterResult>;
|
|
58
|
+
|
|
59
|
+
deregister(options: DeregisterOptions): Promise<DeregisterResult>;
|
|
60
|
+
deregister(id: string): Promise<DeregisterResult>;
|
|
61
|
+
|
|
62
|
+
maintenance(options: MaintenanceOptions): Promise<MaintenanceResult>;
|
|
63
|
+
}
|