lockbox 0.6.0 → 0.6.1

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: 77945cdf065bda9282a4a9cbffd77ebe518bcbe11c3e3ccaa91768bd1579f94c
4
- data.tar.gz: ab052f812a91e1620dcc52ac578006b55e84d5aae1770ecb5c6c89c5119f9073
3
+ metadata.gz: 723ecf0e8367d053e2e80afddfa954559901f1b8c44d3a7cdb3ad562b3f5135a
4
+ data.tar.gz: 6c512616214fa1fdca743539769e1d2bd5f91135337a904b89ba58273dc9dbc5
5
5
  SHA512:
6
- metadata.gz: 8223d89af7efa1e4192c48512a45177d877df2c1878da425b05bf4e2b066c1f3a413b57f8f0fbdc73a04f000db191bfde2ef8bb0319c4bce7eee6a1985a3771f
7
- data.tar.gz: 7bcb4b647f4abdc8141c571441ce1c8e47b5864aee3e043cd7f620ca7f9abc208ddb1134ac6f35700c73a30f934c56169ff5bca235ba32faba4a0d2325bc926a
6
+ metadata.gz: 440177ac7cbe84f4e20eeedffe3045060debab17f178631bcba0b631e2e4c656bce1c0977f3af9dc84ce06788cf370626fed9053d3a4503632bc3daa0b6ab43d
7
+ data.tar.gz: ab23683aa75ff078b88cdfb65f29564691f5785b49549fa1d9286baf11a9959f7d49f0a21a7c84d10dd7d181c8affd05ca739769cdbe68193e4fb211f9a932af
@@ -1,3 +1,9 @@
1
+ ## 0.6.1 (2020-12-03)
2
+
3
+ - Added integration with Rails credentials
4
+ - Fixed in place changes for Active Record 6.1
5
+ - Fixed error with `content_type` method for CarrierWave < 2
6
+
1
7
  ## 0.6.0 (2020-12-03)
2
8
 
3
9
  - Added `encrypted` flag to Active Storage metadata
data/README.md CHANGED
@@ -35,10 +35,17 @@ Set the following environment variable with your key (you can use this one in de
35
35
  LOCKBOX_MASTER_KEY=0000000000000000000000000000000000000000000000000000000000000000
36
36
  ```
37
37
 
38
+ or add it to your credentials for each environment (`rails credentials:edit --environment <env>` for Rails 6+)
39
+
40
+ ```yml
41
+ lockbox:
42
+ master_key: "0000000000000000000000000000000000000000000000000000000000000000"
43
+ ```
44
+
38
45
  or create `config/initializers/lockbox.rb` with something like
39
46
 
40
47
  ```ruby
41
- Lockbox.master_key = Rails.application.credentials.lockbox_master_key
48
+ Lockbox.master_key = Rails.application.credentials.lockbox[:master_key]
42
49
  ```
43
50
 
44
51
  Then follow the instructions below for the data you want to encrypt.
@@ -27,6 +27,11 @@ end
27
27
 
28
28
  if defined?(ActiveSupport.on_load)
29
29
  ActiveSupport.on_load(:active_record) do
30
+ # TODO raise error in 0.7.0
31
+ if ActiveRecord::VERSION::STRING.to_f <= 5.0
32
+ warn "Active Record version (#{ActiveRecord::VERSION::STRING}) not supported in this version of Lockbox (#{Lockbox::VERSION})"
33
+ end
34
+
30
35
  extend Lockbox::Model
31
36
  extend Lockbox::Model::Attached
32
37
  ActiveRecord::Calculations.prepend Lockbox::Calculations
@@ -32,9 +32,14 @@ module Lockbox
32
32
  read.bytesize
33
33
  end
34
34
 
35
- # based on CarrierWave::SanitizedFile#mime_magic_content_type
36
35
  def content_type
37
- MimeMagic.by_magic(read).try(:type) || "invalid/invalid"
36
+ if CarrierWave::VERSION.to_i >= 2
37
+ # based on CarrierWave::SanitizedFile#mime_magic_content_type
38
+ MimeMagic.by_magic(read).try(:type) || "invalid/invalid"
39
+ else
40
+ # uses filename
41
+ super
42
+ end
38
43
  end
39
44
 
40
45
  # disable processing since already processed
@@ -98,7 +103,10 @@ module Lockbox
98
103
  end
99
104
 
100
105
  if CarrierWave::VERSION.to_i > 2
101
- raise "CarrierWave version not supported in this version of Lockbox: #{CarrierWave::VERSION}"
106
+ raise "CarrierWave version (#{CarrierWave::VERSION}) not supported in this version of Lockbox (#{Lockbox::VERSION})"
107
+ elsif CarrierWave::VERSION.to_i < 1
108
+ # TODO raise error in 0.7.0
109
+ warn "CarrierWave version (#{CarrierWave::VERSION}) not supported in this version of Lockbox (#{Lockbox::VERSION})"
102
110
  end
103
111
 
104
112
  CarrierWave::Uploader::Base.extend(Lockbox::CarrierWaveExtensions)
@@ -247,6 +247,18 @@ module Lockbox
247
247
  else
248
248
  attribute name, :string
249
249
  end
250
+ else
251
+ # hack for Active Record 6.1
252
+ # to set string type after serialize
253
+ # otherwise, type gets set to ActiveModel::Type::Value
254
+ # which always returns false for changed_in_place?
255
+ # earlier versions of Active Record take the previous code path
256
+ if ActiveRecord::VERSION::STRING.to_f >= 6.1 && attributes_to_define_after_schema_loads[name.to_s].first.is_a?(Proc)
257
+ attribute_type = attributes_to_define_after_schema_loads[name.to_s].first.call
258
+ if attribute_type.is_a?(ActiveRecord::Type::Serialized) && attribute_type.subtype.nil?
259
+ attribute name, ActiveRecord::Type::Serialized.new(ActiveRecord::Type::String.new, attribute_type.coder)
260
+ end
261
+ end
250
262
  end
251
263
 
252
264
  define_method("#{name}_was") do
@@ -1,6 +1,10 @@
1
1
  module Lockbox
2
2
  class Railtie < Rails::Railtie
3
3
  initializer "lockbox" do |app|
4
+ if defined?(Rails.application.credentials)
5
+ Lockbox.master_key ||= Rails.application.credentials.dig(:lockbox, :master_key)
6
+ end
7
+
4
8
  require "lockbox/carrier_wave_extensions" if defined?(CarrierWave)
5
9
 
6
10
  if defined?(ActiveStorage)
@@ -1,3 +1,3 @@
1
1
  module Lockbox
2
- VERSION = "0.6.0"
2
+ VERSION = "0.6.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lockbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-03 00:00:00.000000000 Z
11
+ date: 2020-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler