imperium 0.3.0 → 0.4.0
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.
- checksums.yaml +5 -5
- data/lib/imperium.rb +2 -0
- data/lib/imperium/kv.rb +15 -0
- data/lib/imperium/transaction.rb +48 -0
- data/lib/imperium/transaction_response.rb +25 -0
- data/lib/imperium/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f7231972c5ebe74723a4eeb085545b3e04829d9b090350dc4768544b432f55f9
|
4
|
+
data.tar.gz: 3e7213cb2b41cacacad8124e232142b48906df5632b8d0e74e99b8d8387e5992
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb0f038f9476123ce5287d26095c7aa9fb6980a2349e063c1d9bdd284d2043a78776c79d036703c75e20573209a9ad7121263ea80d89d3101eabe01d75fe5b9b
|
7
|
+
data.tar.gz: 487de77a4b1fcebff0b021cb0ba80233a4b3d4d759886bf044142bfdea64f6f4a7dada9ee17726e3232d16fff16121dd97367ca1dc9818bf009f3364cf284b8e
|
data/lib/imperium.rb
CHANGED
@@ -17,6 +17,8 @@ require 'imperium/kv_delete_response'
|
|
17
17
|
require 'imperium/response'
|
18
18
|
require 'imperium/service'
|
19
19
|
require 'imperium/service_check'
|
20
|
+
require 'imperium/transaction'
|
21
|
+
require 'imperium/transaction_response'
|
20
22
|
require 'imperium/version'
|
21
23
|
|
22
24
|
module Imperium
|
data/lib/imperium/kv.rb
CHANGED
@@ -127,6 +127,21 @@ module Imperium
|
|
127
127
|
KVDELETEResponse.new(response, options: expanded_options)
|
128
128
|
end
|
129
129
|
|
130
|
+
# Perform operation in the transaction
|
131
|
+
#
|
132
|
+
# This is useful when having a number of statements that must be executed
|
133
|
+
# together or not at all.
|
134
|
+
#
|
135
|
+
# @yieldparam [Transaction] a Transaction instance that can be used to
|
136
|
+
# perform operations in the transaction
|
137
|
+
# @return [TransactionResponse]
|
138
|
+
def transaction
|
139
|
+
tx = Imperium::Transaction.new
|
140
|
+
yield tx
|
141
|
+
response = @http_client.put('v1/txn', tx.body)
|
142
|
+
Imperium::TransactionResponse.new(response)
|
143
|
+
end
|
144
|
+
|
130
145
|
private
|
131
146
|
|
132
147
|
def construct_nested_hash(key_parts, value)
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Imperium
|
2
|
+
# A Transaction support for KV API
|
3
|
+
class Transaction
|
4
|
+
# Initializa a new transaction containing an array of
|
5
|
+
# operations
|
6
|
+
def initialize
|
7
|
+
@operations = []
|
8
|
+
end
|
9
|
+
|
10
|
+
# {#set Set or Put} a key value pair
|
11
|
+
# @see #set
|
12
|
+
def set(key, value, flags: nil)
|
13
|
+
add_operation('set', key, value: value, flags: flags)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Get JSON object for operations
|
17
|
+
#
|
18
|
+
# @return JSON KV object
|
19
|
+
def body
|
20
|
+
@operations.to_json
|
21
|
+
end
|
22
|
+
|
23
|
+
# Add operation to a Transaction
|
24
|
+
|
25
|
+
# @param verb [string] Specifies the type of operation to perform
|
26
|
+
# @param key [string] Specifies the full path of the entry
|
27
|
+
# @param value [string] Specifies a base64-encoded blob of data.
|
28
|
+
# Values cannot be larger than 512kB.
|
29
|
+
# @param flags [int] Specifies an opaque unsigned integer that
|
30
|
+
# can be attached to each entry. Clients can choose to use this
|
31
|
+
# however makes sense for their application.
|
32
|
+
# @param index [int] Specifies an index.
|
33
|
+
# @param session [string] Specifies a session.
|
34
|
+
#
|
35
|
+
# @return list of operations to perform inside the atomic transaction
|
36
|
+
def add_operation(verb, key, value: nil, flags: nil, index: nil, session_id: nil)
|
37
|
+
kv = {
|
38
|
+
'Verb' => verb,
|
39
|
+
'Key' => key
|
40
|
+
}
|
41
|
+
kv['Value'] = Base64.encode64(value) if value
|
42
|
+
kv['Flags'] = flags if flags
|
43
|
+
kv['Index'] = index if index
|
44
|
+
kv['Session'] = session_id if session_id
|
45
|
+
@operations << { 'KV' => kv }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Imperium
|
2
|
+
# A Response is a decorator around the
|
3
|
+
# {http://www.rubydoc.info/gems/httpclient/HTTP/Message HTTP::Message} object
|
4
|
+
# returned when a transaction is made.
|
5
|
+
#
|
6
|
+
# It exposes, through a convenient API, headers common to all interactions
|
7
|
+
# with the Consul HTTP API
|
8
|
+
class TransactionResponse < Response
|
9
|
+
# Add Results as a KVPair to the response coerced body
|
10
|
+
#
|
11
|
+
# @return Imperium::KVPair
|
12
|
+
def results
|
13
|
+
coerced_body['Results'].map do |result|
|
14
|
+
KVPair.new(result['KV']) if result['KV']
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# Add Errors to the response coerced body
|
19
|
+
#
|
20
|
+
# @return the error
|
21
|
+
def errors
|
22
|
+
coerced_body['Errors']
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
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.4.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-
|
11
|
+
date: 2018-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -179,6 +179,8 @@ files:
|
|
179
179
|
- lib/imperium/service.rb
|
180
180
|
- lib/imperium/service_check.rb
|
181
181
|
- lib/imperium/testing.rb
|
182
|
+
- lib/imperium/transaction.rb
|
183
|
+
- lib/imperium/transaction_response.rb
|
182
184
|
- lib/imperium/version.rb
|
183
185
|
homepage: https://github.com/instructure/imperium
|
184
186
|
licenses:
|
@@ -200,7 +202,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
200
202
|
version: '0'
|
201
203
|
requirements: []
|
202
204
|
rubyforge_project:
|
203
|
-
rubygems_version: 2.6
|
205
|
+
rubygems_version: 2.7.6
|
204
206
|
signing_key:
|
205
207
|
specification_version: 4
|
206
208
|
summary: A powerful, easy to use, Consul client
|