Skip to content

Commit

Permalink
Update dependencies for rails 6
Browse files Browse the repository at this point in the history
  • Loading branch information
kwkwan committed Jan 18, 2023
1 parent a2c3e7f commit 0189e84
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 15 deletions.
2 changes: 1 addition & 1 deletion app/models/rails/keyserver/application_record.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Rails
module Keyserver
class ApplicationRecord < ActiveRecord::Base
class ApplicationRecord < ::ActiveRecord::Base
self.abstract_class = true
end
end
Expand Down
15 changes: 10 additions & 5 deletions app/models/rails/keyserver/key.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -87,3 +90,5 @@ def save_fingerprint; end
end
end
end

require File.expand_path("key/pgp", __dir__)
5 changes: 4 additions & 1 deletion app/models/rails/keyserver/key/pgp.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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?
Expand Down
15 changes: 7 additions & 8 deletions lib/rails/keyserver.rb
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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!
6 changes: 6 additions & 0 deletions lib/rails/keyserver/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down

0 comments on commit 0189e84

Please sign in to comment.