This DRYs up setting up encrypted columns for a model. You just need to specify the column or columns to be encrypted, and the plugin takes care of setting up the column_encryption plugin. Other advantages: * Model.redacted_columns is now an attr_reader, and does not need to check for encrypted columns every time it is called. * Model#before_destroy can look at Model.encrypted_columns (also an attr_reader), so it is simplified as well. Simplify the method while here by using hash key omission, and make sure the constant it uses is frozen.
25 lines
675 B
Ruby
25 lines
675 B
Ruby
# frozen_string_literal: true
|
|
|
|
require_relative "../model"
|
|
require "aws-sdk-ec2"
|
|
|
|
class LocationCredential < Sequel::Model
|
|
plugin ResourceMethods, encrypted_columns: [:access_key, :secret_key]
|
|
many_to_one :project
|
|
many_to_one :location, key: :id
|
|
|
|
def client
|
|
Aws::EC2::Client.new(access_key_id: access_key, secret_access_key: secret_key, region: location.name)
|
|
end
|
|
end
|
|
|
|
# Table: location_credential
|
|
# Columns:
|
|
# access_key | text | NOT NULL
|
|
# secret_key | text | NOT NULL
|
|
# id | uuid | PRIMARY KEY
|
|
# Indexes:
|
|
# location_credential_pkey | PRIMARY KEY btree (id)
|
|
# Foreign key constraints:
|
|
# location_credential_id_fkey | (id) REFERENCES location(id)
|