daffy_lib 0.1.3 → 0.1.4

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: 7eb281bde2461b8274952783bc2206fd328874c747dccac03f7d4a54f9fa2d57
4
- data.tar.gz: ae3522cd8a5c663b84af151ae77baaf985cca4fa1c185577d8140fc0a6d828c8
3
+ metadata.gz: e42df7142acbd13e877203468339c8c27e84516d44ccc3107fa01f7e5034af05
4
+ data.tar.gz: d2da07b7b352615048dc862cc389440cffe860b735fa39b0d17c9f128cb5bd61
5
5
  SHA512:
6
- metadata.gz: 5476f53e1db7c2bbb28978db6bb05de7a6279cd39f974efaf68d027a0702ca75d51745d52170fc1f8819829baa46802eda97b8b50466ffa039de4bf92d41a36a
7
- data.tar.gz: 68801fda22eab1cc629f47e7af75240b76962baa307f1175ab42d99e2d50e1076fa7dfb26bc9496543257eafb7b47c260ca5f4ed553614d6eae0072784d6b9ee
6
+ metadata.gz: 6ebfe579e41062e8e4eaf6f36f8ff808cbc231f512f77be55c4a043d85f384a372dcb22f22a9cdb8fb8b0d8d5193f2be140839bd260e4102162fa667c8b3f85c
7
+ data.tar.gz: 200e8e4df5686ae1fdb7fc1ceb051582f27952e7c940602260ba3076b5b383be29738d32bdb0ee7dc978853b9f8610816cd57de09818b0bedc0b460474fd4087
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- daffy_lib (0.1.3)
4
+ daffy_lib (0.1.4)
5
5
  porky_lib
6
6
  rails
7
7
  redis
@@ -68,16 +68,16 @@ GEM
68
68
  attr_encrypted (3.1.0)
69
69
  encryptor (~> 3.0.0)
70
70
  aws-eventstream (1.0.3)
71
- aws-partitions (1.269.0)
72
- aws-sdk-core (3.89.1)
71
+ aws-partitions (1.274.0)
72
+ aws-sdk-core (3.90.1)
73
73
  aws-eventstream (~> 1.0, >= 1.0.2)
74
74
  aws-partitions (~> 1, >= 1.239.0)
75
75
  aws-sigv4 (~> 1.1)
76
76
  jmespath (~> 1.0)
77
- aws-sdk-kms (1.28.0)
77
+ aws-sdk-kms (1.29.0)
78
78
  aws-sdk-core (~> 3, >= 3.71.0)
79
79
  aws-sigv4 (~> 1.1)
80
- aws-sdk-s3 (1.60.1)
80
+ aws-sdk-s3 (1.60.2)
81
81
  aws-sdk-core (~> 3, >= 3.83.0)
82
82
  aws-sdk-kms (~> 1)
83
83
  aws-sigv4 (~> 1.1)
@@ -122,7 +122,7 @@ GEM
122
122
  mini_mime (1.0.2)
123
123
  mini_portile2 (2.4.0)
124
124
  minitest (5.13.0)
125
- msgpack (1.3.1)
125
+ msgpack (1.3.3)
126
126
  nio4r (2.5.2)
127
127
  nokogiri (1.10.8)
128
128
  mini_portile2 (~> 2.4.0)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DaffyLib
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.4"
5
5
  end
@@ -25,5 +25,51 @@ namespace :db do
25
25
  created_at:datetime \\
26
26
  updated_at:datetime`
27
27
  end
28
+
29
+ desc 'Migrates the database by generating partition guid and encryption epoch for the specified model'
30
+ task :generate_encryption_attributes, %i[model limit] => :environment do |_t, args|
31
+ model = args[:model].camelize
32
+ limit = args[:limit] || 1000
33
+ limit = limit.to_i
34
+
35
+ abort 'Need to provide `model` as argument' if model.blank?
36
+
37
+ model_classname = model.to_s.camelize.singularize.constantize
38
+
39
+ model_classname.instance_eval do
40
+ # Find all records that don't yet have a partition_guid
41
+ scope :pending_migration, -> { where(partition_guid: nil) }
42
+ end
43
+
44
+ model_classname.reset_column_information
45
+
46
+ records = limit.zero? ? model_classname.pending_migration : model_classname.pending_migration.limit(limit)
47
+
48
+ records.each do |record|
49
+ record.generate_partition_guid
50
+ record.generate_encryption_epoch
51
+
52
+ record.save!(validate: false)
53
+ end
54
+ end
55
+
56
+ desc 'Migrates the database by performing read/write to re-encrypt specified attributes for the specified model'
57
+ task :re_encrypt_attributes, %i[model] => :environment do |_t, args|
58
+ model = args[:model].camelize
59
+
60
+ abort 'Need to provide `model` as argument' if model.blank?
61
+
62
+ model_classname = model.to_s.camelize.singularize.constantize
63
+ encrypted_attributes = model_classname.encrypted_attributes.keys
64
+
65
+ model_classname.all.each do |record|
66
+ encrypted_attributes.each do |attribute|
67
+ value = record.attributes.with_indifferent_access[attribute.to_sym]
68
+ record.send("#{attribute}=", value) unless value.blank?
69
+ end
70
+
71
+ record.save!(validate: false)
72
+ end
73
+ end
28
74
  end
29
75
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: daffy_lib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benoît Jeaurond, Weiyun Lu
@@ -337,8 +337,6 @@ files:
337
337
  - lib/daffy_lib/validators/string_validator.rb
338
338
  - lib/daffy_lib/version.rb
339
339
  - lib/tasks/db_tasks.rake
340
- - lib/tasks/generate_encryption_attributes.rake
341
- - lib/tasks/re_encrypt_attributes.rake
342
340
  homepage: https://github.com/Zetatango/daffy_lib
343
341
  licenses: []
344
342
  metadata: {}
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # :nocov:
4
- namespace :db do
5
- desc 'this task generates partition guid and encryption epoch for the specified model'
6
- task :generate_encryption_attributes, %i[model limit] => :environment do |_t, args|
7
- model = args[:model].camelize
8
- limit = args[:limit] || 1000
9
- limit = limit.to_i
10
-
11
- abort 'Need to provide `model` as argument' if model.blank?
12
-
13
- model_classname = model.to_s.camelize.singularize.constantize
14
-
15
- model_classname.instance_eval do
16
- # Find all records that don't yet have a partition_guid
17
- scope :pending_migration, -> { where(partition_guid: nil) }
18
- end
19
-
20
- model_classname.reset_column_information
21
-
22
- records = limit.zero? ? model_classname.pending_migration : model_classname.pending_migration.limit(limit)
23
-
24
- records.each do |record|
25
- record.generate_partition_guid
26
- record.generate_encryption_epoch
27
-
28
- record.save!(validate: false)
29
- end
30
- end
31
- end
32
- # :nocov:
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # :nocov:
4
- namespace :db do
5
- desc 'this task performs a db read/write to re-encrypt specified attributes for the specified model'
6
- task :re_encrypt_attributes, %i[model] => :environment do |_t, args|
7
- model = args[:model].camelize
8
-
9
- abort 'Need to provide `model` as argument' if model.blank?
10
-
11
- model_classname = model.to_s.camelize.singularize.constantize
12
- encrypted_attributes = model_classname.encrypted_attributes.keys
13
-
14
- model_classname.all.each do |record|
15
- encrypted_attributes.each do |attribute|
16
- value = record.attributes.with_indifferent_access[attribute.to_sym]
17
- record.send("#{attribute}=", value) unless value.blank?
18
- end
19
-
20
- record.save!(validate: false)
21
- end
22
- end
23
- end
24
- # :nocov: