module PiiSafeSchema
Constants
- VERSION
Public Class Methods
activate!()
click to toggle source
# File lib/pii_safe_schema.rb, line 30 def self.activate! return if Rails.env.test? ActiveSupport.on_load :active_record do Notify.notify(PiiSafeSchema::PiiColumn.all) end rescue ActiveRecord::NoDatabaseError Rails.logger.info('PiiSafeSchema: No DB'.red) end
configuration()
click to toggle source
# File lib/pii_safe_schema.rb, line 18 def self.configuration @configuration ||= Configuration.new end
configure() { |configuration| ... }
click to toggle source
# File lib/pii_safe_schema.rb, line 26 def self.configure yield(configuration) end
generate_migrations(additional_pii_columns = [])
click to toggle source
# File lib/pii_safe_schema.rb, line 40 def self.generate_migrations(additional_pii_columns = []) PiiSafeSchema::MigrationGenerator.generate_migrations( PiiSafeSchema::PiiColumn.all + additional_pii_columns, ) end
parse_additional_columns(arguments)
click to toggle source
# File lib/pii_safe_schema.rb, line 46 def self.parse_additional_columns(arguments) arguments.map do |str| matches = /([a-z_]+):([a-z_]+):([a-z_]+)/i.match(str) return print_help! if matches.blank? suggestion = Annotations.comment(matches[3]) return print_help! if suggestion.blank? PiiColumn.from_column_name(table: matches[1], column: matches[2], suggestion: suggestion) end end
print_help!(do_exit: true)
click to toggle source
# File lib/pii_safe_schema.rb, line 58 def self.print_help!(do_exit: true) # rubocop:disable Metrics/MethodLength puts <<~HELPMSG # rubocop:disable Rails/Output Usage: rake pii_safe_schema:generate_migrations [table:column:annotation_type] ... Arguments: [table:column:annotation_type] # A column to manually annotate. Can be repeated. # annotation_type can be "email", "phone", "ip_address", # "geolocation", "address", "postal_code", "name", # "sensitive_data", or "encrypted_data" Description: Generates a migration to add PII annotation comments to appropriate columns on a table. Uses a series of regular expressions to find sensitive fields. Optionally supply arguments to annotate columns explicitly Example: rake pii_safe_schema:generate_migrations signatures:signatory_name:name signatures:landline:phone Will generate a migration with the following, assuming automatic regex had no matches: class ChangeCommentsInSignatures < ActiveRecord::Migration[5.2] def change safety_assured do change_column :signatures, :signatory_name, :string, comment: '{"pii":{"obfuscate":"name_obfuscator"}}' change_column :signatures, :landline, :string, comment: '{"pii":{"obfuscate":"phone_obfuscator"}}' end end end HELPMSG exit(1) if do_exit # rubocop:disable Rails/Exit end
reset_configuration!()
click to toggle source
# File lib/pii_safe_schema.rb, line 22 def self.reset_configuration! @configuration = Configuration.new end