standard_audit 0.4.0 → 0.5.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 +23 -0
- data/README.md +2 -0
- data/lib/generators/standard_audit/install/install_generator.rb +67 -1
- data/lib/generators/standard_audit/install/templates/initializer.rb.erb +7 -4
- data/lib/standard_audit/configuration.rb +0 -18
- data/lib/standard_audit/rspec.rb +29 -0
- data/lib/standard_audit/version.rb +1 -1
- metadata +25 -11
- data/lib/standard_audit/presets/standard_id.rb +0 -22
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6dff9827071db99dfcb9dc184f3cc20d0bcfd208de8f5d41c86efff0f7e4c2be
|
|
4
|
+
data.tar.gz: 979f93e8ed8d293695337e453ade9926b553be7904617d7c61d653ef5997a3ea
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 98bf60f4d4d40d46ff28d9203c8686a5c57765a86c4c3ef1db97c59d32b27e355ac7b585730cd69865e54cf8540109c87546259ea19e4afdfa9a3510b5b52e1f
|
|
7
|
+
data.tar.gz: dda3b2376d9afcd2a61808fc79025e246365302f7b097c17a801bf47cc6a8f3e26a3e11b411dc19b31f6ebac32dc44107e92582e02813a22476be2fa1eaca32a
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,29 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.5.0] - 2026-04-29
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- CI and release workflows migrated to the shared `rarebit-one/.github` reusable workflows (`reusable-gem-ci.yml@v1`, `reusable-gem-release.yml@v1`); `.github/workflows/ci.yml` and `release.yml` are now thin shims.
|
|
15
|
+
- The `standard_audit:install` generator is now idempotent. Re-running it skips the migration when a `*_create_audit_logs.rb` file already exists in `db/migrate/`, and skips the initializer when `config/initializers/standard_audit.rb` already exists. New flags: `--skip-migration`, `--skip-initializer`, and `--force` (overwrite the existing initializer; defaults to skip without an interactive prompt).
|
|
16
|
+
|
|
17
|
+
### Removed
|
|
18
|
+
|
|
19
|
+
- **BREAKING:** Removed `Configuration#use_preset` and the `lib/standard_audit/presets/` directory. The preset pattern (`config.use_preset(:standard_id)`) created a direct dependency from `standard_audit` on a specific publisher gem, which inverted the intended dependency direction — `standard_audit` should be a generic event consumer with no knowledge of any particular publisher. Host apps should subscribe to event patterns directly:
|
|
20
|
+
```ruby
|
|
21
|
+
StandardAudit.configure do |c|
|
|
22
|
+
c.subscribe_to "standard_id.authentication.*"
|
|
23
|
+
c.subscribe_to "standard_id.session.created"
|
|
24
|
+
c.subscribe_to "standard_id.session.revoked"
|
|
25
|
+
c.subscribe_to "standard_id.session.expired"
|
|
26
|
+
c.subscribe_to "standard_id.account.*"
|
|
27
|
+
end
|
|
28
|
+
```
|
|
29
|
+
Each publisher gem documents its event namespace.
|
|
30
|
+
- **BREAKING:** Dropped support for Ruby < 4.0. `required_ruby_version` is now `>= 4.0`. Hosts must upgrade to Ruby 4.0+ before bundling this version. CI tests all four published 4.0.x patches.
|
|
31
|
+
- **BREAKING:** Dropped support for Rails < 8.0. `activerecord`, `activejob`, and `activesupport` constraints are now `>= 8.0` (was `>= 7.1`). Hosts on Rails 7.x must upgrade to Rails 8.0+ before bundling this version. Aligns with the org-wide policy of supporting Rails 8 and up.
|
|
32
|
+
|
|
10
33
|
## [0.4.0] - 2026-04-19
|
|
11
34
|
|
|
12
35
|
### Added
|
data/README.md
CHANGED
|
@@ -23,6 +23,8 @@ This creates:
|
|
|
23
23
|
- A migration for the `audit_logs` table (UUID primary keys, JSON metadata)
|
|
24
24
|
- An initializer at `config/initializers/standard_audit.rb`
|
|
25
25
|
|
|
26
|
+
The generator is idempotent — re-running it skips the migration when a `*_create_audit_logs.rb` already exists in `db/migrate/`, and skips the initializer when `config/initializers/standard_audit.rb` already exists. Pass `--skip-migration` or `--skip-initializer` to opt out of individual steps, or `--force` to overwrite the existing initializer.
|
|
27
|
+
|
|
26
28
|
## Quick Start
|
|
27
29
|
|
|
28
30
|
### 1. Subscribe to events
|
|
@@ -1,19 +1,85 @@
|
|
|
1
|
+
require "rails/generators"
|
|
2
|
+
|
|
1
3
|
module StandardAudit
|
|
2
4
|
module Generators
|
|
5
|
+
# Installs StandardAudit in a host Rails application.
|
|
6
|
+
#
|
|
7
|
+
# Creates the migration for the `audit_logs` table and writes the
|
|
8
|
+
# initializer at `config/initializers/standard_audit.rb`.
|
|
9
|
+
#
|
|
10
|
+
# Idempotent: re-running the generator will skip pieces it has already
|
|
11
|
+
# installed. Pass `--skip-*` flags to opt out of individual steps and
|
|
12
|
+
# `--force` to overwrite an existing initializer.
|
|
3
13
|
class InstallGenerator < Rails::Generators::Base
|
|
4
14
|
include Rails::Generators::Migration
|
|
5
15
|
source_root File.expand_path("templates", __dir__)
|
|
6
16
|
|
|
17
|
+
desc <<~DESC
|
|
18
|
+
Installs StandardAudit. By default this:
|
|
19
|
+
* copies a CreateAuditLogs migration into db/migrate/
|
|
20
|
+
* writes config/initializers/standard_audit.rb
|
|
21
|
+
|
|
22
|
+
Use --skip-* flags to opt out of individual steps when re-running on an
|
|
23
|
+
existing install. The generator is idempotent — already-installed
|
|
24
|
+
pieces are skipped with a clear message. Pass --force to overwrite an
|
|
25
|
+
existing initializer.
|
|
26
|
+
DESC
|
|
27
|
+
|
|
28
|
+
class_option :skip_migration, type: :boolean, default: false,
|
|
29
|
+
desc: "Do not copy the CreateAuditLogs migration into db/migrate"
|
|
30
|
+
class_option :skip_initializer, type: :boolean, default: false,
|
|
31
|
+
desc: "Do not write config/initializers/standard_audit.rb"
|
|
32
|
+
class_option :force, type: :boolean, default: false,
|
|
33
|
+
desc: "Overwrite config/initializers/standard_audit.rb if it already exists"
|
|
34
|
+
|
|
7
35
|
def self.next_migration_number(dirname)
|
|
8
36
|
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
|
9
37
|
end
|
|
10
38
|
|
|
11
39
|
def copy_migration
|
|
40
|
+
if options[:skip_migration]
|
|
41
|
+
say_status("skip", "db/migrate/*_create_audit_logs.rb (--skip-migration)", :yellow)
|
|
42
|
+
return
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
if existing_migration
|
|
46
|
+
say_status(
|
|
47
|
+
"identical",
|
|
48
|
+
"AuditLog migration already present (#{relative_migration_path(existing_migration)}), skipping",
|
|
49
|
+
:blue
|
|
50
|
+
)
|
|
51
|
+
return
|
|
52
|
+
end
|
|
53
|
+
|
|
12
54
|
migration_template "create_audit_logs.rb.erb", "db/migrate/create_audit_logs.rb"
|
|
13
55
|
end
|
|
14
56
|
|
|
15
57
|
def copy_initializer
|
|
16
|
-
|
|
58
|
+
initializer_path = "config/initializers/standard_audit.rb"
|
|
59
|
+
|
|
60
|
+
if options[:skip_initializer]
|
|
61
|
+
say_status("skip", "#{initializer_path} (--skip-initializer)", :yellow)
|
|
62
|
+
return
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
if File.exist?(File.join(destination_root, initializer_path)) && !options[:force]
|
|
66
|
+
say_status("identical", "#{initializer_path} (already exists; pass --force to overwrite)", :blue)
|
|
67
|
+
return
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
template "initializer.rb.erb", initializer_path, force: options[:force]
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
no_commands do
|
|
74
|
+
def existing_migration
|
|
75
|
+
Dir.glob(File.join(destination_root, "db/migrate/*_create_audit_logs.rb")).first
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def relative_migration_path(absolute_path)
|
|
79
|
+
Pathname.new(absolute_path).relative_path_from(Pathname.new(destination_root)).to_s
|
|
80
|
+
rescue ArgumentError
|
|
81
|
+
absolute_path
|
|
82
|
+
end
|
|
17
83
|
end
|
|
18
84
|
end
|
|
19
85
|
end
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
StandardAudit.configure do |config|
|
|
2
|
-
#
|
|
3
|
-
#
|
|
4
|
-
|
|
5
|
-
#
|
|
2
|
+
# Subscribe to ActiveSupport::Notifications / Rails.event patterns.
|
|
3
|
+
# Each gem documents its own event namespace; subscribe to whichever
|
|
4
|
+
# patterns you want audited:
|
|
5
|
+
# config.subscribe_to "standard_id.authentication.*"
|
|
6
|
+
# config.subscribe_to "standard_id.session.created"
|
|
7
|
+
# config.subscribe_to "standard_id.session.revoked"
|
|
8
|
+
# config.subscribe_to "standard_circuit.circuit.*"
|
|
6
9
|
# config.subscribe_to "audit.**"
|
|
7
10
|
|
|
8
11
|
# Actor extractor from notification payload
|
|
@@ -10,7 +10,6 @@ module StandardAudit
|
|
|
10
10
|
|
|
11
11
|
def initialize
|
|
12
12
|
@subscriptions = []
|
|
13
|
-
@applied_presets = []
|
|
14
13
|
@async = false
|
|
15
14
|
@queue_name = :default
|
|
16
15
|
@enabled = true
|
|
@@ -56,22 +55,5 @@ module StandardAudit
|
|
|
56
55
|
def subscriptions
|
|
57
56
|
@subscriptions.dup.freeze
|
|
58
57
|
end
|
|
59
|
-
|
|
60
|
-
def use_preset(name)
|
|
61
|
-
key = name.to_sym
|
|
62
|
-
return self if @applied_presets.include?(key)
|
|
63
|
-
|
|
64
|
-
preset = case key
|
|
65
|
-
when :standard_id
|
|
66
|
-
require "standard_audit/presets/standard_id"
|
|
67
|
-
StandardAudit::Presets::StandardId
|
|
68
|
-
else
|
|
69
|
-
raise ArgumentError, "Unknown preset: #{name}. Available presets: :standard_id"
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
preset.apply(self)
|
|
73
|
-
@applied_presets << key
|
|
74
|
-
self
|
|
75
|
-
end
|
|
76
58
|
end
|
|
77
59
|
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require "standard_audit"
|
|
2
|
+
|
|
3
|
+
# StandardAudit state reset between examples.
|
|
4
|
+
#
|
|
5
|
+
# - Clears the thread-local batch buffer so a spec that exits inside a
|
|
6
|
+
# `StandardAudit.batch { ... }` block (e.g. via an unhandled error or
|
|
7
|
+
# abort) cannot leak buffered records into the next example.
|
|
8
|
+
# - Resets the Configuration via `StandardAudit.reset_configuration!` so
|
|
9
|
+
# that mutations to `StandardAudit.config` (subscriptions, sensitive
|
|
10
|
+
# keys, async flag, custom resolvers, etc.) do not bleed across specs.
|
|
11
|
+
# Consumers that customise configuration must re-call
|
|
12
|
+
# `StandardAudit.configure { |c| ... }` from a `before` hook in their
|
|
13
|
+
# own suite if they need a non-default baseline.
|
|
14
|
+
#
|
|
15
|
+
# The memoized `Subscriber` and `EventSubscriber` instances are *not*
|
|
16
|
+
# torn down here — they are wired up at engine boot via initializers and
|
|
17
|
+
# rebuilding them per-example would unsubscribe from
|
|
18
|
+
# `ActiveSupport::Notifications` / `Rails.event` for the rest of the run.
|
|
19
|
+
# Specs that need to assert on subscriber behaviour should manage that
|
|
20
|
+
# locally.
|
|
21
|
+
#
|
|
22
|
+
# Intentionally `before(:example)` rather than `after(:example)` so the
|
|
23
|
+
# reset always runs even when a previous example aborted in an after hook.
|
|
24
|
+
RSpec.configure do |config|
|
|
25
|
+
config.before(:example) do
|
|
26
|
+
Thread.current[:standard_audit_batch] = nil
|
|
27
|
+
StandardAudit.reset_configuration!
|
|
28
|
+
end
|
|
29
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: standard_audit
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jaryl Sim
|
|
@@ -15,42 +15,42 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - ">="
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: '
|
|
18
|
+
version: '8.0'
|
|
19
19
|
type: :runtime
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
23
|
- - ">="
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: '
|
|
25
|
+
version: '8.0'
|
|
26
26
|
- !ruby/object:Gem::Dependency
|
|
27
27
|
name: activejob
|
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
|
29
29
|
requirements:
|
|
30
30
|
- - ">="
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
|
-
version: '
|
|
32
|
+
version: '8.0'
|
|
33
33
|
type: :runtime
|
|
34
34
|
prerelease: false
|
|
35
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
36
36
|
requirements:
|
|
37
37
|
- - ">="
|
|
38
38
|
- !ruby/object:Gem::Version
|
|
39
|
-
version: '
|
|
39
|
+
version: '8.0'
|
|
40
40
|
- !ruby/object:Gem::Dependency
|
|
41
41
|
name: activesupport
|
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|
|
43
43
|
requirements:
|
|
44
44
|
- - ">="
|
|
45
45
|
- !ruby/object:Gem::Version
|
|
46
|
-
version: '
|
|
46
|
+
version: '8.0'
|
|
47
47
|
type: :runtime
|
|
48
48
|
prerelease: false
|
|
49
49
|
version_requirements: !ruby/object:Gem::Requirement
|
|
50
50
|
requirements:
|
|
51
51
|
- - ">="
|
|
52
52
|
- !ruby/object:Gem::Version
|
|
53
|
-
version: '
|
|
53
|
+
version: '8.0'
|
|
54
54
|
- !ruby/object:Gem::Dependency
|
|
55
55
|
name: globalid
|
|
56
56
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -65,9 +65,23 @@ dependencies:
|
|
|
65
65
|
- - ">="
|
|
66
66
|
- !ruby/object:Gem::Version
|
|
67
67
|
version: '1.0'
|
|
68
|
+
- !ruby/object:Gem::Dependency
|
|
69
|
+
name: simplecov
|
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - "~>"
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: '0.22'
|
|
75
|
+
type: :development
|
|
76
|
+
prerelease: false
|
|
77
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - "~>"
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: '0.22'
|
|
68
82
|
description: StandardAudit is a standalone Rails gem for database-backed audit logging.
|
|
69
|
-
On Rails 8.1+ it subscribes to Rails.event; on
|
|
70
|
-
|
|
83
|
+
On Rails 8.1+ it subscribes to Rails.event; on Rails 8.0 it falls back to ActiveSupport::Notifications.
|
|
84
|
+
Generic, flexible, and works with any Rails application.
|
|
71
85
|
email:
|
|
72
86
|
- code@jaryl.dev
|
|
73
87
|
executables: []
|
|
@@ -94,7 +108,7 @@ files:
|
|
|
94
108
|
- lib/standard_audit/configuration.rb
|
|
95
109
|
- lib/standard_audit/engine.rb
|
|
96
110
|
- lib/standard_audit/event_subscriber.rb
|
|
97
|
-
- lib/standard_audit/
|
|
111
|
+
- lib/standard_audit/rspec.rb
|
|
98
112
|
- lib/standard_audit/subscriber.rb
|
|
99
113
|
- lib/standard_audit/version.rb
|
|
100
114
|
- lib/tasks/standard_audit_tasks.rake
|
|
@@ -113,7 +127,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
113
127
|
requirements:
|
|
114
128
|
- - ">="
|
|
115
129
|
- !ruby/object:Gem::Version
|
|
116
|
-
version: '
|
|
130
|
+
version: '4.0'
|
|
117
131
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
132
|
requirements:
|
|
119
133
|
- - ">="
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
module StandardAudit
|
|
2
|
-
module Presets
|
|
3
|
-
module StandardId
|
|
4
|
-
# Regex wildcards capture all events in a namespace. Session uses
|
|
5
|
-
# explicit strings to exclude noisy events like session.validated
|
|
6
|
-
# that fire on every authenticated request.
|
|
7
|
-
SUBSCRIPTIONS = [
|
|
8
|
-
/\Astandard_id\.authentication\./,
|
|
9
|
-
"standard_id.session.created",
|
|
10
|
-
"standard_id.session.revoked",
|
|
11
|
-
"standard_id.session.expired",
|
|
12
|
-
/\Astandard_id\.account\./,
|
|
13
|
-
/\Astandard_id\.social\./,
|
|
14
|
-
/\Astandard_id\.passwordless\./
|
|
15
|
-
].freeze
|
|
16
|
-
|
|
17
|
-
def self.apply(config)
|
|
18
|
-
SUBSCRIPTIONS.each { |pattern| config.subscribe_to(pattern) }
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|