Class: Dor::Configuration

Inherits:
Confstruct::Configuration
  • Object
show all
Includes:
ActiveSupport::Callbacks
Defined in:
lib/dor/config.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Configuration


12
13
14
15
# File 'lib/dor/config.rb', line 12

def initialize *args
  super *args
  run_callbacks(:initialize) { }
end

Instance Method Details

#autoconfigure(url, cert_file = Config.ssl.cert_file, key_file = Config.ssl.key_file, key_pass = Config.ssl.key_pass) ⇒ Object


34
35
36
37
38
# File 'lib/dor/config.rb', line 34

def autoconfigure(url, cert_file=Config.ssl.cert_file, key_file=Config.ssl.key_file, key_pass=Config.ssl.key_pass)
  client = make_rest_client(url, cert_file, key_file, key_pass)
  config = Confstruct::Configuration.symbolize_hash JSON.parse(client.get :accept => 'application/json')
  self.configure(config)
end

#configure(*args) ⇒ Object


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/dor/config.rb', line 17

def configure *args
  result = self
  temp_v = $-v
  $-v = nil
  begin
    run_callbacks :configure do
      result = super(*args)
    end
  ensure
    $-v = temp_v
  end
  params = { :dor_services_url => result.dor_services.url }
  params[:timeout] = result.workflow.timeout if result.workflow.timeout
  Dor::WorkflowService.configure result.workflow.url, params
  return result
end

#fedora_configObject


126
127
128
129
130
131
132
# File 'lib/dor/config.rb', line 126

def fedora_config
  fedora_uri = URI.parse(self.fedora.url)
  connection_opts = { :url => self.fedora.safeurl, :user => fedora_uri.user, :password => fedora_uri.password }
  connection_opts[:ssl_client_cert] = OpenSSL::X509::Certificate.new(File.read(self.ssl.cert_file)) if self.ssl.cert_file.present?
  connection_opts[:ssl_client_key] = OpenSSL::PKey::RSA.new(File.read(self.ssl.key_file),self.ssl.key_pass) if self.ssl.key_file.present?
  connection_opts
end

#init(*args) ⇒ Object

Act like an ActiveFedora.configurator


124
# File 'lib/dor/config.rb', line 124

def init *args; end

#make_rest_client(url, cert = Config.ssl.cert_file, key = Config.ssl.key_file, pass = Config.ssl.key_pass) ⇒ Object


44
45
46
47
48
49
# File 'lib/dor/config.rb', line 44

def make_rest_client(url, cert=Config.ssl.cert_file, key=Config.ssl.key_file, pass=Config.ssl.key_pass)
  params = {}
  params[:ssl_client_cert] = OpenSSL::X509::Certificate.new(File.read(cert)) if cert
  params[:ssl_client_key]  = OpenSSL::PKey::RSA.new(File.read(key), pass) if key
  RestClient::Resource.new(url, params)
end

#make_solr_connection(add_opts = {}) ⇒ Object


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

def make_solr_connection(add_opts={})
  opts = Config.solrizer.opts.merge(add_opts).merge(
    :url => Config.solrizer.url
  )
  ::RSolr::Ext.connect(opts)
end

#predicate_configObject


138
139
140
# File 'lib/dor/config.rb', line 138

def predicate_config
  YAML.load(File.read(File.expand_path('../../../config/predicate_mappings.yml',__FILE__)))
end

#sanitizeObject


40
41
42
# File 'lib/dor/config.rb', line 40

def sanitize
  self.dup
end

#solr_configObject


134
135
136
# File 'lib/dor/config.rb', line 134

def solr_config
  { :url => self.solrizer.url }
end