audit_loggable 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +5 -8
- data/Appraisals +4 -0
- data/CHANGELOG.md +15 -0
- data/README.md +2 -0
- data/audit_loggable.gemspec +3 -1
- data/gemfiles/rails_7.0.gemfile +7 -0
- data/lib/audit_loggable/audit_record.rb +2 -2
- data/lib/audit_loggable/configuration.rb +2 -1
- data/lib/audit_loggable/logger.rb +17 -3
- data/lib/audit_loggable/version.rb +1 -1
- data/lib/audit_loggable.rb +3 -2
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec0a5517dd3f92ad8be7051785176487c7e7fdec36762421469224bf9461eaaf
|
4
|
+
data.tar.gz: fd8d3fd6157d0b74b74df9d73d6ee8cf55fbb3be30c717b8ac2264ff5b959970
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd8ff1bcf4cfb1ea6a80d7992f13c7bc387bbf43de128b32bf6f97e35e424ad24646828648a2aacc9699db519b14d289a577cc5cce724e7a12b81860d668b60e
|
7
|
+
data.tar.gz: 3122c66ac200a2cc7d4720516596d6f4a81d3ff855f6503119cf2ad26da11c29ee8e8984a3eb508a9bfd547291afaf19c0c9b03d8c450bed16f6674ab1c2c7a5
|
data/.github/workflows/ruby.yml
CHANGED
@@ -14,18 +14,13 @@ jobs:
|
|
14
14
|
runs-on: ubuntu-latest
|
15
15
|
strategy:
|
16
16
|
matrix:
|
17
|
-
ruby: ['2.
|
18
|
-
activerecord: ['6.0', '6.1']
|
17
|
+
ruby: ['2.7', '3.0', '3.1']
|
18
|
+
activerecord: ['6.0', '6.1', '7.0']
|
19
19
|
experimental: [false]
|
20
20
|
exclude:
|
21
|
-
- ruby: '3.
|
21
|
+
- ruby: '3.1'
|
22
22
|
activerecord: '6.0'
|
23
23
|
experimental: false
|
24
|
-
include:
|
25
|
-
# waiting for a release of https://github.com/rails/rails/pull/39697
|
26
|
-
- ruby: '3.0'
|
27
|
-
activerecord: '6.0'
|
28
|
-
experimental: true
|
29
24
|
continue-on-error: ${{ matrix.experimental }}
|
30
25
|
env:
|
31
26
|
APPRAISAL: rails_${{ matrix.activerecord }}
|
@@ -40,4 +35,6 @@ jobs:
|
|
40
35
|
bundle install
|
41
36
|
bundle exec appraisal $APPRAISAL bundle install
|
42
37
|
- name: Run tests
|
38
|
+
env:
|
39
|
+
TZ: "Asia/Tokyo"
|
43
40
|
run: bundle exec appraisal $APPRAISAL rake
|
data/Appraisals
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,21 @@
|
|
1
1
|
## Unreleased
|
2
2
|
|
3
3
|
|
4
|
+
## 1.1.0 (2022-09-23)
|
5
|
+
|
6
|
+
### Changes
|
7
|
+
|
8
|
+
* Make configurable timezone of timestamp
|
9
|
+
* Change `AuditRecord#as_json` to accept the options of `Hash#as_json`
|
10
|
+
|
11
|
+
### Misc
|
12
|
+
|
13
|
+
* CI against for Rails 7.0
|
14
|
+
* CI against for Ruby 3.1
|
15
|
+
* Require MFA to release gem
|
16
|
+
* Drop support for Ruby 2.5/2.6
|
17
|
+
|
18
|
+
|
4
19
|
## 1.0.0 (2021-03-30)
|
5
20
|
|
6
21
|
* Initial release
|
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# AuditLoggable
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/audit_loggable.svg)](https://badge.fury.io/rb/audit_loggable)
|
3
4
|
[![Build](https://github.com/vividgarden/audit_loggable/actions/workflows/ruby.yml/badge.svg)](https://github.com/vividgarden/audit_loggable/actions/workflows/ruby.yml)
|
4
5
|
|
5
6
|
AuditLoggable is a Rails plugin gem that logs changes to your models. AuditLoggable can also record who made those changes.
|
@@ -43,6 +44,7 @@ Options
|
|
43
44
|
| `audit_log_shift_age` | Integer or String | Same as `shift_age` option of `Logger` class of stdlib. | `0` |
|
44
45
|
| `audit_log_shift_size` | Integer | Same as `shift_size` option of `Logger` class of stdlib. | `1048576` |
|
45
46
|
| `audit_log_shift_period_suffix` | String | Same as `shift_period_suffix` options of `Logger` class of stdlib. | `%Y%m%d` |
|
47
|
+
| `audit_log_timezone` | Enum | The timezone of timestamp. Any value of `:local` or `:utc`. | `local` |
|
46
48
|
|
47
49
|
### Extend your model by `AuditLoggable::Extension`
|
48
50
|
``` ruby
|
data/audit_loggable.gemspec
CHANGED
@@ -23,6 +23,8 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.metadata["homepage_uri"] = spec.homepage
|
24
24
|
spec.metadata["source_code_uri"] = spec.homepage
|
25
25
|
spec.metadata["changelog_uri"] = "https://github.com/vividgarden/audit_loggable/blob/main/CHANGELOG.md"
|
26
|
+
|
27
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
26
28
|
else
|
27
29
|
raise "RubyGems 2.0 or newer is required to protect against " \
|
28
30
|
"public gem pushes."
|
@@ -37,7 +39,7 @@ Gem::Specification.new do |spec|
|
|
37
39
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
38
40
|
spec.require_paths = ["lib"]
|
39
41
|
|
40
|
-
spec.required_ruby_version = ">= 2.
|
42
|
+
spec.required_ruby_version = ">= 2.7"
|
41
43
|
|
42
44
|
spec.add_dependency "activerecord", ">= 6.0"
|
43
45
|
spec.add_dependency "activesupport", ">= 6.0"
|
@@ -11,7 +11,7 @@ module AuditLoggable
|
|
11
11
|
@request_uuid = request_uuid
|
12
12
|
end
|
13
13
|
|
14
|
-
def as_json(
|
14
|
+
def as_json(options = nil)
|
15
15
|
{
|
16
16
|
auditable: { id: auditable.id, type: auditable.class.polymorphic_name },
|
17
17
|
user: user ? { id: user.id, type: user.class.polymorphic_name } : nil,
|
@@ -19,7 +19,7 @@ module AuditLoggable
|
|
19
19
|
changes: changeset.to_json, # serialize to JSON string
|
20
20
|
remote_address: remote_address,
|
21
21
|
request_uuid: request_uuid
|
22
|
-
}
|
22
|
+
}.as_json(options)
|
23
23
|
end
|
24
24
|
|
25
25
|
private
|
@@ -3,13 +3,14 @@
|
|
3
3
|
module AuditLoggable
|
4
4
|
class Configuration
|
5
5
|
attr_accessor :audit_log_path, :audit_log_shift_age, :audit_log_shift_size, :audit_log_shift_period_suffix,
|
6
|
-
:auditing_enabled
|
6
|
+
:auditing_enabled, :audit_log_timezone
|
7
7
|
|
8
8
|
def initialize
|
9
9
|
self.auditing_enabled = true
|
10
10
|
self.audit_log_shift_age = 0
|
11
11
|
self.audit_log_shift_size = 1024 * 1024
|
12
12
|
self.audit_log_shift_period_suffix = "%Y%m%d"
|
13
|
+
self.audit_log_timezone = :local
|
13
14
|
end
|
14
15
|
end
|
15
16
|
end
|
@@ -5,8 +5,22 @@ require "logger"
|
|
5
5
|
module AuditLoggable
|
6
6
|
class Logger
|
7
7
|
class JSONFormatter < ::Logger::Formatter
|
8
|
+
attr_reader :timezone
|
9
|
+
|
10
|
+
def initialize(timezone:)
|
11
|
+
raise ArgumentError unless %i[utc local].include? timezone
|
12
|
+
|
13
|
+
@timezone = timezone
|
14
|
+
end
|
15
|
+
|
8
16
|
def call(_severity, time, _progname, message)
|
9
|
-
|
17
|
+
timestamp =
|
18
|
+
case timezone
|
19
|
+
when :utc then time.getutc
|
20
|
+
when :local then time.getlocal
|
21
|
+
end
|
22
|
+
|
23
|
+
h = { timestamp: timestamp, record: message }
|
10
24
|
"#{h.to_json}\n"
|
11
25
|
end
|
12
26
|
end
|
@@ -20,8 +34,8 @@ module AuditLoggable
|
|
20
34
|
end
|
21
35
|
|
22
36
|
class InternalLogger < ::Logger
|
23
|
-
def initialize(logdev, shift_age:, shift_size:, shift_period_suffix:)
|
24
|
-
super(nil, level: :info, formatter: JSONFormatter.new)
|
37
|
+
def initialize(logdev, shift_age:, shift_size:, shift_period_suffix:, timezone:)
|
38
|
+
super(nil, level: :info, formatter: JSONFormatter.new(timezone: timezone))
|
25
39
|
|
26
40
|
return unless logdev
|
27
41
|
|
data/lib/audit_loggable.rb
CHANGED
@@ -21,7 +21,7 @@ module AuditLoggable
|
|
21
21
|
attr_reader :logger
|
22
22
|
|
23
23
|
delegate :audit_log_path, :audit_log_shift_age, :audit_log_shift_size, :audit_log_shift_period_suffix,
|
24
|
-
:auditing_enabled,
|
24
|
+
:auditing_enabled, :audit_log_timezone,
|
25
25
|
to: :configuration
|
26
26
|
|
27
27
|
def configure
|
@@ -40,7 +40,8 @@ module AuditLoggable
|
|
40
40
|
self.audit_log_path,
|
41
41
|
shift_age: self.audit_log_shift_age,
|
42
42
|
shift_size: self.audit_log_shift_size,
|
43
|
-
shift_period_suffix: self.audit_log_shift_period_suffix
|
43
|
+
shift_period_suffix: self.audit_log_shift_period_suffix,
|
44
|
+
timezone: self.audit_log_timezone
|
44
45
|
)
|
45
46
|
end
|
46
47
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: audit_loggable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuji Hanamura
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -144,6 +144,7 @@ files:
|
|
144
144
|
- bin/setup
|
145
145
|
- gemfiles/rails_6.0.gemfile
|
146
146
|
- gemfiles/rails_6.1.gemfile
|
147
|
+
- gemfiles/rails_7.0.gemfile
|
147
148
|
- lib/audit_loggable.rb
|
148
149
|
- lib/audit_loggable/audit_record.rb
|
149
150
|
- lib/audit_loggable/audit_record_set.rb
|
@@ -162,6 +163,7 @@ metadata:
|
|
162
163
|
homepage_uri: https://github.com/vividgarden/audit_loggable
|
163
164
|
source_code_uri: https://github.com/vividgarden/audit_loggable
|
164
165
|
changelog_uri: https://github.com/vividgarden/audit_loggable/blob/main/CHANGELOG.md
|
166
|
+
rubygems_mfa_required: 'true'
|
165
167
|
post_install_message:
|
166
168
|
rdoc_options: []
|
167
169
|
require_paths:
|
@@ -170,14 +172,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
170
172
|
requirements:
|
171
173
|
- - ">="
|
172
174
|
- !ruby/object:Gem::Version
|
173
|
-
version: '2.
|
175
|
+
version: '2.7'
|
174
176
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
175
177
|
requirements:
|
176
178
|
- - ">="
|
177
179
|
- !ruby/object:Gem::Version
|
178
180
|
version: '0'
|
179
181
|
requirements: []
|
180
|
-
rubygems_version: 3.
|
182
|
+
rubygems_version: 3.3.7
|
181
183
|
signing_key:
|
182
184
|
specification_version: 4
|
183
185
|
summary: Log changes to your models
|