diplomat 2.0.5 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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 = nil)
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
- raw = @conn.put do |req|
15
- url = ['/v1/session/create']
16
- url += use_named_parameter('dc', options[:dc]) if options && options[:dc]
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 = nil)
31
- raw = @conn.put do |req|
32
- url = ["/v1/session/destroy/#{id}"]
33
- url += use_named_parameter('dc', options[:dc]) if options && options[:dc]
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 = nil)
45
- raw = @conn.get do |req|
46
- url = ['/v1/session/list']
47
- url += use_named_parameter('dc', options[:dc]) if options && options[:dc]
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 = nil)
60
- raw = @conn.put do |req|
61
- url = ["/v1/session/renew/#{id}"]
62
- url += use_named_parameter('dc', options[:dc]) if options && options[:dc]
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 = nil)
75
- raw = @conn.get do |req|
76
- url = ["/v1/session/info/#{id}"]
77
- url += use_named_parameter('dc', options[:dc]) if options && options[:dc]
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 = nil)
90
- raw = @conn.get do |req|
91
- url = ["/v1/session/node/#{name}"]
92
- url += use_named_parameter('dc', options[:dc]) if options && options[:dc]
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
@@ -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
- url = ['/v1/status/leader']
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
- url = ['/v1/status/peers']
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
@@ -1,3 +1,3 @@
1
1
  module Diplomat
2
- VERSION = '2.0.5'.freeze
2
+ VERSION = '2.1.0'.freeze
3
3
  end
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.5
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-02-26 00:00:00.000000000 Z
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
- rubyforge_project:
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