event_store_client 0.1.19 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -0
- data/lib/event_store_client/broker.rb +1 -1
- data/lib/event_store_client/data_decryptor.rb +7 -7
- data/lib/event_store_client/data_encryptor.rb +5 -5
- data/lib/event_store_client/encryption_metadata.rb +1 -1
- data/lib/event_store_client/mapper/encrypted.rb +3 -3
- data/lib/event_store_client/store_adapter/api/client.rb +6 -5
- data/lib/event_store_client/store_adapter/api/connection.rb +7 -4
- data/lib/event_store_client/store_adapter/in_memory.rb +8 -4
- data/lib/event_store_client/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c833953b7c234efb592ba1c80b0b1ad920d6edfa38f712b4e0bd666c1a600a16
|
4
|
+
data.tar.gz: 56236d43242019d752ecf48243df4b077974deb41161017e5ecddbf60a120a45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 544fa64532df3c80581d1c972e96cb31d7c2cce68a056dc59165eff59df19f607e62b4b28b61eeb6ba88449a3a739227d0e1c6ffe32327ca0abe89aac325ac07
|
7
|
+
data.tar.gz: 597a9a467cf339289cea538953f42ca065324b755a8d7f3d01fa401b96bf4f567254956a66f8dec89020b86fb13423bec2925507c004147c097e7cf3e1ec054e
|
data/README.md
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
![Run tests](https://github.com/yousty/event_store_client/workflows/Run%20tests/badge.svg?branch=master&event=push)
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/event_store_client.svg)](https://badge.fury.io/rb/event_store_client)
|
3
|
+
|
1
4
|
# EventStoreClient
|
2
5
|
|
3
6
|
An easy-to use API client for connecting ruby applications with https://eventstore.org/
|
@@ -252,6 +255,11 @@ Do you want to contribute? Welcome!
|
|
252
255
|
2. Create Issue
|
253
256
|
3. Create PR ;)
|
254
257
|
|
258
|
+
### Publishing new version
|
259
|
+
|
260
|
+
1. Push commit with updated `version.rb` file to the `release` branch. The new version will be automatically pushed to [rubygems](https://rubygems.org).
|
261
|
+
2. Create release on github including change log.
|
262
|
+
|
255
263
|
## License
|
256
264
|
|
257
265
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
@@ -4,7 +4,7 @@ module EventStoreClient
|
|
4
4
|
class Broker
|
5
5
|
def call(subscriptions)
|
6
6
|
subscriptions.each do |subscription|
|
7
|
-
new_events = connection.consume_feed(subscription.stream, subscription.name)
|
7
|
+
new_events = connection.consume_feed(subscription.stream, subscription.name) || []
|
8
8
|
next if new_events.none?
|
9
9
|
new_events.each { |event| subscription.subscriber.call(event) }
|
10
10
|
end
|
@@ -8,9 +8,9 @@ module EventStoreClient
|
|
8
8
|
return decrypted_data if encryption_metadata.empty?
|
9
9
|
|
10
10
|
decrypt_attributes(
|
11
|
-
key: find_key(encryption_metadata[
|
11
|
+
key: find_key(encryption_metadata['key']),
|
12
12
|
data: decrypted_data,
|
13
|
-
attributes: encryption_metadata[
|
13
|
+
attributes: encryption_metadata['attributes']
|
14
14
|
)
|
15
15
|
end
|
16
16
|
|
@@ -21,18 +21,18 @@ module EventStoreClient
|
|
21
21
|
attr_reader :key_repository
|
22
22
|
|
23
23
|
def initialize(data:, schema:, repository:)
|
24
|
-
@decrypted_data = deep_dup(data).transform_keys!(&:
|
24
|
+
@decrypted_data = deep_dup(data).transform_keys!(&:to_s)
|
25
25
|
@key_repository = repository
|
26
|
-
@encryption_metadata = schema&.transform_keys(&:
|
26
|
+
@encryption_metadata = schema&.transform_keys(&:to_s) || {}
|
27
27
|
end
|
28
28
|
|
29
29
|
def decrypt_attributes(key:, data:, attributes:)
|
30
30
|
decrypted_text = key_repository.decrypt(
|
31
|
-
key_id: key.id, text: data[
|
31
|
+
key_id: key.id, text: data['es_encrypted'], cipher: key.cipher, iv: key.iv
|
32
32
|
)
|
33
|
-
decrypted = JSON.parse(decrypted_text).transform_keys(&:
|
33
|
+
decrypted = JSON.parse(decrypted_text).transform_keys(&:to_s)
|
34
34
|
decrypted.each { |key, value| data[key] = value if data.key?(key) }
|
35
|
-
data.delete(
|
35
|
+
data.delete('es_encrypted')
|
36
36
|
data
|
37
37
|
end
|
38
38
|
|
@@ -11,7 +11,7 @@ module EventStoreClient
|
|
11
11
|
encrypt_attributes(
|
12
12
|
key: key,
|
13
13
|
data: encrypted_data,
|
14
|
-
attributes: encryption_metadata[:attributes]
|
14
|
+
attributes: encryption_metadata[:attributes].map(&:to_s)
|
15
15
|
)
|
16
16
|
end
|
17
17
|
|
@@ -22,18 +22,18 @@ module EventStoreClient
|
|
22
22
|
attr_reader :key_repository
|
23
23
|
|
24
24
|
def initialize(data:, schema:, repository:)
|
25
|
-
@encrypted_data = deep_dup(data).transform_keys!(&:
|
25
|
+
@encrypted_data = deep_dup(data).transform_keys!(&:to_s)
|
26
26
|
@key_repository = repository
|
27
27
|
@encryption_metadata = EncryptionMetadata.new(data: data, schema: schema).call
|
28
28
|
end
|
29
29
|
|
30
30
|
def encrypt_attributes(key:, data:, attributes:)
|
31
|
-
text = JSON.generate(data.select { |hash_key, _value| attributes.include?(hash_key) })
|
31
|
+
text = JSON.generate(data.select { |hash_key, _value| attributes.include?(hash_key.to_s) })
|
32
32
|
encrypted = key_repository.encrypt(
|
33
33
|
key_id: key.id, text: text, cipher: key.cipher, iv: key.iv
|
34
34
|
)
|
35
|
-
attributes.each { |att| data[att] = 'es_encrypted' if data.key?(att) }
|
36
|
-
data[
|
35
|
+
attributes.each { |att| data[att.to_s] = 'es_encrypted' if data.key?(att.to_s) }
|
36
|
+
data['es_encrypted'] = encrypted
|
37
37
|
data
|
38
38
|
end
|
39
39
|
|
@@ -26,13 +26,13 @@ module EventStoreClient
|
|
26
26
|
event.class.respond_to?(:encryption_schema) &&
|
27
27
|
event.class.encryption_schema
|
28
28
|
)
|
29
|
-
encryptor = DataEncryptor.new(
|
29
|
+
encryptor = EventStoreClient::DataEncryptor.new(
|
30
30
|
data: event.data,
|
31
31
|
schema: encryption_schema,
|
32
32
|
repository: key_repository
|
33
33
|
)
|
34
34
|
encryptor.call
|
35
|
-
Event.new(
|
35
|
+
EventStoreClient::Event.new(
|
36
36
|
data: serializer.serialize(encryptor.encrypted_data),
|
37
37
|
metadata: serializer.serialize(
|
38
38
|
event.metadata.merge(encryption: encryptor.encryption_metadata)
|
@@ -52,7 +52,7 @@ module EventStoreClient
|
|
52
52
|
def deserialize(event)
|
53
53
|
metadata = serializer.deserialize(event.metadata)
|
54
54
|
encryption_schema = serializer.deserialize(event.metadata)['encryption']
|
55
|
-
decrypted_data = DataDecryptor.new(
|
55
|
+
decrypted_data = EventStoreClient::DataDecryptor.new(
|
56
56
|
data: serializer.deserialize(event.data),
|
57
57
|
schema: encryption_schema,
|
58
58
|
repository: key_repository
|
@@ -17,7 +17,7 @@ module EventStoreClient
|
|
17
17
|
response
|
18
18
|
end
|
19
19
|
|
20
|
-
def delete_stream(stream_name, hard_delete)
|
20
|
+
def delete_stream(stream_name, hard_delete: false)
|
21
21
|
headers = {
|
22
22
|
'ES-HardDelete' => hard_delete.to_s
|
23
23
|
}.reject { |_key, val| val.empty? }
|
@@ -84,7 +84,7 @@ module EventStoreClient
|
|
84
84
|
headers = long_poll.positive? ? { 'ES-LongPoll' => long_poll.to_s } : {}
|
85
85
|
headers['Content-Type'] = 'application/vnd.eventstore.competingatom+json'
|
86
86
|
headers['Accept'] = 'application/vnd.eventstore.competingatom+json'
|
87
|
-
headers['ES-
|
87
|
+
headers['ES-ResolveLinktos'] = resolve_links.to_s
|
88
88
|
|
89
89
|
make_request(
|
90
90
|
:get,
|
@@ -115,11 +115,12 @@ module EventStoreClient
|
|
115
115
|
|
116
116
|
private
|
117
117
|
|
118
|
-
attr_reader :endpoint, :per_page
|
118
|
+
attr_reader :endpoint, :per_page, :connection_options
|
119
119
|
|
120
|
-
def initialize(host:, port:, per_page: 20)
|
120
|
+
def initialize(host:, port:, per_page: 20, connection_options: {})
|
121
121
|
@endpoint = Endpoint.new(host: host, port: port)
|
122
122
|
@per_page = per_page
|
123
|
+
@connection_options = connection_options
|
123
124
|
end
|
124
125
|
|
125
126
|
def build_events_data(events)
|
@@ -153,7 +154,7 @@ module EventStoreClient
|
|
153
154
|
end
|
154
155
|
|
155
156
|
def connection
|
156
|
-
@connection ||= Api::Connection.new(endpoint).call
|
157
|
+
@connection ||= Api::Connection.new(endpoint, connection_options).call
|
157
158
|
end
|
158
159
|
|
159
160
|
def validate_response(resp, expected_version)
|
@@ -8,8 +8,10 @@ module EventStoreClient
|
|
8
8
|
class Connection
|
9
9
|
def call
|
10
10
|
Faraday.new(
|
11
|
-
|
12
|
-
|
11
|
+
{
|
12
|
+
url: endpoint.url,
|
13
|
+
headers: DEFAULT_HEADERS
|
14
|
+
}.merge(options)
|
13
15
|
) do |conn|
|
14
16
|
conn.basic_auth(ENV['EVENT_STORE_USER'], ENV['EVENT_STORE_PASSWORD'])
|
15
17
|
conn.adapter Faraday.default_adapter
|
@@ -18,11 +20,12 @@ module EventStoreClient
|
|
18
20
|
|
19
21
|
private
|
20
22
|
|
21
|
-
def initialize(endpoint)
|
23
|
+
def initialize(endpoint, options = {})
|
22
24
|
@endpoint = endpoint
|
25
|
+
@options = options
|
23
26
|
end
|
24
27
|
|
25
|
-
attr_reader :endpoint
|
28
|
+
attr_reader :endpoint, :options
|
26
29
|
|
27
30
|
DEFAULT_HEADERS = {
|
28
31
|
'Content-Type' => 'application/vnd.eventstore.events+json'
|
@@ -36,11 +36,15 @@ module EventStoreClient
|
|
36
36
|
Response.new(response.to_json, 200)
|
37
37
|
end
|
38
38
|
|
39
|
-
def subscribe_to_stream
|
39
|
+
def subscribe_to_stream(stream_name, subscription_name, **)
|
40
40
|
# TODO: implement method body
|
41
41
|
end
|
42
42
|
|
43
|
-
def consume_feed
|
43
|
+
def consume_feed(
|
44
|
+
stream_name,
|
45
|
+
subscription_name,
|
46
|
+
**
|
47
|
+
)
|
44
48
|
# TODO: implement method body
|
45
49
|
end
|
46
50
|
|
@@ -48,11 +52,11 @@ module EventStoreClient
|
|
48
52
|
event_store.delete(stream_name)
|
49
53
|
end
|
50
54
|
|
51
|
-
def link_to(stream_name, events)
|
55
|
+
def link_to(stream_name, events, **)
|
52
56
|
append_to_stream(stream_name, events)
|
53
57
|
end
|
54
58
|
|
55
|
-
def ack
|
59
|
+
def ack(url)
|
56
60
|
# TODO: implement method body
|
57
61
|
end
|
58
62
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: event_store_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sebastian Wilgosz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-07-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-schema
|
@@ -148,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
148
148
|
- !ruby/object:Gem::Version
|
149
149
|
version: '0'
|
150
150
|
requirements: []
|
151
|
-
rubygems_version: 3.0.
|
151
|
+
rubygems_version: 3.0.4
|
152
152
|
signing_key:
|
153
153
|
specification_version: 4
|
154
154
|
summary: Ruby integration for https://eventstore.org
|