Module: KmsEncryptedModelPatch

Extended by:
KmsEncryptedModelPatch
Included in:
KmsEncryptedModelPatch
Defined in:
app/models/concerns/kms_encrypted_model_patch.rb

Instance Method Summary collapse

Instance Method Details

#has_kms_key(**args) ⇒ Object

rubocop:disable Naming/PredicateName



9
10
11
12
13
# File 'app/models/concerns/kms_encrypted_model_patch.rb', line 9

def has_kms_key(**args)
  # implicitly calls #has_kms_key with specified options, so that we don't need to require it
  # of future encrypted models
  super(**args.merge(kms_options))
end

#kms_key_rotation_dateObject (private)



22
23
24
# File 'app/models/concerns/kms_encrypted_model_patch.rb', line 22

def kms_key_rotation_date
  Date.new(Time.zone.today.year, 10, 12)
end

#kms_optionsObject (private)



26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/models/concerns/kms_encrypted_model_patch.rb', line 26

def kms_options
  # Enumerate key_ids so that all years/previous versions are accounted for. Every
  # version should point to the same key_id
  previous_versions = Hash.new do |hash, key|
    hash[key] = { key_id: KmsEncrypted.key_id }
  end

  {
    version: kms_version,
    previous_versions:
  }
end

#kms_versionObject

rubocop:enable Naming/PredicateName



16
17
18
# File 'app/models/concerns/kms_encrypted_model_patch.rb', line 16

def kms_version
  Time.zone.today < kms_key_rotation_date ? Time.zone.today.year - 1 : Time.zone.today.year
end