orfeas_lyra 0.9.2 → 1.0.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 +4 -4
- data/CHANGELOG.md +2021 -17
- data/README.md +22 -9
- data/Rakefile +40 -1
- data/app/controllers/lyra/application_controller.rb +127 -0
- data/app/controllers/lyra/dashboard_controller.rb +33 -31
- data/app/controllers/lyra/flow_controller.rb +32 -34
- data/app/controllers/lyra/privacy_controller.rb +57 -18
- data/app/views/lyra/dashboard/discrepancies.html.erb +5 -5
- data/app/views/lyra/dashboard/index.html.erb +1 -0
- data/app/views/lyra/flow/crud_mapping.html.erb +1 -1
- data/app/views/lyra/privacy/pii_detection.html.erb +1 -1
- data/app/views/lyra/privacy/policy.html.erb +7 -0
- data/app/views/lyra/privacy/rights.html.erb +78 -0
- data/config/privacy_policies.rb +0 -3
- data/config/routes.rb +1 -0
- data/lib/lyra/access_log.rb +187 -6
- data/lib/lyra/advisory_lock.rb +236 -0
- data/lib/lyra/aggregate.rb +1 -1
- data/lib/lyra/associations/habtm_links.rb +382 -19
- data/lib/lyra/associations/maintenance.rb +229 -0
- data/lib/lyra/attribution.rb +48 -0
- data/lib/lyra/bypass_events.rb +446 -46
- data/lib/lyra/command_handler.rb +19 -14
- data/lib/lyra/configuration.rb +237 -10
- data/lib/lyra/consistency/read_your_writes.rb +4 -2
- data/lib/lyra/correlation.rb +121 -0
- data/lib/lyra/domain_events.rb +4 -0
- data/lib/lyra/dual_view.rb +53 -16
- data/lib/lyra/encrypted_attributes.rb +5 -0
- data/lib/lyra/engine.rb +67 -0
- data/lib/lyra/erasure.rb +1011 -106
- data/lib/lyra/event.rb +35 -1
- data/lib/lyra/event_data.rb +38 -0
- data/lib/lyra/event_flow.rb +31 -15
- data/lib/lyra/event_store_adapter.rb +28 -0
- data/lib/lyra/event_window.rb +58 -0
- data/lib/lyra/genesis.rb +548 -44
- data/lib/lyra/interceptors/association_interceptor.rb +689 -34
- data/lib/lyra/interceptors/crud_interceptor.rb +578 -91
- data/lib/lyra/internal.rb +26 -0
- data/lib/lyra/mode_sync.rb +51 -3
- data/lib/lyra/mode_transition.rb +257 -30
- data/lib/lyra/model_selection.rb +35 -0
- data/lib/lyra/own_connection.rb +17 -2
- data/lib/lyra/privacy/adapters/pam.rb +25 -2
- data/lib/lyra/privacy/gdpr_compliance.rb +314 -48
- data/lib/lyra/privacy/interface.rb +27 -7
- data/lib/lyra/privacy/subject_links.rb +143 -0
- data/lib/lyra/privacy/subject_records.rb +369 -0
- data/lib/lyra/projection.rb +7 -1
- data/lib/lyra/projections/async_checkpoint.rb +32 -0
- data/lib/lyra/projections/async_projection_job.rb +166 -23
- data/lib/lyra/projections/cached_joins.rb +33 -18
- data/lib/lyra/projections/cached_projection.rb +74 -33
- data/lib/lyra/projections/cached_relation.rb +3175 -321
- data/lib/lyra/projections/default_scopes.rb +254 -0
- data/lib/lyra/projections/deferred_relation.rb +23 -3
- data/lib/lyra/projections/event_store_reader.rb +47 -8
- data/lib/lyra/projections/foreign_keys.rb +92 -0
- data/lib/lyra/projections/lazy_projection.rb +165 -27
- data/lib/lyra/projections/model_projection.rb +165 -14
- data/lib/lyra/projections/rebuild.rb +34 -6
- data/lib/lyra/projections/reference_links.rb +463 -72
- data/lib/lyra/projections/typed_values.rb +629 -0
- data/lib/lyra/projections/unique_indexes.rb +595 -0
- data/lib/lyra/projections/uniqueness.rb +784 -0
- data/lib/lyra/projections/value_digest.rb +93 -0
- data/lib/lyra/purpose_bound_reads.rb +912 -77
- data/lib/lyra/repair.rb +119 -28
- data/lib/lyra/retention.rb +114 -8
- data/lib/lyra/rights/consent_store.rb +415 -0
- data/lib/lyra/rights/erasure_guard.rb +135 -0
- data/lib/lyra/rights/pending.rb +74 -0
- data/lib/lyra/rights/queries.rb +269 -0
- data/lib/lyra/rights/store.rb +512 -0
- data/lib/lyra/rights/subject_keys.rb +224 -0
- data/lib/lyra/rights.rb +281 -0
- data/lib/lyra/saves_without_effect.rb +69 -0
- data/lib/lyra/stream_tail.rb +319 -0
- data/lib/lyra/strict_data_access.rb +916 -106
- data/lib/lyra/temporal.rb +4 -2
- data/lib/lyra/touch_registry.rb +404 -0
- data/lib/lyra/verification/bypass_workflow.rb +452 -42
- data/lib/lyra/verification/rights_workflows.rb +170 -0
- data/lib/lyra/version.rb +1 -1
- data/lib/lyra/visualization/event_graph.rb +1 -1
- data/lib/lyra/visualization/timeline.rb +2 -2
- data/lib/lyra.rb +43 -2
- data/lib/tasks/lyra_mode.rake +110 -8
- data/lib/tasks/lyra_projections.rake +43 -2
- metadata +34 -4
- data/lib/lyra/associations/event_aware.rb +0 -224
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "openssl"
|
|
4
|
+
|
|
5
|
+
module Lyra
|
|
6
|
+
module Projections
|
|
7
|
+
# A keyed digest of a value, for the names Lyra gives to things that are
|
|
8
|
+
# about a value without holding it: ES-NoProj's value streams
|
|
9
|
+
# ("Model!column$<digest>", UniqueIndexes) and the advisory locks of a
|
|
10
|
+
# unique value (Uniqueness.value_lock_key), whose key text reaches the
|
|
11
|
+
# database's statement log. An unkeyed hash of an email or an IBAN is
|
|
12
|
+
# reversed by trying the likely values; this one is an HMAC-SHA256 keyed
|
|
13
|
+
# by a secret of the installation: config.value_digest_key, or by
|
|
14
|
+
# default a key derived from the application's secret_key_base
|
|
15
|
+
# (Rails.application.key_generator, with a salt of Lyra's own: every
|
|
16
|
+
# process of an application with the same secret_key_base derives the
|
|
17
|
+
# same key). Without either: KeyMissing is raised at first use, naming both
|
|
18
|
+
# settings, in every Rails environment but development and test (so a
|
|
19
|
+
# staging or preview deployment fails closed too); in development, test
|
|
20
|
+
# or without Rails a fixed key is used, with a warning once, and the digests are only as
|
|
21
|
+
# private as an unkeyed hash. Applications that share an event store
|
|
22
|
+
# (several apps, or apps with different secret_key_base) set
|
|
23
|
+
# config.value_digest_key to one value in all of them, or their value
|
|
24
|
+
# locks and streams miss each other.
|
|
25
|
+
#
|
|
26
|
+
# key_id names the key (a digest of it): ReferenceLinks stores it with
|
|
27
|
+
# each column's link checkpoint, and a column linked under another key
|
|
28
|
+
# has its value streams deleted and linked again under this one on its
|
|
29
|
+
# next use (or with bin/rails lyra:link_values). The value locks follow
|
|
30
|
+
# the key at once: every process of one installation must use the same.
|
|
31
|
+
module ValueDigest
|
|
32
|
+
# No key to digest values with, outside development and test (see above).
|
|
33
|
+
class KeyMissing < StandardError; end
|
|
34
|
+
|
|
35
|
+
SALT = "lyra/value-digest/v1"
|
|
36
|
+
HEX = 32
|
|
37
|
+
|
|
38
|
+
class << self
|
|
39
|
+
# The digest of +text+ (32 hex characters, 128 bits).
|
|
40
|
+
def hex(text) = OpenSSL::HMAC.hexdigest("SHA256", key, text.to_s)[0, HEX]
|
|
41
|
+
|
|
42
|
+
# The key's own name: a digest of it, not the key.
|
|
43
|
+
def key_id = OpenSSL::HMAC.hexdigest("SHA256", key, "#{SALT}/key-id")[0, 16]
|
|
44
|
+
|
|
45
|
+
# The key in use, derived once per configured value.
|
|
46
|
+
def key
|
|
47
|
+
configured = Lyra.config.value_digest_key
|
|
48
|
+
return @key if @key && @key_source.equal?(configured)
|
|
49
|
+
|
|
50
|
+
@key_source = configured
|
|
51
|
+
@key = configured.presence&.to_s || derived_key
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Forget the derived key (tests, a key rotation in a running process).
|
|
55
|
+
def reset!
|
|
56
|
+
@key = nil
|
|
57
|
+
@key_source = nil
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
private
|
|
61
|
+
|
|
62
|
+
def derived_key
|
|
63
|
+
app = defined?(Rails) && Rails.respond_to?(:application) ? Rails.application : nil
|
|
64
|
+
failure = nil
|
|
65
|
+
if app.respond_to?(:key_generator)
|
|
66
|
+
begin
|
|
67
|
+
return app.key_generator.generate_key(SALT, 32)
|
|
68
|
+
rescue StandardError => e
|
|
69
|
+
failure = e
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
if defined?(Rails) && Rails.respond_to?(:env) && !(Rails.env.development? || Rails.env.test?)
|
|
73
|
+
raise KeyMissing, "Lyra cannot key the digests of unique values (value streams, value locks): set " \
|
|
74
|
+
"config.value_digest_key, or the application's secret_key_base" \
|
|
75
|
+
"#{failure ? " (#{failure.class}: #{failure.message})" : ''}"
|
|
76
|
+
end
|
|
77
|
+
warn_unkeyed(failure)
|
|
78
|
+
SALT
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def warn_unkeyed(failure)
|
|
82
|
+
return if @warned
|
|
83
|
+
|
|
84
|
+
@warned = true
|
|
85
|
+
message = "Lyra: no key for the digests of unique values (config.value_digest_key, secret_key_base" \
|
|
86
|
+
"#{failure ? ": #{failure.class}" : ''}); a fixed key is used, as private as an unkeyed hash. " \
|
|
87
|
+
"Production refuses this."
|
|
88
|
+
defined?(Rails) && Rails.respond_to?(:logger) && Rails.logger ? Rails.logger.warn(message) : Kernel.warn(message)
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|