Sha256: 4b72acafdc79071206397a51571b1b6ed976ad5b9d145e6ea838f4a2cdb97d73

Contents?: true

Size: 1.59 KB

Versions: 1

Compression:

Stored size: 1.59 KB

Contents

require "active_support"
require "active_record"

require "active_record/connection_adapters/cipherstash_pg/database_extensions"
require "active_record/connection_adapters/cipherstash_pg/database_tasks"

module ActiveRecord
  module ConnectionAdapters
    module CipherStashPG
      class Railtie < ::Rails::Railtie
        rake_tasks do
          load "cipherstash_tasks.rake"
        end

        initializer "postgres_cipherstash_adapter.configure" do
          if defined?(Rails.application.credentials)
            cs_credentials = Rails.application.credentials.try(:cipherstash)

            client_id = cs_credentials&.fetch(:client_id, nil)
            client_key = cs_credentials&.fetch(:client_key, nil)
            workspace_id = cs_credentials&.fetch(:workspace_id, nil)
            client_access_key = cs_credentials&.fetch(:client_access_key, nil)

            unless client_id.nil?
              ENV["CS_CLIENT_ID"] = client_id
            end

            unless client_key.nil?
              ENV["CS_CLIENT_KEY"] = client_key
            end

            unless workspace_id.nil?
              ENV["CS_WORKSPACE_ID"] = workspace_id
            end

            unless client_access_key.nil?
              ENV["CS_CLIENT_ACCESS_KEY"] = client_access_key
            end
          end
        end
      end

      # Method to install CipherStash custom ORE types
      def self.install
        CipherStashPG::DatabaseExtensions.install
      end

      # Method to uninstall CipherStash custom ORE types
      def self.uninstall
        CipherStashPG::DatabaseExtensions.uninstall
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
activerecord-cipherstash-pg-adapter-0.6.0 lib/activerecord-cipherstash-pg-adapter.rb