diff --git a/app/models/rails/keyserver/application_record.rb b/app/models/rails/keyserver/application_record.rb index 3624053..f1ae4f2 100644 --- a/app/models/rails/keyserver/application_record.rb +++ b/app/models/rails/keyserver/application_record.rb @@ -1,6 +1,6 @@ module Rails module Keyserver - class ApplicationRecord < ActiveRecord::Base + class ApplicationRecord < ::ActiveRecord::Base self.abstract_class = true end end diff --git a/app/models/rails/keyserver/key.rb b/app/models/rails/keyserver/key.rb index 63d8110..219dacc 100644 --- a/app/models/rails/keyserver/key.rb +++ b/app/models/rails/keyserver/key.rb @@ -1,8 +1,11 @@ # frozen_string_literal: true +require_dependency File.expand_path("application_record", __dir__) +require_dependency File.expand_path("../../../../lib/rails/keyserver/engine", __dir__) + module Rails module Keyserver - class Key < ApplicationRecord + class Key < ::Rails::Keyserver::ApplicationRecord class EncryptionKeyNotFoundException < RuntimeError; end include MySQLBinUUID::UUID @@ -40,14 +43,14 @@ def save_fingerprint; end belongs_to :owner, polymorphic: true # XXX: key blankness should ideally be checked in attr_encrypted! - if Engine.config.encryption_key.blank? + if Rails::Keyserver::Engine.config.encryption_key.blank? raise EncryptionKeyNotFoundException, - "Engine.config.encryption_key is blank!" + "Rails::Keyserver::Engine.config.encryption_key is blank!" end attr_encrypted :private, - key: Engine.config.encryption_key, - mode: Engine.config.try(:encryption_mode) || :per_attribute_iv + key: Rails::Keyserver::Engine.config.encryption_key, + mode: Rails::Keyserver::Engine.config.try(:encryption_mode) || :per_attribute_iv scope :primary, -> { pkg = arel_table[:primary_key_grip] @@ -87,3 +90,5 @@ def save_fingerprint; end end end end + +require File.expand_path("key/pgp", __dir__) diff --git a/app/models/rails/keyserver/key/pgp.rb b/app/models/rails/keyserver/key/pgp.rb index 0e4fefe..eb19aab 100644 --- a/app/models/rails/keyserver/key/pgp.rb +++ b/app/models/rails/keyserver/key/pgp.rb @@ -1,5 +1,8 @@ # frozen_string_literal: true +require File.expand_path("../key", __dir__) +require File.expand_path("../application_record", __dir__) + module Rails module Keyserver class Key @@ -12,7 +15,7 @@ def self.extension end # TODO: These defaults belong in somewhere else? - Engine.config.key_host = nil + ::Rails::Keyserver::Engine.config.key_host = nil def derive_metadata_if_empty derive_metadata if metadata.blank? diff --git a/lib/rails/keyserver.rb b/lib/rails/keyserver.rb index 6386756..c0eca82 100644 --- a/lib/rails/keyserver.rb +++ b/lib/rails/keyserver.rb @@ -1,5 +1,12 @@ # frozen_string_literal: true +module Rails + module Keyserver + end +end + +RK = Rails::Keyserver # development use? No, production use, too! + require "rails/keyserver/engine" require "rails/keyserver/routes" require "mysql-binuuid-rails" @@ -10,11 +17,3 @@ # require "mail-gpg" require "attr_encrypted" # require "graphql" - -module Rails - module Keyserver - # Your code goes here... - end -end - -RK = Rails::Keyserver # development use? No, production use, too! diff --git a/lib/rails/keyserver/engine.rb b/lib/rails/keyserver/engine.rb index 4f5c8ac..9ef53c8 100644 --- a/lib/rails/keyserver/engine.rb +++ b/lib/rails/keyserver/engine.rb @@ -9,9 +9,15 @@ class Engine < ::Rails::Engine g.fixture_replacement :factory_bot, dir: "spec/factories" end + config.to_prepare do + # pp Rails::Keyserver::Engine.config.encryption_key + end + config.after_initialize do end + config.autoload_paths << "#{config.root}/lib" + # URL: # https://blog.pivotal.io/labs/labs/leave-your-migrations-in-your-rails-engines initializer :append_migrations do |app|