class Dor::StaticConfig

Provides configuration for dor-services

Public Class Methods

new(hash) click to toggle source
# File lib/dor/static_config.rb, line 17
def initialize(hash)
  @ssl = SslConfig.new(hash.fetch(:ssl))
  @fedora = FedoraConfig.new(hash.fetch(:fedora))
  @solr = SolrConfig.new(hash.fetch(:solr))
  @stacks = StacksConfig.new(hash.fetch(:stacks))
  @suri = SuriConfig.new(hash.fetch(:suri))
end

Public Instance Methods

configure(&block) click to toggle source
# File lib/dor/static_config.rb, line 25
def configure(&block)
  instance_eval(&block)
  maybe_connect_solr
end
default_ssl_cert_store() click to toggle source
# File lib/dor/static_config.rb, line 63
def default_ssl_cert_store
  @default_ssl_cert_store ||= RestClient::Request.default_ssl_cert_store
end
fedora(&block) click to toggle source
# File lib/dor/static_config.rb, line 72
def fedora(&block)
  @fedora.configure(&block) if block_given?
  @fedora
end
fedora_config() click to toggle source

This is consumed by ActiveFedora.configurator

# File lib/dor/static_config.rb, line 47
def fedora_config
  fedora_uri = URI.parse(fedora.url)
  connection_opts = { url: fedora.safeurl, user: fedora_uri.user, password: fedora_uri.password }
  connection_opts[:ssl_client_cert] = OpenSSL::X509::Certificate.new(File.read(ssl.cert_file)) if ssl.cert_file.present?
  connection_opts[:ssl_client_key] = OpenSSL::PKey::RSA.new(File.read(ssl.key_file), ssl.key_pass) if ssl.key_file.present?
  connection_opts[:ssl_cert_store] = default_ssl_cert_store
  connection_opts
end
make_solr_connection() click to toggle source
# File lib/dor/static_config.rb, line 37
def make_solr_connection
  ::RSolr.connect(url: Dor::Config.solr.url)
end
maybe_connect_solr() click to toggle source
# File lib/dor/static_config.rb, line 30
def maybe_connect_solr
  return unless solr.url.present?

  ActiveFedora::SolrService.register
  ActiveFedora::SolrService.instance.instance_variable_set :@conn, make_solr_connection
end
predicate_config() click to toggle source

This is consumed by ActiveFedora.configurator

# File lib/dor/static_config.rb, line 57
def predicate_config
  # rubocop:disable Security/YAMLLoad
  YAML.load(File.read(File.expand_path('../../config/predicate_mappings.yml', __dir__)))
  # rubocop:enable Security/YAMLLoad
end
solr(&block) click to toggle source
# File lib/dor/static_config.rb, line 77
def solr(&block)
  @solr.configure(&block) if block_given?

  @solr
end
solr_config() click to toggle source

This is consumed by ActiveFedora.configurator

# File lib/dor/static_config.rb, line 42
def solr_config
  { url: solr.url }
end
ssl(&block) click to toggle source
# File lib/dor/static_config.rb, line 67
def ssl(&block)
  @ssl.configure(&block) if block_given?
  @ssl
end
stacks(&block) click to toggle source
# File lib/dor/static_config.rb, line 83
def stacks(&block)
  @stacks.configure(&block) if block_given?

  @stacks
end
suri(&block) click to toggle source
# File lib/dor/static_config.rb, line 89
def suri(&block)
  @suri.configure(&block) if block_given?

  @suri
end