authtrail 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b961a98fb477c8b4eeb74ee2ad5fc3ede159438538361c6d6b4dc4acee17aabf
4
- data.tar.gz: 77616ad77bce39a9223b75a289b5f4ea5c23412cdf82a76a697fdf9dad77b4f9
3
+ metadata.gz: 9481599ae1715a613d794df663c4c6a25f15bb941e0b1043f0fda8bb34841771
4
+ data.tar.gz: 42cce2b5e242e9120e7ce9699d7da7d30f61d2cefbd7c06add65182174ab8e95
5
5
  SHA512:
6
- metadata.gz: 783acd6518405cc4f28eb9480b4556b90a188690f12d1bdb388d38316a5381dd2df55d8e65d6faa87f39ce84563ba0ddba7ef17620e82c63cda171a3abe06573
7
- data.tar.gz: 676726af0dcb1e88e5970741d374420c8f219069e86032cdd6a581f12ca09bb574b2930fff196f958741bdb2aaec73998e6f3fffe4e64970ec097bf24db8514c
6
+ metadata.gz: a2facc0859a8c691b5512e95323b7d970a077fa0f7d9effa3701078344b507105fce23d383952c3f889ef941b869d7c53127da7911e1e5a5d57021c1cf603571
7
+ data.tar.gz: 49298c5c5094c5106daa8275ddf4298061a298690fef08469192429999e4cfd44b8e81f13c4148706d10795ebdf2cc3ce6642e6d6509ce1622a885b23d6e05d1
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
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
+
1
6
  ## 0.5.0 (2023-07-02)
2
7
 
3
8
  - Made Active Record and Active Job optional
data/README.md CHANGED
@@ -4,7 +4,7 @@ Track Devise login activity
4
4
 
5
5
  :tangerine: Battle-tested at [Instacart](https://www.instacart.com/opensource)
6
6
 
7
- [![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)
8
8
 
9
9
  ## Installation
10
10
 
@@ -21,7 +21,7 @@ rails generate authtrail:install --encryption=lockbox
21
21
  rails db:migrate
22
22
  ```
23
23
 
24
- To use Active Record encryption (Rails 7+, experimental), run:
24
+ To use Active Record encryption, run:
25
25
 
26
26
  ```sh
27
27
  rails generate authtrail:install --encryption=activerecord
@@ -218,29 +218,6 @@ We recommend using this in addition to Devise’s `Lockable` module and [Rack::A
218
218
 
219
219
  Check out [Hardening Devise](https://ankane.org/hardening-devise) and [Secure Rails](https://github.com/ankane/secure_rails) for more best practices.
220
220
 
221
- ## Upgrading
222
-
223
- ### 0.4.0
224
-
225
- There are two notable changes to geocoding:
226
-
227
- 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`).
228
-
229
- 2. The `geocoder` gem is now an optional dependency. To use geocoding, add it to your Gemfile:
230
-
231
- ```ruby
232
- gem "geocoder"
233
- ```
234
-
235
- ### 0.2.0
236
-
237
- To store latitude and longitude, create a migration with:
238
-
239
- ```ruby
240
- add_column :login_activities, :latitude, :float
241
- add_column :login_activities, :longitude, :float
242
- ```
243
-
244
221
  ## History
245
222
 
246
223
  View the [changelog](https://github.com/ankane/authtrail/blob/master/CHANGELOG.md)
@@ -1,3 +1,3 @@
1
1
  module AuthTrail
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
3
3
  end
data/lib/authtrail.rb CHANGED
@@ -12,6 +12,14 @@ module AuthTrail
12
12
  attr_accessor :exclude_method, :geocode, :track_method, :identity_method, :job_queue, :transform_method
13
13
  end
14
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
15
23
  self.identity_method = lambda do |request, opts, user|
16
24
  if user
17
25
  user.try(:email)
@@ -46,16 +54,7 @@ module AuthTrail
46
54
  exclude = AuthTrail.exclude_method && AuthTrail.safely(default: false) { AuthTrail.exclude_method.call(data) }
47
55
 
48
56
  unless exclude
49
- if AuthTrail.track_method
50
- AuthTrail.track_method.call(data)
51
- else
52
- login_activity = LoginActivity.new
53
- data.each do |k, v|
54
- login_activity.try("#{k}=", v)
55
- end
56
- login_activity.save!
57
- AuthTrail::GeocodeJob.perform_later(login_activity) if AuthTrail.geocode
58
- end
57
+ AuthTrail.track_method.call(data)
59
58
  end
60
59
  end
61
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.5.0
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: 2023-07-02 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,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '6.1'
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: '6.1'
26
+ version: '7'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: warden
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -69,14 +69,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
69
69
  requirements:
70
70
  - - ">="
71
71
  - !ruby/object:Gem::Version
72
- version: '3'
72
+ version: '3.1'
73
73
  required_rubygems_version: !ruby/object:Gem::Requirement
74
74
  requirements:
75
75
  - - ">="
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
78
  requirements: []
79
- rubygems_version: 3.4.10
79
+ rubygems_version: 3.5.22
80
80
  signing_key:
81
81
  specification_version: 4
82
82
  summary: Track Devise login activity