event_store_client 1.1.1 → 1.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '098a9968e45cc7aa2d8374d48658a354f9d43b6338555b115718fb89aa1288a8'
4
- data.tar.gz: cedd89ced40f1a571f12e841fd5266fc83e05e73a087a0135b74d27f6d8621eb
3
+ metadata.gz: 0bce23a0e16ce5f374964b63c3479adb7e55236465285c6dc73c9545e6507807
4
+ data.tar.gz: caac13b0506eb0323597db08303e604527475b11476b4af877f8ff6381f076eb
5
5
  SHA512:
6
- metadata.gz: 12eac04fd6a932acbf7573edbcec9a8aa8d8deb85b91ea5a8de572e4976d1964f0791e71749f2157095be60c0d0e7e7a6ace270fdbccb3dc6eeef565b25cc5d0
7
- data.tar.gz: 42579bd365d172bc63ae7bc10ff7c2e9543de5e7d69e29e3ef6d773f2cf5f595717fbdc4049d683ea5f90a6ba531cc3ec45c2533b0b4addd662c1c3c626a5c72
6
+ metadata.gz: 6d0c69349edd547872c656264c97f397edea084420ed492cd30ce7223961a6649894ba84eb9a2cc97828dc06805c30256f6f3f7346965bbdbf483447106e8a2d
7
+ data.tar.gz: 454e278dc1c5f1fd95f81d65dab0970fff87317ea8468e0da440ffc8903b85c2640c84d7b37429e133aab23d71f1d19688f8f4c332b21282a4e0163f2b79769a
@@ -38,16 +38,17 @@ module EventStoreClient
38
38
 
39
39
  requests = [request.new(options: opts)] # please notice that it's an array. Should be?
40
40
 
41
+ skip_decryption = options[:skip_decryption] || false
41
42
  service.read(requests, metadata: metadata).each do |res|
42
43
  next if res.subscription_confirmation
43
- yield deserialize_event(res.event.event) if block_given?
44
+ yield deserialize_event(res.event.event, skip_decryption: skip_decryption) if block_given?
44
45
  end
45
46
  Success()
46
47
  end
47
48
 
48
49
  private
49
50
 
50
- def deserialize_event(entry)
51
+ def deserialize_event(entry, skip_decryption: false)
51
52
  id = entry.id.string
52
53
  id = SecureRandom.uuid if id.nil? || id.empty?
53
54
 
@@ -65,7 +66,8 @@ module EventStoreClient
65
66
  type: entry.metadata['type'],
66
67
  data: data,
67
68
  metadata: metadata
68
- )
69
+ ),
70
+ skip_decryption: skip_decryption
69
71
  )
70
72
  end
71
73
  end
@@ -43,10 +43,10 @@ module EventStoreClient
43
43
  opts[:stream][:revision] = options[:start]
44
44
  end
45
45
 
46
+ skip_decryption = options[:skip_decryption] || false
46
47
  events = service.read(request.new(options: opts), metadata: metadata).map do |res|
47
48
  raise StreamNotFound if res.stream_not_found
48
-
49
- deserialize_event(res.event.event)
49
+ deserialize_event(res.event.event, skip_decryption: skip_decryption)
50
50
  end
51
51
  Success(events)
52
52
  rescue StreamNotFound
@@ -55,7 +55,7 @@ module EventStoreClient
55
55
 
56
56
  private
57
57
 
58
- def deserialize_event(entry)
58
+ def deserialize_event(entry, skip_decryption: false)
59
59
  data = (entry.data.nil? || entry.data.empty?) ? '{}' : entry.data
60
60
 
61
61
  metadata =
@@ -71,7 +71,7 @@ module EventStoreClient
71
71
  metadata: metadata
72
72
  )
73
73
 
74
- config.mapper.deserialize(event)
74
+ config.mapper.deserialize(event, skip_decryption: skip_decryption)
75
75
  end
76
76
  end
77
77
  end
@@ -28,16 +28,19 @@ module EventStoreClient
28
28
 
29
29
  ack_info = body['links'].find { |link| link['relation'] == 'ackAll' }
30
30
  return { events: [] } unless ack_info
31
+
32
+ skip_decryption = options[:skip_decryption] || false
31
33
  body['entries'].map do |entry|
32
- yield deserialize_event(entry)
34
+ yield deserialize_event(entry, skip_decryption: skip_decryption)
33
35
  end
36
+
34
37
  Ack.new(connection).call(ack_info['uri'])
35
38
  Success()
36
39
  end
37
40
 
38
41
  private
39
42
 
40
- def deserialize_event(entry)
43
+ def deserialize_event(entry, skip_decryption: false)
41
44
  event = EventStoreClient::Event.new(
42
45
  id: entry['eventId'],
43
46
  title: entry['title'],
@@ -46,7 +49,7 @@ module EventStoreClient
46
49
  metadata: entry['isMetaData'] ? entry['metaData'] : '{}'
47
50
  )
48
51
 
49
- config.mapper.deserialize(event)
52
+ config.mapper.deserialize(event, skip_decryption: skip_decryption)
50
53
  rescue EventStoreClient::DeserializedEvent::InvalidDataError
51
54
  event
52
55
  end
@@ -23,8 +23,9 @@ module EventStoreClient
23
23
 
24
24
  return Failure(:stream_not_found) unless response.success? || response.status == 404
25
25
  return Failure(:connection_failed) if response.body.nil? || response.body.empty?
26
+ skip_decryption = options[:skip_decryption] || false
26
27
  entries = JSON.parse(response.body)['entries'].map do |entry|
27
- deserialize_event(entry)
28
+ deserialize_event(entry, skip_decryption: skip_decryption)
28
29
  end.reverse
29
30
  Success(entries)
30
31
  rescue Faraday::ConnectionFailed
@@ -33,7 +34,7 @@ module EventStoreClient
33
34
 
34
35
  private
35
36
 
36
- def deserialize_event(entry)
37
+ def deserialize_event(entry, skip_decryption: false)
37
38
  event = EventStoreClient::Event.new(
38
39
  id: entry['eventId'],
39
40
  title: entry['title'],
@@ -42,7 +43,7 @@ module EventStoreClient
42
43
  metadata: entry['isMetaData'] ? entry['metaData'] : '{}'
43
44
  )
44
45
 
45
- config.mapper.deserialize(event)
46
+ config.mapper.deserialize(event, skip_decryption: skip_decryption)
46
47
  end
47
48
  end
48
49
  end
@@ -46,8 +46,9 @@ module EventStoreClient
46
46
  res = Response.new(response.to_json, 200)
47
47
 
48
48
  return [] if res.body.nil? || res.body.empty?
49
+ skip_decryption = options[:skip_decryption] || false
49
50
  events = JSON.parse(res.body)['entries'].map do |entry|
50
- deserialize_event(entry)
51
+ deserialize_event(entry, skip_decryption: skip_decryption)
51
52
  end.reverse
52
53
  Dry::Monads::Success(events)
53
54
  end
@@ -127,7 +128,7 @@ module EventStoreClient
127
128
  end
128
129
  end
129
130
 
130
- def deserialize_event(entry)
131
+ def deserialize_event(entry, skip_decryption: false)
131
132
  event = EventStoreClient::Event.new(
132
133
  id: entry['eventId'],
133
134
  title: entry['title'],
@@ -136,7 +137,7 @@ module EventStoreClient
136
137
  metadata: entry['isMetaData'] ? entry['metaData'] : '{}'
137
138
  )
138
139
 
139
- mapper.deserialize(event)
140
+ mapper.deserialize(event, skip_decryption: skip_decryption)
140
141
  end
141
142
  end
142
143
  end
@@ -9,28 +9,28 @@ module EventStoreClient
9
9
  KeyNotFoundError = Class.new(StandardError)
10
10
 
11
11
  def call
12
- return decrypted_data if encryption_metadata.empty?
12
+ return encrypted_data if encryption_metadata.empty?
13
13
 
14
14
  decrypt_attributes(
15
15
  key: find_key(encryption_metadata['key']),
16
- data: decrypted_data,
16
+ data: encrypted_data,
17
17
  attributes: encryption_metadata['attributes']
18
18
  )
19
19
  end
20
20
 
21
- attr_reader :decrypted_data, :encryption_metadata
22
-
23
21
  private
24
22
 
25
- attr_reader :key_repository
23
+ attr_reader :key_repository, :encryption_metadata, :encrypted_data
26
24
 
27
25
  def initialize(data:, schema:, repository:)
28
- @decrypted_data = deep_dup(data).transform_keys!(&:to_s)
26
+ @encrypted_data = deep_dup(data).transform_keys!(&:to_s)
29
27
  @key_repository = repository
30
28
  @encryption_metadata = schema&.transform_keys(&:to_s) || {}
31
29
  end
32
30
 
33
31
  def decrypt_attributes(key:, data:, attributes: {}) # rubocop:disable Lint/UnusedMethodArgument
32
+ return data unless key
33
+
34
34
  res = key_repository.decrypt(key: key, message: data['es_encrypted'])
35
35
  return data if res.failure?
36
36
 
@@ -42,6 +42,7 @@ module EventStoreClient
42
42
  end
43
43
 
44
44
  def deep_dup(hash)
45
+ return hash unless hash.instance_of?(Hash)
45
46
  dupl = hash.dup
46
47
  dupl.each { |k, v| dupl[k] = v.instance_of?(Hash) ? deep_dup(v) : v }
47
48
  dupl
@@ -53,8 +54,8 @@ module EventStoreClient
53
54
  key_repository.find(identifier).value!
54
55
  rescue StandardError => e
55
56
  config.error_handler&.call(e)
57
+ nil
56
58
  end
57
- raise KeyNotFoundError unless key
58
59
 
59
60
  key
60
61
  end
@@ -12,7 +12,7 @@ module EventStoreClient
12
12
  )
13
13
  end
14
14
 
15
- def deserialize(event)
15
+ def deserialize(event, **)
16
16
  metadata = serializer.deserialize(event.metadata)
17
17
  data = serializer.deserialize(event.data)
18
18
 
@@ -49,14 +49,20 @@ module EventStoreClient
49
49
  # which key should be used as an identifier.
50
50
  # *Returns*: Specific event class with all data decrypted
51
51
 
52
- def deserialize(event)
52
+ def deserialize(event, skip_decryption: false)
53
53
  metadata = serializer.deserialize(event.metadata)
54
54
  encryption_schema = serializer.deserialize(event.metadata)['encryption']
55
- decrypted_data = EventStoreClient::DataDecryptor.new(
56
- data: serializer.deserialize(event.data),
57
- schema: encryption_schema,
58
- repository: key_repository
59
- ).call
55
+
56
+ decrypted_data =
57
+ if skip_decryption
58
+ serializer.deserialize(event.data)
59
+ else
60
+ EventStoreClient::DataDecryptor.new(
61
+ data: serializer.deserialize(event.data),
62
+ schema: encryption_schema,
63
+ repository: key_repository
64
+ ).call
65
+ end
60
66
 
61
67
  event_class =
62
68
  begin
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EventStoreClient
4
- VERSION = '1.1.1'
4
+ VERSION = '1.1.2'
5
5
  end
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: event_store_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian Wilgosz
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2021-06-07 00:00:00.000000000 Z
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: 0.2.8
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.14'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.14'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: rspec
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -233,7 +247,7 @@ licenses:
233
247
  - MIT
234
248
  metadata:
235
249
  allowed_push_host: https://rubygems.org
236
- post_install_message:
250
+ post_install_message:
237
251
  rdoc_options: []
238
252
  require_paths:
239
253
  - lib
@@ -248,8 +262,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
248
262
  - !ruby/object:Gem::Version
249
263
  version: '0'
250
264
  requirements: []
251
- rubygems_version: 3.0.4
252
- signing_key:
265
+ rubygems_version: 3.1.4
266
+ signing_key:
253
267
  specification_version: 4
254
268
  summary: Ruby integration for https://eventstore.org
255
269
  test_files: []