imperium 0.2.4 → 0.3.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 +5 -5
- data/build.sh +1 -1
- data/lib/imperium.rb +1 -0
- data/lib/imperium/http_client.rb +5 -4
- data/lib/imperium/kv.rb +30 -14
- data/lib/imperium/kv_delete_response.rb +34 -0
- data/lib/imperium/kv_put_response.rb +0 -3
- data/lib/imperium/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5bd55423ed578c5f67828e03fa2f543650b45ee4
|
4
|
+
data.tar.gz: 6ad6505a0763f99f72d4dbdf0cb59da6cfa47371
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6907eb064bcb3e1b4ef97c1baa871b6e983f4fd94b408a88d45e5e13e49bd87262630e57f90d85ebfcb4801c2090f4fed83f0297b9042aa639f2d548a9521f7
|
7
|
+
data.tar.gz: 8fa3313caa6f2ae61f83049b49fea64ea132c87286d57a3d2d72117ef4f0804ca8d4ea151c743f010cbef9bc698139aa1b967d40972085e9c08672c861a263fd
|
data/README.md
CHANGED
@@ -44,13 +44,13 @@ Configure:
|
|
44
44
|
Imperium.configure do |config|
|
45
45
|
# Connection values can be specified separately
|
46
46
|
config.host = 'consul.example.com'
|
47
|
-
config.port = 8585
|
47
|
+
config.port = 8585
|
48
48
|
config.ssl = false
|
49
49
|
|
50
50
|
# Or, as a url (this is equivilant to the example above).
|
51
51
|
config.url = 'http://consul.example.com:8585'
|
52
52
|
|
53
|
-
|
53
|
+
config.token = 'super-sekret-value'
|
54
54
|
end
|
55
55
|
|
56
56
|
# If you want a client that uses some other configuration values without altering
|
@@ -58,17 +58,17 @@ end
|
|
58
58
|
|
59
59
|
config = Imperium::Configuration.new(url: 'https://other-consul.example.com', token: 'foobar')
|
60
60
|
# This client will contact other-consul.example.com rather than the one configured above.
|
61
|
-
kv_client = Imperium::KV.new(config)
|
61
|
+
kv_client = Imperium::KV.new(config)
|
62
62
|
```
|
63
63
|
|
64
64
|
GET values from the KV store:
|
65
65
|
```
|
66
66
|
# Get a single value
|
67
|
-
response = Imperium::KV.get('config/single-value', :stale)
|
67
|
+
response = Imperium::KV.get('config/single-value', :stale)
|
68
68
|
response.values # => 'qux'
|
69
69
|
|
70
70
|
# Get a set of nested values
|
71
|
-
response = Imperium::KV.get('config/complex-value', :recurse)
|
71
|
+
response = Imperium::KV.get('config/complex-value', :recurse)
|
72
72
|
response.values # => {first: 'value', second: 'value'}
|
73
73
|
```
|
74
74
|
|
data/build.sh
CHANGED
data/lib/imperium.rb
CHANGED
@@ -13,6 +13,7 @@ require 'imperium/kv'
|
|
13
13
|
require 'imperium/kv_pair'
|
14
14
|
require 'imperium/kv_get_response'
|
15
15
|
require 'imperium/kv_put_response'
|
16
|
+
require 'imperium/kv_delete_response'
|
16
17
|
require 'imperium/response'
|
17
18
|
require 'imperium/service'
|
18
19
|
require 'imperium/service_check'
|
data/lib/imperium/http_client.rb
CHANGED
@@ -12,10 +12,11 @@ module Imperium
|
|
12
12
|
@driver.receive_timeout = @config.receive_timeout
|
13
13
|
end
|
14
14
|
|
15
|
-
def delete(path)
|
15
|
+
def delete(path, query: {})
|
16
16
|
wrapping_exceptions do
|
17
17
|
url = config.url.join(path)
|
18
|
-
|
18
|
+
url.query_values = query
|
19
|
+
@driver.delete(url, header: build_request_headers)
|
19
20
|
end
|
20
21
|
end
|
21
22
|
|
@@ -32,9 +33,9 @@ module Imperium
|
|
32
33
|
url = config.url.join(path)
|
33
34
|
url.query_values = query
|
34
35
|
if value.is_a?(String)
|
35
|
-
@driver.put(url, body: value)
|
36
|
+
@driver.put(url, body: value, header: build_request_headers)
|
36
37
|
else
|
37
|
-
@driver.put(url, body: JSON.generate(value))
|
38
|
+
@driver.put(url, body: JSON.generate(value), header: build_request_headers)
|
38
39
|
end
|
39
40
|
end
|
40
41
|
end
|
data/lib/imperium/kv.rb
CHANGED
@@ -15,20 +15,10 @@ module Imperium
|
|
15
15
|
default_client.put(key, value, *options)
|
16
16
|
end
|
17
17
|
|
18
|
-
#
|
19
|
-
# @
|
20
|
-
|
21
|
-
|
22
|
-
# object. If you're really serious about using this we'll probably want
|
23
|
-
# to build a wrapper around the response with some logic to simplify
|
24
|
-
# interpreting the response.
|
25
|
-
#
|
26
|
-
# @param key [String] The key to be deleted
|
27
|
-
# @param options [Array] Un-used, only here to prevent changing the method
|
28
|
-
# signature when we actually implement more advanced functionality.
|
29
|
-
# @return [HTTP::Message]
|
30
|
-
def delete(key, *options)
|
31
|
-
@http_client.delete(prefix_path(key))
|
18
|
+
# {#delete DELETE} a key using the {.default_client}
|
19
|
+
# @see #delete
|
20
|
+
def self.delete(key, *options)
|
21
|
+
default_client.delete(key, *options)
|
32
22
|
end
|
33
23
|
|
34
24
|
GET_ALLOWED_OPTIONS = %i{consistent stale recurse keys separator raw}.freeze
|
@@ -37,6 +27,9 @@ module Imperium
|
|
37
27
|
PUT_ALLOWED_OPTIONS = %i{flags cas acquire release}.freeze
|
38
28
|
private_constant :PUT_ALLOWED_OPTIONS
|
39
29
|
|
30
|
+
DELETE_ALLOWED_OPTIONS = %i{cas}.freeze
|
31
|
+
private_constant :DELETE_ALLOWED_OPTIONS
|
32
|
+
|
40
33
|
# Get the specified key/prefix using the supplied options.
|
41
34
|
#
|
42
35
|
# @example Fetching a key that is allowed to be stale.
|
@@ -111,6 +104,29 @@ module Imperium
|
|
111
104
|
KVPUTResponse.new(response, options: expanded_options)
|
112
105
|
end
|
113
106
|
|
107
|
+
# Delete the specified key
|
108
|
+
#
|
109
|
+
# @todo Decide whether to support recursive deletion by accepting the
|
110
|
+
# :recurse parameter
|
111
|
+
#
|
112
|
+
# @param key [String] The key to be created or updated.
|
113
|
+
# @param [Array<Symbol,String,Hash>] options The options for constructing
|
114
|
+
# the request
|
115
|
+
# @option options [String] :dc Specify the datacenter to use for the request
|
116
|
+
# @option options [Integer] :cas Specifies to use a Check-And-Set operation.
|
117
|
+
# This is very useful as a building block for more complex synchronization
|
118
|
+
# primitives. Unlike PUT, the index must be greater than 0 for Consul to
|
119
|
+
# take any action: a 0 index will not delete the key. If the index is
|
120
|
+
# non-zero, the key is only deleted if the index matches the ModifyIndex
|
121
|
+
# of that key.
|
122
|
+
# @return [KVDELETEResponse]
|
123
|
+
def delete(key, *options)
|
124
|
+
expanded_options = hashify_options(options)
|
125
|
+
query_params = extract_query_params(expanded_options, allowed_params: DELETE_ALLOWED_OPTIONS)
|
126
|
+
response = @http_client.delete(prefix_path(key), query: query_params)
|
127
|
+
KVDELETEResponse.new(response, options: expanded_options)
|
128
|
+
end
|
129
|
+
|
114
130
|
private
|
115
131
|
|
116
132
|
def construct_nested_hash(key_parts, value)
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require_relative 'response'
|
2
|
+
|
3
|
+
module Imperium
|
4
|
+
# KVDELETEResponse is a wrapper for the raw HTTP::Message response from the API
|
5
|
+
#
|
6
|
+
# @note This class doesn't really make sense to be instantiated outside of
|
7
|
+
# {KV#delete}
|
8
|
+
#
|
9
|
+
# @!attribute [rw] options
|
10
|
+
# @return [Hash<Symbol, Object>] The options for the get request after being
|
11
|
+
# coerced from an array to hash.
|
12
|
+
class KVDELETEResponse < Response
|
13
|
+
attr_accessor :options
|
14
|
+
|
15
|
+
def initialize(message, options: {})
|
16
|
+
super message
|
17
|
+
@options = options
|
18
|
+
end
|
19
|
+
|
20
|
+
if RUBY_VERSION < "2.4"
|
21
|
+
def success?
|
22
|
+
return @success if defined? @success
|
23
|
+
@success = (body.chomp == "true")
|
24
|
+
end
|
25
|
+
else
|
26
|
+
def success?
|
27
|
+
return @success if defined? @success
|
28
|
+
@success = JSON.parse(body)
|
29
|
+
rescue JSON::ParserError
|
30
|
+
body.empty? ? @success = false : raise
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -9,9 +9,6 @@ module Imperium
|
|
9
9
|
# @!attribute [rw] options
|
10
10
|
# @return [Hash<Symbol, Object>] The options for the get request after being
|
11
11
|
# coerced from an array to hash.
|
12
|
-
# @attribute [rw] prefix
|
13
|
-
# @return [String] The key prefix requested from the api, used to coerce the
|
14
|
-
# returned values from the API into their various shapes.
|
15
12
|
class KVPUTResponse < Response
|
16
13
|
attr_accessor :options
|
17
14
|
|
data/lib/imperium/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: imperium
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tyler Pickett
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-01-
|
11
|
+
date: 2018-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -170,6 +170,7 @@ files:
|
|
170
170
|
- lib/imperium/events.rb
|
171
171
|
- lib/imperium/http_client.rb
|
172
172
|
- lib/imperium/kv.rb
|
173
|
+
- lib/imperium/kv_delete_response.rb
|
173
174
|
- lib/imperium/kv_get_response.rb
|
174
175
|
- lib/imperium/kv_pair.rb
|
175
176
|
- lib/imperium/kv_put_response.rb
|