railtracks 0.1.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.
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+
5
+ require "digest"
6
+
7
+ module Railtracks
8
+ # Deterministic digest of the model columns and registry declarations that an
9
+ # erasure plan was built from. Receipts record this value so a later reviewer
10
+ # can tell whether the plan changed after the evidence was written.
11
+ class SchemaFingerprint
12
+ def initialize(registry:, model_classes:)
13
+ @registry = registry
14
+ @model_classes = model_classes
15
+ end
16
+
17
+ def to_s
18
+ Digest::SHA256.hexdigest(JSON.generate(payload))
19
+ end
20
+
21
+ private
22
+
23
+ def payload
24
+ declarations = @model_classes.flat_map do |klass|
25
+ @registry.actions_for(klass.name).map { |d| [ d.model, d.column, d.action, d.retention ] }
26
+ end
27
+ [ @model_classes.map { |klass| [ klass.name, klass.column_names.sort ] }, declarations ]
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "openssl"
4
+
5
+ module Railtracks
6
+ # The single identifier Railtracks keeps for an erased person.
7
+ #
8
+ # A token is an HMAC over the original subject reference, so the reference
9
+ # cannot be recovered from it. Only a value that already matches the token
10
+ # format is passed through unchanged; any other string is always hashed, so a
11
+ # caller cannot smuggle a chosen "railtracks:" string into the receipts table.
12
+ module SubjectToken
13
+ FORMAT = /\Arailtracks:[0-9a-f]{64}\z/
14
+
15
+ def self.derive(secret:, subject_ref:)
16
+ raise ArgumentError, "A receipt secret is required" if secret.to_s.strip.empty?
17
+ return subject_ref if valid?(subject_ref)
18
+
19
+ "railtracks:#{OpenSSL::HMAC.hexdigest("SHA256", secret, subject_ref.to_s)}"
20
+ end
21
+
22
+ def self.valid?(value)
23
+ value.is_a?(String) && value.match?(FORMAT)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Railtracks
4
+ VERSION = "0.1.0"
5
+ end
data/lib/railtracks.rb ADDED
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "railtracks/version"
4
+ require "railtracks/registry"
5
+ require "railtracks/retention_period"
6
+ require "railtracks/schema_audit"
7
+ require "railtracks/schema_fingerprint"
8
+ require "railtracks/subject_token"
9
+ require "railtracks/configuration"
10
+ require "railtracks/retention"
11
+ require "railtracks/engine" if defined?(Rails::Engine)
12
+
13
+ module Railtracks
14
+ class << self
15
+ def configuration
16
+ @configuration ||= Configuration.new
17
+ end
18
+
19
+ # Validates and stores the configuration. An invalid retention track fails
20
+ # here, during boot, instead of at the first erasure request.
21
+ def configure
22
+ yield configuration
23
+ configuration.validate!
24
+ @retention = nil
25
+ configuration
26
+ end
27
+
28
+ # The configured retention services, or an error when the track is off.
29
+ def retention
30
+ unless configuration.track?(:retention)
31
+ raise Configuration::Error, "The retention track is not enabled"
32
+ end
33
+
34
+ @retention ||= Retention.new(configuration)
35
+ end
36
+
37
+ def reset!
38
+ @configuration = Configuration.new
39
+ @retention = nil
40
+ end
41
+ alias reset_configuration! reset!
42
+ end
43
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: railtracks
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mohamed Salahy
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: activerecord
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '7.2'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '7.2'
26
+ - !ruby/object:Gem::Dependency
27
+ name: railties
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '7.2'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '7.2'
40
+ description: Railtracks adds opt-in tracks to Rails applications. Each track provides
41
+ a guarantee Rails leaves to the application, using ActiveRecord, Railties, generators
42
+ and instrumentation rather than replacing Rails conventions.
43
+ email:
44
+ - Salahy@tutanota.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - CHANGELOG.md
50
+ - LICENSE
51
+ - README.md
52
+ - app/models/railtracks/application_record.rb
53
+ - app/models/railtracks/due_for_erasure.rb
54
+ - app/models/railtracks/erasure_execution.rb
55
+ - app/models/railtracks/erasure_receipt.rb
56
+ - app/models/railtracks/receipt_store.rb
57
+ - app/models/railtracks/recorded_erasure_execution.rb
58
+ - db/migrate/20261204000000_create_railtracks_erasure_receipts.rb
59
+ - docs/configuration.md
60
+ - docs/install.md
61
+ - docs/limits.md
62
+ - docs/migration-from-demo.md
63
+ - docs/security-model.md
64
+ - docs/upgrade.md
65
+ - lib/generators/railtracks/install/install_generator.rb
66
+ - lib/generators/railtracks/install/templates/initializer.rb
67
+ - lib/railtracks.rb
68
+ - lib/railtracks/configuration.rb
69
+ - lib/railtracks/engine.rb
70
+ - lib/railtracks/registry.rb
71
+ - lib/railtracks/retention.rb
72
+ - lib/railtracks/retention_period.rb
73
+ - lib/railtracks/schema_audit.rb
74
+ - lib/railtracks/schema_fingerprint.rb
75
+ - lib/railtracks/subject_token.rb
76
+ - lib/railtracks/version.rb
77
+ homepage: https://github.com/Sifr-Dev/Railtracks
78
+ licenses:
79
+ - MIT
80
+ metadata:
81
+ source_code_uri: https://github.com/Sifr-Dev/Railtracks
82
+ changelog_uri: https://github.com/Sifr-Dev/Railtracks/blob/main/CHANGELOG.md
83
+ documentation_uri: https://github.com/Sifr-Dev/Railtracks/tree/main/railtracks/docs
84
+ rubygems_mfa_required: 'true'
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '3.2'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubygems_version: 4.0.20
100
+ specification_version: 4
101
+ summary: Opt-in Rails tracks for data lifecycle and operational guarantees.
102
+ test_files: []