lockbox 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 767467c10e8b38cc53b822c604bc4d6189563a00b7a53a12181ac5d3de19e723
4
- data.tar.gz: 56319f892b400761e11a96b9f0e05f3a5cf684c6b6f069e9f85cbbdd81299bef
3
+ metadata.gz: 860bb7bcddfde22f980e11185c2afae0453e6547064d4538024a16f7652f953d
4
+ data.tar.gz: 5c97a4bcde5621234bf3f832d0c4a2eb7ca2a986541cb203b6370170141fe29b
5
5
  SHA512:
6
- metadata.gz: 8e4550edc543add59495e42f0648b80c538ace8d326c12acbe5bad3bfb907f329d1ff63be86406bad83f8a2732b2938efa6ce6e20bce9b2d10406f173ee3e56b
7
- data.tar.gz: 7087087f6307212b8b041c1703f4d08be578042295a4dcd91efdc1aaab17d1a4c8f2066969ae1837216d746ac3824f287f5fdcbb58afd8a12ce772bf7592d5b9
6
+ metadata.gz: f1435f9cd4dac0ea8bbee39d787c2a28c73b72a3de260759c27a5bc6c53f2c2fb344f144fa391742f3415baf7a0ea183e683353773c0eb305e145f1084d11918
7
+ data.tar.gz: 7623133737e4e465a3c63a0c5bbec337382fcce37469e9685a77578af02218d82b5988a057d3b9dc1d7c1accc9de84014ec9bf32d5ac1f0bc8d15455a80c392c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 1.1.0 (2022-10-09)
2
+
3
+ - Added support for `insert`, `insert_all`, `insert_all!`, `upsert`, and `upsert_all`
4
+
1
5
  ## 1.0.0 (2022-06-11)
2
6
 
3
7
  - Deprecated `encrypts` in favor of `has_encrypted` to avoid conflicting with Active Record encryption
data/README.md CHANGED
@@ -738,7 +738,7 @@ end
738
738
  Make it the default with:
739
739
 
740
740
  ```ruby
741
- Lockbox.default_options = {algorithm: "xsalsa20"}
741
+ Lockbox.default_options[:algorithm] = "xsalsa20"
742
742
  ```
743
743
 
744
744
  You can also pass an algorithm to `previous_versions` for key rotation.
@@ -1048,66 +1048,6 @@ User.with_attached_license.find_each do |user|
1048
1048
  end
1049
1049
  ```
1050
1050
 
1051
- ### 0.3.6
1052
-
1053
- 0.3.6 makes content type detection more reliable for Active Storage. You can check and update the content type of existing files with:
1054
-
1055
- ```ruby
1056
- User.with_attached_license.find_each do |user|
1057
- next unless user.license.attached?
1058
-
1059
- license = user.license
1060
- content_type = Marcel::MimeType.for(license.download, name: license.filename.to_s)
1061
- if content_type != license.content_type
1062
- license.update!(content_type: content_type)
1063
- end
1064
- end
1065
- ```
1066
-
1067
- ### 0.2.0
1068
-
1069
- 0.2.0 brings a number of improvements. Here are a few to be aware of:
1070
-
1071
- - Added `encrypts` method for database fields
1072
- - Added support for XSalsa20
1073
- - `attached_encrypted` is deprecated in favor of `encrypts_attached`.
1074
-
1075
- #### Optional
1076
-
1077
- To switch to a master key, generate a key:
1078
-
1079
- ```ruby
1080
- Lockbox.generate_key
1081
- ```
1082
-
1083
- And set `ENV["LOCKBOX_MASTER_KEY"]` or `Lockbox.master_key`.
1084
-
1085
- Update your model:
1086
-
1087
- ```ruby
1088
- class User < ApplicationRecord
1089
- encrypts_attached :license, previous_versions: [{key: key}]
1090
- end
1091
- ```
1092
-
1093
- New uploads will be encrypted with the new key.
1094
-
1095
- You can rotate existing records with:
1096
-
1097
- ```ruby
1098
- User.unscoped.find_each do |user|
1099
- user.license.rotate_encryption!
1100
- end
1101
- ```
1102
-
1103
- Once that’s complete, update your model:
1104
-
1105
- ```ruby
1106
- class User < ApplicationRecord
1107
- encrypts_attached :license
1108
- end
1109
- ```
1110
-
1111
1051
  ## History
1112
1052
 
1113
1053
  View the [changelog](https://github.com/ankane/lockbox/blob/master/CHANGELOG.md)
data/lib/lockbox/model.rb CHANGED
@@ -226,6 +226,52 @@ module Lockbox
226
226
 
227
227
  result
228
228
  end
229
+
230
+ if ActiveRecord::VERSION::MAJOR >= 6
231
+ def self.insert_all(attributes, **options)
232
+ super(lockbox_map_attributes(attributes), **options)
233
+ end
234
+
235
+ def self.insert_all!(attributes, **options)
236
+ super(lockbox_map_attributes(attributes), **options)
237
+ end
238
+
239
+ def self.upsert_all(attributes, **options)
240
+ super(lockbox_map_attributes(attributes, check_readonly: true), **options)
241
+ end
242
+
243
+ # private
244
+ # does not try to handle :returning option for simplicity
245
+ def self.lockbox_map_attributes(records, check_readonly: false)
246
+ return records unless records.is_a?(Array)
247
+
248
+ records.map do |attributes|
249
+ # transform keys like Active Record
250
+ attributes = attributes.transform_keys do |key|
251
+ n = key.to_s
252
+ attribute_aliases[n] || n
253
+ end
254
+
255
+ lockbox_attributes = self.lockbox_attributes.slice(*attributes.keys.map(&:to_sym))
256
+ lockbox_attributes.each do |key, lockbox_attribute|
257
+ attribute = key.to_s
258
+ # check read only
259
+ # users should mark both plaintext and ciphertext columns
260
+ if check_readonly && readonly_attributes.include?(attribute) && !readonly_attributes.include?(lockbox_attribute[:encrypted_attribute].to_s)
261
+ warn "[lockbox] WARNING: Mark attribute as readonly: #{lockbox_attribute[:encrypted_attribute]}"
262
+ end
263
+
264
+ message = attributes[attribute]
265
+ attributes.delete(attribute) unless lockbox_attribute[:migrating]
266
+ encrypted_attribute = lockbox_attribute[:encrypted_attribute]
267
+ ciphertext = send("generate_#{encrypted_attribute}", message)
268
+ attributes[encrypted_attribute] = ciphertext
269
+ end
270
+
271
+ attributes
272
+ end
273
+ end
274
+ end
229
275
  else
230
276
  def reload
231
277
  self.class.lockbox_attributes.each do |_, v|
@@ -1,3 +1,3 @@
1
1
  module Lockbox
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
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: 1.0.0
4
+ version: 1.1.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: 2022-10-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: andrew@ankane.org