Class: Dor::StaticConfig

Inherits:
Object
  • Object
show all
Extended by:
ActiveSupport::Autoload
Defined in:
lib/dor/static_config.rb,
lib/dor/static_config/ssl_config.rb,
lib/dor/static_config/solr_config.rb,
lib/dor/static_config/suri_config.rb,
lib/dor/static_config/fedora_config.rb,
lib/dor/static_config/stacks_config.rb,
lib/dor/static_config/workflow_config.rb

Overview

Provides configuration for dor-services

Defined Under Namespace

Classes: FedoraConfig, SolrConfig, SslConfig, StacksConfig, SuriConfig, WorkflowConfig

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ StaticConfig

Returns a new instance of StaticConfig.



18
19
20
21
22
23
24
25
# File 'lib/dor/static_config.rb', line 18

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))
  @workflow = WorkflowConfig.new(hash.fetch(:workflow))
end

Instance Method Details

#configure(&block) ⇒ Object



27
28
29
30
# File 'lib/dor/static_config.rb', line 27

def configure(&block)
  instance_eval(&block)
  maybe_connect_solr
end

#default_ssl_cert_storeObject



65
66
67
# File 'lib/dor/static_config.rb', line 65

def default_ssl_cert_store
  @default_ssl_cert_store ||= RestClient::Request.default_ssl_cert_store
end

#fedora(&block) ⇒ Object



74
75
76
77
# File 'lib/dor/static_config.rb', line 74

def fedora(&block)
  @fedora.configure(&block) if block_given?
  @fedora
end

#fedora_configObject

This is consumed by ActiveFedora.configurator



49
50
51
52
53
54
55
56
# File 'lib/dor/static_config.rb', line 49

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_connectionObject



39
40
41
# File 'lib/dor/static_config.rb', line 39

def make_solr_connection
  ::RSolr.connect(url: Dor::Config.solr.url)
end

#maybe_connect_solrObject



32
33
34
35
36
37
# File 'lib/dor/static_config.rb', line 32

def maybe_connect_solr
  return unless solr.url.present?

  ActiveFedora::SolrService.register
  ActiveFedora::SolrService.instance.instance_variable_set :@conn, make_solr_connection
end

#predicate_configObject

This is consumed by ActiveFedora.configurator



59
60
61
62
63
# File 'lib/dor/static_config.rb', line 59

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) ⇒ Object



79
80
81
82
83
# File 'lib/dor/static_config.rb', line 79

def solr(&block)
  @solr.configure(&block) if block_given?

  @solr
end

#solr_configObject

This is consumed by ActiveFedora.configurator



44
45
46
# File 'lib/dor/static_config.rb', line 44

def solr_config
  { url: solr.url }
end

#ssl(&block) ⇒ Object



69
70
71
72
# File 'lib/dor/static_config.rb', line 69

def ssl(&block)
  @ssl.configure(&block) if block_given?
  @ssl
end

#stacks(&block) ⇒ Object



85
86
87
88
89
# File 'lib/dor/static_config.rb', line 85

def stacks(&block)
  @stacks.configure(&block) if block_given?

  @stacks
end

#suri(&block) ⇒ Object



91
92
93
94
95
# File 'lib/dor/static_config.rb', line 91

def suri(&block)
  @suri.configure(&block) if block_given?

  @suri
end

#workflow(&block) ⇒ Object



97
98
99
100
101
# File 'lib/dor/static_config.rb', line 97

def workflow(&block)
  @workflow.configure(&block) if block_given?

  @workflow
end