diplomat 2.0.5 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -1
- data/lib/diplomat/acl.rb +23 -32
- data/lib/diplomat/agent.rb +12 -40
- data/lib/diplomat/check.rb +46 -31
- data/lib/diplomat/datacenter.rb +6 -7
- data/lib/diplomat/error.rb +1 -0
- data/lib/diplomat/event.rb +28 -37
- data/lib/diplomat/health.rb +23 -43
- data/lib/diplomat/kv.rb +45 -53
- data/lib/diplomat/lock.rb +18 -24
- data/lib/diplomat/maintenance.rb +7 -11
- data/lib/diplomat/members.rb +3 -2
- data/lib/diplomat/node.rb +12 -23
- data/lib/diplomat/nodes.rb +6 -9
- data/lib/diplomat/query.rb +26 -61
- data/lib/diplomat/rest_client.rb +80 -44
- data/lib/diplomat/service.rb +37 -59
- data/lib/diplomat/session.rb +25 -49
- data/lib/diplomat/status.rb +6 -6
- data/lib/diplomat/version.rb +1 -1
- metadata +37 -4
data/lib/diplomat/session.rb
CHANGED
@@ -6,18 +6,14 @@ module Diplomat
|
|
6
6
|
# Create a new session
|
7
7
|
# @param value [Object] hash or json representation of the session arguments
|
8
8
|
# @param options [Hash] session options
|
9
|
-
# @param options [String] :dc datacenter to create session for
|
10
9
|
# @return [String] The sesssion id
|
11
|
-
def create(value = nil, options =
|
10
|
+
def create(value = nil, options = {})
|
12
11
|
# TODO: only certain keys are recognised in a session create request,
|
13
12
|
# should raise an error on others.
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
req.url concat_url url
|
19
|
-
req.body = (value.is_a?(String) ? value : JSON.generate(value)) unless value.nil?
|
20
|
-
end
|
13
|
+
custom_params = []
|
14
|
+
custom_params << use_named_parameter('dc', options[:dc]) if options[:dc]
|
15
|
+
data = value.is_a?(String) ? value : JSON.generate(value) unless value.nil?
|
16
|
+
raw = send_put_request(@conn, ['/v1/session/create'], options, data, custom_params)
|
21
17
|
body = JSON.parse(raw.body)
|
22
18
|
body['ID']
|
23
19
|
end
|
@@ -25,74 +21,54 @@ module Diplomat
|
|
25
21
|
# Destroy a session
|
26
22
|
# @param id [String] session id
|
27
23
|
# @param options [Hash] session options
|
28
|
-
# @param options [String] :dc datacenter to destroy session for
|
29
24
|
# @return [String] Success or failure of the session destruction
|
30
|
-
def destroy(id, options =
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
req.url concat_url url
|
36
|
-
end
|
25
|
+
def destroy(id, options = {})
|
26
|
+
custom_params = []
|
27
|
+
custom_params << use_named_parameter('dc', options[:dc]) if options[:dc]
|
28
|
+
raw = send_put_request(@conn, ["/v1/session/destroy/#{id}"], options, nil, custom_params)
|
37
29
|
raw.body
|
38
30
|
end
|
39
31
|
|
40
32
|
# List sessions
|
41
33
|
# @param options [Hash] session options
|
42
|
-
# @param options [String] :dc datacenter to list sessions
|
43
34
|
# @return [OpenStruct]
|
44
|
-
def list(options =
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
req.url concat_url url
|
50
|
-
end
|
35
|
+
def list(options = {})
|
36
|
+
custom_params = []
|
37
|
+
custom_params << use_named_parameter('dc', options[:dc]) if options[:dc]
|
38
|
+
raw = send_get_request(@conn, ['/v1/session/list'], options, custom_params)
|
51
39
|
JSON.parse(raw.body).map { |session| OpenStruct.new session }
|
52
40
|
end
|
53
41
|
|
54
42
|
# Renew session
|
55
43
|
# @param id [String] session id
|
56
44
|
# @param options [Hash] session options
|
57
|
-
# @param options [String] :dc datacenter to renew session for
|
58
45
|
# @return [OpenStruct]
|
59
|
-
def renew(id, options =
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
req.url concat_url url
|
65
|
-
end
|
46
|
+
def renew(id, options = {})
|
47
|
+
custom_params = []
|
48
|
+
custom_params << use_named_parameter('dc', options[:dc]) if options[:dc]
|
49
|
+
raw = send_put_request(@conn, ["/v1/session/renew/#{id}"], options, nil, custom_params)
|
66
50
|
JSON.parse(raw.body).map { |session| OpenStruct.new session }
|
67
51
|
end
|
68
52
|
|
69
53
|
# Session information
|
70
54
|
# @param id [String] session id
|
71
55
|
# @param options [Hash] session options
|
72
|
-
# @param options [String] :dc datacenter to renew session for
|
73
56
|
# @return [OpenStruct]
|
74
|
-
def info(id, options =
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
req.url concat_url url
|
80
|
-
end
|
57
|
+
def info(id, options = {})
|
58
|
+
custom_params = []
|
59
|
+
custom_params << use_named_parameter('dc', options[:dc]) if options[:dc]
|
60
|
+
raw = send_get_request(@conn, ["/v1/session/info/#{id}"], options, custom_params)
|
81
61
|
JSON.parse(raw.body).map { |session| OpenStruct.new session }
|
82
62
|
end
|
83
63
|
|
84
64
|
# Session information for a given node
|
85
65
|
# @param name [String] node name
|
86
66
|
# @param options [Hash] session options
|
87
|
-
# @param options [String] :dc datacenter to renew session for
|
88
67
|
# @return [OpenStruct]
|
89
|
-
def node(name, options =
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
req.url concat_url url
|
95
|
-
end
|
68
|
+
def node(name, options = {})
|
69
|
+
custom_params = []
|
70
|
+
custom_params << use_named_parameter('dc', options[:dc]) if options[:dc]
|
71
|
+
raw = send_get_request(@conn, ["/v1/session/node/#{name}"], options, custom_params)
|
96
72
|
JSON.parse(raw.body).map { |session| OpenStruct.new session }
|
97
73
|
end
|
98
74
|
end
|
data/lib/diplomat/status.rb
CHANGED
@@ -4,18 +4,18 @@ module Diplomat
|
|
4
4
|
@access_methods = %i[leader peers]
|
5
5
|
|
6
6
|
# Get the raft leader for the datacenter in which the local consul agent is running
|
7
|
+
# @param options [Hash] options parameter hash
|
7
8
|
# @return [OpenStruct] the address of the leader
|
8
|
-
def leader
|
9
|
-
|
10
|
-
ret = @conn.get concat_url url
|
9
|
+
def leader(options = {})
|
10
|
+
ret = send_get_request(@conn, ['/v1/status/leader'], options)
|
11
11
|
JSON.parse(ret.body)
|
12
12
|
end
|
13
13
|
|
14
14
|
# Get an array of Raft peers for the datacenter in which the agent is running
|
15
|
+
# @param options [Hash] options parameter hash
|
15
16
|
# @return [OpenStruct] an array of peers
|
16
|
-
def peers
|
17
|
-
|
18
|
-
ret = @conn.get concat_url url
|
17
|
+
def peers(options = {})
|
18
|
+
ret = send_get_request(@conn, ['/v1/status/peers'], options)
|
19
19
|
JSON.parse(ret.body)
|
20
20
|
end
|
21
21
|
end
|
data/lib/diplomat/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: diplomat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Hamelink
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-
|
12
|
+
date: 2019-03-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -157,6 +157,40 @@ dependencies:
|
|
157
157
|
- - "~>"
|
158
158
|
- !ruby/object:Gem::Version
|
159
159
|
version: '0.49'
|
160
|
+
- !ruby/object:Gem::Dependency
|
161
|
+
name: webmock
|
162
|
+
requirement: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
type: :development
|
168
|
+
prerelease: false
|
169
|
+
version_requirements: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
- !ruby/object:Gem::Dependency
|
175
|
+
name: deep_merge
|
176
|
+
requirement: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - "~>"
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '1.0'
|
181
|
+
- - ">="
|
182
|
+
- !ruby/object:Gem::Version
|
183
|
+
version: 1.0.1
|
184
|
+
type: :runtime
|
185
|
+
prerelease: false
|
186
|
+
version_requirements: !ruby/object:Gem::Requirement
|
187
|
+
requirements:
|
188
|
+
- - "~>"
|
189
|
+
- !ruby/object:Gem::Version
|
190
|
+
version: '1.0'
|
191
|
+
- - ">="
|
192
|
+
- !ruby/object:Gem::Version
|
193
|
+
version: 1.0.1
|
160
194
|
- !ruby/object:Gem::Dependency
|
161
195
|
name: faraday
|
162
196
|
requirement: !ruby/object:Gem::Requirement
|
@@ -224,8 +258,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
224
258
|
- !ruby/object:Gem::Version
|
225
259
|
version: '0'
|
226
260
|
requirements: []
|
227
|
-
|
228
|
-
rubygems_version: 2.7.7
|
261
|
+
rubygems_version: 3.0.3
|
229
262
|
signing_key:
|
230
263
|
specification_version: 4
|
231
264
|
summary: Diplomat is a simple wrapper for Consul
|