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.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +2021 -17
  3. data/README.md +22 -9
  4. data/Rakefile +40 -1
  5. data/app/controllers/lyra/application_controller.rb +127 -0
  6. data/app/controllers/lyra/dashboard_controller.rb +33 -31
  7. data/app/controllers/lyra/flow_controller.rb +32 -34
  8. data/app/controllers/lyra/privacy_controller.rb +57 -18
  9. data/app/views/lyra/dashboard/discrepancies.html.erb +5 -5
  10. data/app/views/lyra/dashboard/index.html.erb +1 -0
  11. data/app/views/lyra/flow/crud_mapping.html.erb +1 -1
  12. data/app/views/lyra/privacy/pii_detection.html.erb +1 -1
  13. data/app/views/lyra/privacy/policy.html.erb +7 -0
  14. data/app/views/lyra/privacy/rights.html.erb +78 -0
  15. data/config/privacy_policies.rb +0 -3
  16. data/config/routes.rb +1 -0
  17. data/lib/lyra/access_log.rb +187 -6
  18. data/lib/lyra/advisory_lock.rb +236 -0
  19. data/lib/lyra/aggregate.rb +1 -1
  20. data/lib/lyra/associations/habtm_links.rb +382 -19
  21. data/lib/lyra/associations/maintenance.rb +229 -0
  22. data/lib/lyra/attribution.rb +48 -0
  23. data/lib/lyra/bypass_events.rb +446 -46
  24. data/lib/lyra/command_handler.rb +19 -14
  25. data/lib/lyra/configuration.rb +237 -10
  26. data/lib/lyra/consistency/read_your_writes.rb +4 -2
  27. data/lib/lyra/correlation.rb +121 -0
  28. data/lib/lyra/domain_events.rb +4 -0
  29. data/lib/lyra/dual_view.rb +53 -16
  30. data/lib/lyra/encrypted_attributes.rb +5 -0
  31. data/lib/lyra/engine.rb +67 -0
  32. data/lib/lyra/erasure.rb +1011 -106
  33. data/lib/lyra/event.rb +35 -1
  34. data/lib/lyra/event_data.rb +38 -0
  35. data/lib/lyra/event_flow.rb +31 -15
  36. data/lib/lyra/event_store_adapter.rb +28 -0
  37. data/lib/lyra/event_window.rb +58 -0
  38. data/lib/lyra/genesis.rb +548 -44
  39. data/lib/lyra/interceptors/association_interceptor.rb +689 -34
  40. data/lib/lyra/interceptors/crud_interceptor.rb +578 -91
  41. data/lib/lyra/internal.rb +26 -0
  42. data/lib/lyra/mode_sync.rb +51 -3
  43. data/lib/lyra/mode_transition.rb +257 -30
  44. data/lib/lyra/model_selection.rb +35 -0
  45. data/lib/lyra/own_connection.rb +17 -2
  46. data/lib/lyra/privacy/adapters/pam.rb +25 -2
  47. data/lib/lyra/privacy/gdpr_compliance.rb +314 -48
  48. data/lib/lyra/privacy/interface.rb +27 -7
  49. data/lib/lyra/privacy/subject_links.rb +143 -0
  50. data/lib/lyra/privacy/subject_records.rb +369 -0
  51. data/lib/lyra/projection.rb +7 -1
  52. data/lib/lyra/projections/async_checkpoint.rb +32 -0
  53. data/lib/lyra/projections/async_projection_job.rb +166 -23
  54. data/lib/lyra/projections/cached_joins.rb +33 -18
  55. data/lib/lyra/projections/cached_projection.rb +74 -33
  56. data/lib/lyra/projections/cached_relation.rb +3175 -321
  57. data/lib/lyra/projections/default_scopes.rb +254 -0
  58. data/lib/lyra/projections/deferred_relation.rb +23 -3
  59. data/lib/lyra/projections/event_store_reader.rb +47 -8
  60. data/lib/lyra/projections/foreign_keys.rb +92 -0
  61. data/lib/lyra/projections/lazy_projection.rb +165 -27
  62. data/lib/lyra/projections/model_projection.rb +165 -14
  63. data/lib/lyra/projections/rebuild.rb +34 -6
  64. data/lib/lyra/projections/reference_links.rb +463 -72
  65. data/lib/lyra/projections/typed_values.rb +629 -0
  66. data/lib/lyra/projections/unique_indexes.rb +595 -0
  67. data/lib/lyra/projections/uniqueness.rb +784 -0
  68. data/lib/lyra/projections/value_digest.rb +93 -0
  69. data/lib/lyra/purpose_bound_reads.rb +912 -77
  70. data/lib/lyra/repair.rb +119 -28
  71. data/lib/lyra/retention.rb +114 -8
  72. data/lib/lyra/rights/consent_store.rb +415 -0
  73. data/lib/lyra/rights/erasure_guard.rb +135 -0
  74. data/lib/lyra/rights/pending.rb +74 -0
  75. data/lib/lyra/rights/queries.rb +269 -0
  76. data/lib/lyra/rights/store.rb +512 -0
  77. data/lib/lyra/rights/subject_keys.rb +224 -0
  78. data/lib/lyra/rights.rb +281 -0
  79. data/lib/lyra/saves_without_effect.rb +69 -0
  80. data/lib/lyra/stream_tail.rb +319 -0
  81. data/lib/lyra/strict_data_access.rb +916 -106
  82. data/lib/lyra/temporal.rb +4 -2
  83. data/lib/lyra/touch_registry.rb +404 -0
  84. data/lib/lyra/verification/bypass_workflow.rb +452 -42
  85. data/lib/lyra/verification/rights_workflows.rb +170 -0
  86. data/lib/lyra/version.rb +1 -1
  87. data/lib/lyra/visualization/event_graph.rb +1 -1
  88. data/lib/lyra/visualization/timeline.rb +2 -2
  89. data/lib/lyra.rb +43 -2
  90. data/lib/tasks/lyra_mode.rake +110 -8
  91. data/lib/tasks/lyra_projections.rake +43 -2
  92. metadata +34 -4
  93. data/lib/lyra/associations/event_aware.rb +0 -224
@@ -52,6 +52,11 @@ module Lyra
52
52
  end
53
53
  end
54
54
 
55
+ # +value+ of the encrypted attribute +key+ as the log holds it: its
56
+ # ciphertext (nil stays nil). For Lyra::Erasure, which replaces a value
57
+ # in an event it has opened.
58
+ def seal_value(model_class, key, value) = encrypt(model_class, key, value)
59
+
55
60
  private
56
61
 
57
62
  def model_for(data)
data/lib/lyra/engine.rb CHANGED
@@ -53,6 +53,14 @@ module Lyra
53
53
  end
54
54
  end
55
55
 
56
+ # Rails' uniqueness validation answered from events in ES-NoProj
57
+ # (Lyra::Projections::Uniqueness); inert in other modes.
58
+ initializer "lyra.install_es_noproj_uniqueness", after: "lyra.inject_interceptors" do
59
+ ActiveSupport.on_load(:active_record) do
60
+ Lyra::Projections::Uniqueness.install!
61
+ end
62
+ end
63
+
56
64
  # Read hooks for ES-Lazy (projection_mode :lazy); inert in other modes.
57
65
  initializer "lyra.install_lazy_reads", after: "lyra.inject_interceptors" do
58
66
  ActiveSupport.on_load(:active_record) do
@@ -63,9 +71,13 @@ module Lyra
63
71
 
64
72
  # Install strict data access relation extension for update_all/delete_all
65
73
  # This intercepts bulk operations on relations (Model.where(...).update_all)
74
+ # Then the purpose-bound query hooks (Lyra::PurposeBoundReads), above
75
+ # it: a query refused for its purpose is refused before a bulk write
76
+ # snapshots or publishes anything.
66
77
  initializer "lyra.install_strict_data_access", after: "lyra.inject_interceptors" do
67
78
  ActiveSupport.on_load(:active_record) do
68
79
  ActiveRecord::Relation.prepend(Lyra::StrictDataAccessRelation)
80
+ Lyra::PurposeBoundReads.install!
69
81
  end
70
82
  end
71
83
 
@@ -84,6 +96,27 @@ module Lyra
84
96
  end
85
97
  end
86
98
 
99
+ # Lyra::Rights: the durable store for the subject's rights (Arts. 18 and
100
+ # 21) and for consent, and the subject key resolver, installed into PAM
101
+ # DSL when both are loaded (lyra/rights does it on load). At boot, after
102
+ # the application's initializers, only what is still unset is installed
103
+ # again: a store or resolver the application installed there is kept
104
+ # (its way to opt out). The resolver's cached plans go with each code
105
+ # reload.
106
+ # Each web request is a checking scope (Lyra::Rights::Middleware): the
107
+ # rights are read afresh at its first check. Jobs include
108
+ # Lyra::Rights::Job when lyra/rights loads.
109
+ initializer "lyra.rights_scope" do |app|
110
+ app.config.middleware.use Lyra::Rights::Middleware if defined?(Lyra::Rights::Middleware)
111
+ end
112
+
113
+ initializer "lyra.rights", after: :load_config_initializers do |app|
114
+ next unless defined?(Lyra::Rights)
115
+
116
+ Lyra::Rights.install!(only_unset: true)
117
+ app.config.to_prepare { Lyra::Rights::SubjectKeys.reset! }
118
+ end
119
+
87
120
  # Lyra::Correlation::Middleware and Lyra::Correlation::Job: the writes of
88
121
  # one request share a correlation, and a job's writes the one in scope
89
122
  # where it was created (config.correlate_writes).
@@ -98,6 +131,10 @@ module Lyra
98
131
  config.after_initialize do
99
132
  Lyra.booted!
100
133
  Lyra.verify_mapping! if Lyra.config.verify_mapping_at_boot?
134
+ # config.record_touches = false: refused in an application that runs
135
+ # in Hijack or event sourcing, otherwise registered (every process,
136
+ # rake tasks included). Nothing with the option on.
137
+ Lyra::TouchRegistry.boot!
101
138
  # Mode Transition Safety at boot, for the processes that serve the
102
139
  # application. Rake tasks (migrations, rake lyra:mode:check itself)
103
140
  # boot too, and must not be refused by the switch they prepare.
@@ -126,6 +163,36 @@ module Lyra
126
163
  end
127
164
  end
128
165
 
166
+ # A retention rule that can never act (:soft_delete, the strategy of
167
+ # a rule that names none, on a table with no deleted_at or
168
+ # discarded_at): a warning per model at boot, for the models enrolled
169
+ # by then (with eager loading, all of them). Lyra::Retention warns
170
+ # again in each run that skips records for it. Never stops the boot.
171
+ initializer "lyra.check_retention_rules", after: "lyra.apply_declared_models" do
172
+ config.after_initialize do
173
+ next unless Lyra.config.monitored_models.any?
174
+
175
+ Lyra::Retention.check_rules!
176
+ rescue StandardError => e
177
+ Rails.logger&.debug("Lyra: retention rules not checked at boot (#{e.class}: #{e.message})")
178
+ end
179
+ end
180
+
181
+ # ES-NoProj set by configuration rather than reached by a switch: a
182
+ # warning for each thing the switch into ES-NoProj would refuse (a
183
+ # database foreign key from an unmonitored table into a monitored one,
184
+ # a default scope it cannot evaluate), for the models enrolled by then
185
+ # (with eager loading, all of them). Never stops the boot.
186
+ initializer "lyra.check_es_noproj", after: "lyra.apply_declared_models" do
187
+ config.after_initialize do
188
+ next unless Lyra.config.monitored_models.any?
189
+
190
+ Lyra::ModeTransition.check_es_noproj!
191
+ rescue StandardError => e
192
+ Rails.logger&.debug("Lyra: ES-NoProj requirements not checked at boot (#{e.class}: #{e.message})")
193
+ end
194
+ end
195
+
129
196
  # Rails loads every lib/tasks/*.rake under an engine's root into the
130
197
  # host application. In a development checkout that root also holds its own
131
198
  # maintenance tasks (gems:, public:, stats:, ...), and the Lyra task