daffy_lib 0.1.1 → 0.1.2

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: 83018eb7ecab966f8b2735dfdf734799b847e275b53c0c744cf11ea3cbb090f9
4
- data.tar.gz: b7d09dad2fb06cd398ac783b7dec39b6fa0891098691a5c95d41efbd459e4848
3
+ metadata.gz: faba74eda53723e334c18a034844f7800d5ddce97a924fb2178eb415f6ed49fe
4
+ data.tar.gz: ee433a137161339be70a78ef005f5f09e0bfbe4f0d8da3212efeb60ce06ebbb5
5
5
  SHA512:
6
- metadata.gz: 1a2708f077f87e1d3b316449b387114f82315ab4983e733bcda749c2b59cf8cd9fc9c4d0a9956b68f4f7b67e7c3ad40777869ecca58a80645502715c279050d2
7
- data.tar.gz: bf09073a430ad69567c4069727d5d9f3fab1cf8afa01f8de7cc8cdd205f21cf757cc8e39914aad7b6cc0ad22ba7c0484fc91907152c9c3cc99ad386c77007506
6
+ metadata.gz: b93f7a314777375667919219dab46f84e76d39dfe2f0d0f394a8351eee057ed57a424816e5d936163779fa7bed6001602843df6c289cfc4bb68c4b2944ab8e01
7
+ data.tar.gz: f00b7e4c6300d8ae5d4982339eb7fbc4af089faf9f5ae15956339aaef05b05d3b63d2852b98d3f1b7041da203dbeded747a4858a2a22a72798be88053a24c89f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- daffy_lib (0.1.1)
4
+ daffy_lib (0.1.2)
5
5
  porky_lib
6
6
  rails
7
7
  redis
@@ -68,7 +68,7 @@ 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.263.0)
71
+ aws-partitions (1.265.0)
72
72
  aws-sdk-core (3.89.1)
73
73
  aws-eventstream (~> 1.0, >= 1.0.2)
74
74
  aws-partitions (~> 1, >= 1.239.0)
@@ -102,7 +102,7 @@ GEM
102
102
  factory_bot_rails (5.1.1)
103
103
  factory_bot (~> 5.1.0)
104
104
  railties (>= 4.2.0)
105
- ffi (1.11.3)
105
+ ffi (1.12.1)
106
106
  globalid (0.4.2)
107
107
  activesupport (>= 4.2.0)
108
108
  i18n (1.7.1)
data/README.md CHANGED
@@ -66,46 +66,11 @@ t.index [:guid], name: :index_encryption_keys_on_guid, unique: true
66
66
  t.index [:partition_guid, :key_epoch], name: :index_encryption_keys, unique: true
67
67
 
68
68
  ```
69
- Next, if the models do not have existing records, one can run `rake db:migrate:add_encryption_fields[modelname]` to add the `partition_guid` and `encryption_epoch` columns.
69
+ Next, run `rake db:migrate:add_encryption_fields['modelname']` to add the `partition_guid` and `encryption_epoch` columns to each model.
70
70
 
71
- However, if there may already be existing records, then the `generate_partition_guid` and `generate_encryption_epoch` methods need to be invoked before the new columns can be set to required. Below is a sample migration file for our example above, where one should replace `models` with their own.
72
- ```
73
- def up
74
- models = %i[users users/attributes]
75
-
76
- models.each do |model|
77
-
78
- model_classname = model.to_s.camelize.singularize.constantize
79
- model_tablename = model.to_s.gsub('/', '_')
80
-
81
- add_column model_tablename, :partition_guid, :string
82
- add_column model_tablename, :encryption_epoch, :datetime
83
-
84
- model_classname.reset_column_information
85
- model_classname.find_each do |record|
86
- record.generate_partition_guid
87
- record.generate_encryption_epoch
88
-
89
- record.save!(validate: false)
90
- end
71
+ Run `rake generate_encryption_attributes['modelname','limit']` to populate existing records of each model with the encryption attributes. The limit specifies the maximum number of records updated per execution; a limit of 0 means no limit.
91
72
 
92
- change_column model_tablename, :partition_guid, :string, null: false
93
- change_column model_tablename, :encryption_epoch, :datetime, null: false
94
- end
95
- end
96
-
97
- def down
98
- models = %i[users users/attributes]
99
-
100
- models.each do |model|
101
- model_tablename = model.to_s.gsub('/', '_')
102
-
103
- remove_column model_tablename, :partition_guid
104
- remove_column model_tablename, :encryption_epoch
105
- end
106
- end
107
- end
108
- ```
73
+ Finally, once existing records have been populated, it is advisable to perform a final migration to set `partition_guid` and `encryption_epoch` columns to mandatory.
109
74
 
110
75
 
111
76
  ## Development
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DaffyLib
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nocov:
4
+ desc 'this task generates partition guid and encryption epoch for the specified model'
5
+ task :generate_encryption_attributes, %i[model limit] => :environment do |_t, args|
6
+ model = args[:model].camelize
7
+ limit = args[:limit] || 1000
8
+ limit = limit.to_i
9
+
10
+ abort 'Need to provide `model` as argument' if model.blank?
11
+
12
+ model_classname = model.to_s.camelize.singularize.constantize
13
+
14
+ model_classname.instance_eval do
15
+ # Find all records that don't yet have a partition_guid
16
+ scope :pending_migration, -> { where(partition_guid: nil) }
17
+ end
18
+
19
+ model_classname.reset_column_information
20
+
21
+ records = limit.zero? ? model_classname.pending_migration : model_classname.pending_migration.limit(limit)
22
+
23
+ records.each do |record|
24
+ record.generate_partition_guid
25
+ record.generate_encryption_epoch
26
+
27
+ record.save!(validate: false)
28
+ end
29
+ end
30
+ # :nocov:
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: daffy_lib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benoît Jeaurond, Weiyun Lu
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-17 00:00:00.000000000 Z
11
+ date: 2020-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: attr_encrypted
@@ -324,7 +324,6 @@ files:
324
324
  - SECURITY.MD
325
325
  - bin/console
326
326
  - bin/setup
327
- - daffy_lib-0.1.0.gem
328
327
  - daffy_lib.gemspec
329
328
  - lib/daffy_lib.rb
330
329
  - lib/daffy_lib/caching_encryptor.rb
@@ -338,6 +337,7 @@ files:
338
337
  - lib/daffy_lib/validators/string_validator.rb
339
338
  - lib/daffy_lib/version.rb
340
339
  - lib/tasks/db_tasks.rake
340
+ - lib/tasks/generate_encryption_attributes.rb
341
341
  homepage: https://github.com/Zetatango/daffy_lib
342
342
  licenses: []
343
343
  metadata: {}
data/daffy_lib-0.1.0.gem DELETED
Binary file