authtrail 0.4.3 → 0.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 00a8cfabe2cfddb7349c055c13db2b56080409058ba48813310c6218a6b34fba
4
- data.tar.gz: 59190df662382f672ad17c753d1eee6c0f8afacb68f7e082ed8766f188487d66
3
+ metadata.gz: 9481599ae1715a613d794df663c4c6a25f15bb941e0b1043f0fda8bb34841771
4
+ data.tar.gz: 42cce2b5e242e9120e7ce9699d7da7d30f61d2cefbd7c06add65182174ab8e95
5
5
  SHA512:
6
- metadata.gz: c9137421c5e8f4c91be7dae62ccc9f12a831da6ae6fb390cfca766274045135c130f3cd9b0b5178d041be1348c527f39cc1aa0c986c798634e68300ee1c5a0a7
7
- data.tar.gz: fa139b3a9df804feb52fa3823a67fb88781cefeda509d5719caf3f98c793e1aaaaecec553e8d1b1f08c03da8c4886b8e42400158e04aef12c34d404045b7b799
6
+ metadata.gz: a2facc0859a8c691b5512e95323b7d970a077fa0f7d9effa3701078344b507105fce23d383952c3f889ef941b869d7c53127da7911e1e5a5d57021c1cf603571
7
+ data.tar.gz: 49298c5c5094c5106daa8275ddf4298061a298690fef08469192429999e4cfd44b8e81f13c4148706d10795ebdf2cc3ce6642e6d6509ce1622a885b23d6e05d1
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## 0.6.0 (2024-11-11)
2
+
3
+ - Improved generator for Active Record encryption and MySQL
4
+ - Removed support for Rails < 7 and Ruby < 3.1
5
+
6
+ ## 0.5.0 (2023-07-02)
7
+
8
+ - Made Active Record and Active Job optional
9
+ - Removed support for Rails < 6.1 and Ruby < 3
10
+
1
11
  ## 0.4.3 (2022-06-12)
2
12
 
3
13
  - Updated install generator for Lockbox 1.0
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2017-2021 Andrew Kane
1
+ Copyright (c) 2017-2023 Andrew Kane
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -2,11 +2,9 @@
2
2
 
3
3
  Track Devise login activity
4
4
 
5
- **AuthTrail 0.4.0 was recently released** - see [how to upgrade](#upgrading)
6
-
7
5
  :tangerine: Battle-tested at [Instacart](https://www.instacart.com/opensource)
8
6
 
9
- [![Build Status](https://github.com/ankane/authtrail/workflows/build/badge.svg?branch=master)](https://github.com/ankane/authtrail/actions)
7
+ [![Build Status](https://github.com/ankane/authtrail/actions/workflows/build.yml/badge.svg)](https://github.com/ankane/authtrail/actions)
10
8
 
11
9
  ## Installation
12
10
 
@@ -23,7 +21,7 @@ rails generate authtrail:install --encryption=lockbox
23
21
  rails db:migrate
24
22
  ```
25
23
 
26
- To use Active Record encryption (Rails 7+, experimental), run:
24
+ To use Active Record encryption, run:
27
25
 
28
26
  ```sh
29
27
  rails generate authtrail:install --encryption=activerecord
@@ -135,13 +133,17 @@ AuthTrail.job_queue = :low_priority
135
133
 
136
134
  ### Local Geocoding
137
135
 
138
- For privacy and performance, we recommend geocoding locally. Add this line to your application’s Gemfile:
136
+ For privacy and performance, we recommend geocoding locally.
137
+
138
+ For city-level geocoding, download the [GeoLite2 City database](https://dev.maxmind.com/geoip/geoip2/geolite2/).
139
+
140
+ Add this line to your application’s Gemfile:
139
141
 
140
142
  ```ruby
141
143
  gem "maxminddb"
142
144
  ```
143
145
 
144
- For city-level geocoding, download the [GeoLite2 City database](https://dev.maxmind.com/geoip/geoip2/geolite2/) and create `config/initializers/geocoder.rb` with:
146
+ And create `config/initializers/geocoder.rb` with:
145
147
 
146
148
  ```ruby
147
149
  Geocoder.configure(
@@ -158,6 +160,12 @@ For country-level geocoding, install the `geoip-database` package. It’s preins
158
160
  sudo apt-get install geoip-database
159
161
  ```
160
162
 
163
+ Add this line to your application’s Gemfile:
164
+
165
+ ```ruby
166
+ gem "geoip"
167
+ ```
168
+
161
169
  And create `config/initializers/geocoder.rb` with:
162
170
 
163
171
  ```ruby
@@ -210,29 +218,6 @@ We recommend using this in addition to Devise’s `Lockable` module and [Rack::A
210
218
 
211
219
  Check out [Hardening Devise](https://ankane.org/hardening-devise) and [Secure Rails](https://github.com/ankane/secure_rails) for more best practices.
212
220
 
213
- ## Upgrading
214
-
215
- ### 0.4.0
216
-
217
- There are two notable changes to geocoding:
218
-
219
- 1. Geocoding is now disabled by default (this was already the case for new installations with 0.3.0+). Check out the instructions for [how to enable it](#geocoding) (you may need to create `config/initializers/authtrail.rb`).
220
-
221
- 2. The `geocoder` gem is now an optional dependency. To use geocoding, add it to your Gemfile:
222
-
223
- ```ruby
224
- gem "geocoder"
225
- ```
226
-
227
- ### 0.2.0
228
-
229
- To store latitude and longitude, create a migration with:
230
-
231
- ```ruby
232
- add_column :login_activities, :latitude, :float
233
- add_column :login_activities, :longitude, :float
234
- ```
235
-
236
221
  ## History
237
222
 
238
223
  View the [changelog](https://github.com/ankane/authtrail/blob/master/CHANGELOG.md)
@@ -1,3 +1,3 @@
1
1
  module AuthTrail
2
- VERSION = "0.4.3"
2
+ VERSION = "0.6.0"
3
3
  end
data/lib/authtrail.rb CHANGED
@@ -2,15 +2,24 @@
2
2
  require "warden"
3
3
 
4
4
  # modules
5
- require "auth_trail/engine"
6
- require "auth_trail/manager"
7
- require "auth_trail/version"
5
+ require_relative "auth_trail/manager"
6
+ require_relative "auth_trail/version"
8
7
 
9
8
  module AuthTrail
9
+ autoload :GeocodeJob, "auth_trail/geocode_job"
10
+
10
11
  class << self
11
12
  attr_accessor :exclude_method, :geocode, :track_method, :identity_method, :job_queue, :transform_method
12
13
  end
13
14
  self.geocode = false
15
+ self.track_method = lambda do |data|
16
+ login_activity = LoginActivity.new
17
+ data.each do |k, v|
18
+ login_activity.try("#{k}=", v)
19
+ end
20
+ login_activity.save!
21
+ AuthTrail::GeocodeJob.perform_later(login_activity) if AuthTrail.geocode
22
+ end
14
23
  self.identity_method = lambda do |request, opts, user|
15
24
  if user
16
25
  user.try(:email)
@@ -45,16 +54,7 @@ module AuthTrail
45
54
  exclude = AuthTrail.exclude_method && AuthTrail.safely(default: false) { AuthTrail.exclude_method.call(data) }
46
55
 
47
56
  unless exclude
48
- if AuthTrail.track_method
49
- AuthTrail.track_method.call(data)
50
- else
51
- login_activity = LoginActivity.new
52
- data.each do |k, v|
53
- login_activity.try("#{k}=", v)
54
- end
55
- login_activity.save!
56
- AuthTrail::GeocodeJob.perform_later(login_activity) if AuthTrail.geocode
57
- end
57
+ AuthTrail.track_method.call(data)
58
58
  end
59
59
  end
60
60
 
@@ -6,9 +6,7 @@ module Authtrail
6
6
  include ActiveRecord::Generators::Migration
7
7
  source_root File.join(__dir__, "templates")
8
8
 
9
- class_option :encryption, type: :string
10
- # deprecated
11
- class_option :lockbox, type: :boolean
9
+ class_option :encryption, type: :string, required: true
12
10
 
13
11
  def copy_migration
14
12
  encryption # ensure valid
@@ -39,8 +37,11 @@ module Authtrail
39
37
  when "lockbox"
40
38
  "t.text :identity_ciphertext\n t.string :identity_bidx, index: true"
41
39
  else
42
- # TODO add limit: 510 for Active Record encryption + MySQL?
43
- "t.string :identity, index: true"
40
+ if encryption == "activerecord" && mysql?
41
+ "t.string :identity, limit: 510, index: true"
42
+ else
43
+ "t.string :identity, index: true"
44
+ end
44
45
  end
45
46
  end
46
47
 
@@ -49,23 +50,14 @@ module Authtrail
49
50
  when "lockbox"
50
51
  "t.text :ip_ciphertext\n t.string :ip_bidx, index: true"
51
52
  else
52
- # TODO add limit: 510 for Active Record encryption + MySQL?
53
53
  "t.string :ip, index: true"
54
54
  end
55
55
  end
56
56
 
57
- # TODO remove default
58
57
  def encryption
59
58
  case options[:encryption]
60
59
  when "lockbox", "activerecord", "none"
61
60
  options[:encryption]
62
- when nil
63
- if options[:lockbox]
64
- # TODO deprecation warning
65
- "lockbox"
66
- else
67
- "none"
68
- end
69
61
  else
70
62
  abort "Error: encryption must be lockbox, activerecord, or none"
71
63
  end
@@ -78,6 +70,14 @@ module Authtrail
78
70
  "has_encrypted"
79
71
  end
80
72
  end
73
+
74
+ def mysql?
75
+ adapter =~ /mysql|trilogy/i
76
+ end
77
+
78
+ def adapter
79
+ ActiveRecord::Base.connection_db_config.adapter.to_s
80
+ end
81
81
  end
82
82
  end
83
83
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authtrail
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-12 00:00:00.000000000 Z
11
+ date: 2024-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -16,28 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '5.2'
19
+ version: '7'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '5.2'
27
- - !ruby/object:Gem::Dependency
28
- name: activerecord
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '5.2'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '5.2'
26
+ version: '7'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: warden
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -61,8 +47,7 @@ files:
61
47
  - CHANGELOG.md
62
48
  - LICENSE.txt
63
49
  - README.md
64
- - app/jobs/auth_trail/geocode_job.rb
65
- - lib/auth_trail/engine.rb
50
+ - lib/auth_trail/geocode_job.rb
66
51
  - lib/auth_trail/manager.rb
67
52
  - lib/auth_trail/version.rb
68
53
  - lib/authtrail.rb
@@ -84,14 +69,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
84
69
  requirements:
85
70
  - - ">="
86
71
  - !ruby/object:Gem::Version
87
- version: '2.6'
72
+ version: '3.1'
88
73
  required_rubygems_version: !ruby/object:Gem::Requirement
89
74
  requirements:
90
75
  - - ">="
91
76
  - !ruby/object:Gem::Version
92
77
  version: '0'
93
78
  requirements: []
94
- rubygems_version: 3.3.7
79
+ rubygems_version: 3.5.22
95
80
  signing_key:
96
81
  specification_version: 4
97
82
  summary: Track Devise login activity
@@ -1,7 +0,0 @@
1
- require "active_support"
2
- require "rails/engine"
3
-
4
- module AuthTrail
5
- class Engine < Rails::Engine
6
- end
7
- end
File without changes