Skip to content

Commit

Permalink
Merge pull request #284 from sul-dlss/simplify_config
Browse files Browse the repository at this point in the history
Avoid Dor::Config where possible and use Settings
  • Loading branch information
justinlittman committed May 22, 2019
2 parents 72ebc5b + 854e813 commit 75ca4fa
Show file tree
Hide file tree
Showing 32 changed files with 150 additions and 247 deletions.
4 changes: 2 additions & 2 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ class ApplicationController < ActionController::API
include ActionController::HttpAuthentication::Basic::ControllerMethods
include ActionController::MimeResponds

http_basic_authenticate_with name: Settings.DOR.SERVICE_USER,
password: Settings.DOR.SERVICE_PASSWORD
http_basic_authenticate_with name: Settings.dor.service_user,
password: Settings.dor.service_password

before_action :check_auth_token

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/content_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ def list
private

def druid_tools
DruidTools::Druid.new(params[:id], Dor::Config.content.content_base_dir)
DruidTools::Druid.new(params[:id], Settings.content.content_base_dir)
end
end
10 changes: 5 additions & 5 deletions app/models/dor/goobi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ class Goobi < ServiceItem
RestClient::SSLCertificateNotVerified]

def register
with_retries(max_tries: Dor::Config.goobi.max_tries,
base_sleep_seconds: Dor::Config.goobi.base_sleep_seconds,
max_sleep_seconds: Dor::Config.goobi.max_sleep_seconds,
with_retries(max_tries: Settings.goobi.max_tries,
base_sleep_seconds: Settings.goobi.base_sleep_seconds,
max_sleep_seconds: Settings.goobi.max_sleep_seconds,
rescue: RETRIABLE_EXCEPTIONS) do |_attempt|
RestClient.post(Dor::Config.goobi.url, xml_request, content_type: 'application/xml')
RestClient.post(Settings.goobi.url, xml_request, content_type: 'application/xml')
end
end

Expand All @@ -35,7 +35,7 @@ def xml_request
<barcode>#{barcode}</barcode>
<collectionId>#{collection_id}</collectionId>
<collectionName>#{collection_name.encode(xml: :text)}</collectionName>
<sdrWorkflow>#{Dor::Config.goobi.dpg_workflow_name}</sdrWorkflow>
<sdrWorkflow>#{Settings.goobi.dpg_workflow_name}</sdrWorkflow>
<goobiWorkflow>#{goobi_workflow_name}</goobiWorkflow>
<ocr>#{goobi_ocr_tag_present?}</ocr>
<tags>#{goobi_xml_tags}</tags>
Expand Down
2 changes: 1 addition & 1 deletion app/models/dor/service_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def goobi_workflow_name
@goobi_workflow_name ||= begin
dpg_workflow_tag_id = 'DPG : Workflow : '
content_tag = @druid_obj.tags.select { |tag| tag.include?(dpg_workflow_tag_id) }
content_tag.empty? ? Dor::Config.goobi.default_goobi_workflow_name : content_tag[0].split(':').last.strip
content_tag.empty? ? Settings.goobi.default_goobi_workflow_name : content_tag[0].split(':').last.strip
end
end

Expand Down
6 changes: 3 additions & 3 deletions app/models/dor/update_marc_record_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ def generate_symphony_records
def write_symphony_records(symphony_records)
return if symphony_records.blank?

symphony_file_name = "#{Dor::Config.release.symphony_path}/sdr-purl-856s"
symphony_file_name = "#{Settings.release.symphony_path}/sdr-purl-856s"
symphony_records.each do |symphony_record|
command = "#{Dor::Config.release.write_marc_script} #{Shellwords.escape(symphony_record)} #{Shellwords.escape(symphony_file_name)}"
command = "#{Settings.release.write_marc_script} #{Shellwords.escape(symphony_record)} #{Shellwords.escape(symphony_file_name)}"
run_write_script(command)
end
end
Expand Down Expand Up @@ -111,7 +111,7 @@ def get_z_field

# It builds the PURL uri based on the druid id
def get_u_field
"|u#{Dor::Config.release.purl_base_uri}/#{@druid_id}"
"|u#{Settings.release.purl_base_uri}/#{@druid_id}"
end

# It returns the SDR-PURL subfield
Expand Down
2 changes: 1 addition & 1 deletion app/models/marcxml_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def self.find_by(catkey: nil, barcode: nil)
if catkey
new(catkey: catkey)
elsif barcode
solr = RSolr.connect(url: Settings.CATALOG.SOLR_URL)
solr = RSolr.connect(url: Settings.catalog.solr_url)
response = solr.get('barcode', params: { n: barcode }).with_indifferent_access
catkey = response[:response][:docs].first[:id]

Expand Down
4 changes: 2 additions & 2 deletions app/models/symphony_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class SymphonyReader
attr_reader :catkey

def self.client
Faraday.new(headers: Settings.CATALOG.SYMPHONY.HEADERS)
Faraday.new(headers: Settings.catalog.symphony.headers)
end

def initialize(catkey:)
Expand Down Expand Up @@ -37,7 +37,7 @@ def client
end

def json
@json ||= JSON.parse(client.get(Settings.CATALOG.SYMPHONY.JSON_URL % { catkey: catkey }).body)
@json ||= JSON.parse(client.get(Settings.catalog.symphony.json_url % { catkey: catkey }).body)
end

def bib_record
Expand Down
4 changes: 2 additions & 2 deletions app/services/public_desc_metadata_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def add_constituent_relations!
# point to the PURL for the parent
location = doc.create_element 'location'
url = doc.create_element 'url'
url.content = "http://#{Dor::Config.stacks.document_cache_host}/#{druid.split(':').last}"
url.content = "http://#{Settings.stacks.document_cache_host}/#{druid.split(':').last}"
location << url
relatedItem << location

Expand Down Expand Up @@ -151,7 +151,7 @@ def add_related_item_node_for_collection!(collection_druid)
# </location>
loc_node = doc.create_element('location')
url_node = doc.create_element('url')
url_node.content = "https://#{Dor::Config.stacks.document_cache_host}/#{collection_druid.split(':').last}"
url_node.content = "https://#{Settings.stacks.document_cache_host}/#{collection_druid.split(':').last}"
loc_node << url_node

type_node = Nokogiri::XML::Node.new('typeOfResource', doc)
Expand Down
24 changes: 12 additions & 12 deletions app/services/publish_metadata_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def transfer_to_document_store(content, filename)
end

def purl_druid
@purl_druid ||= DruidTools::PurlDruid.new item.pid, Dor::Config.stacks.local_document_cache_root
@purl_druid ||= DruidTools::PurlDruid.new item.pid, Settings.stacks.local_document_cache_root
end

def prune_purl_dir
Expand All @@ -62,25 +62,25 @@ def prune_purl_dir

##
# When publishing a PURL, we notify purl-fetcher of changes.
# If the purl service isn't configured, instead we drop a `aa11bb2222` file into the `local_recent_changes` folder
# to notify other applications watching the filesystem (i.e., purl-fetcher).
# We also remove any .deletes entry that may have left over from a previous removal
#
def publish_notify_on_success
id = item.pid.gsub(/^druid:/, '')
raise 'You have not configured perl-fetcher (Dor::Config.purl_services.url).' unless Dor::Config.purl_services.url

purl_services = Dor::Config.purl_services.rest_client
purl_services["purls/#{id}"].post ''
rest_client["purls/#{id}"].post ''
end

##
# When publishing a PURL, we notify purl-fetcher of changes.
# When deleting a PURL, we notify purl-fetcher of changes.
#
def publish_delete_on_success
return unless Dor::Config.purl_services.url

id = item.pid.gsub(/^druid:/, '')

purl_services = Dor::Config.purl_services.rest_client
purl_services["purls/#{id}"].delete
rest_client["purls/#{id}"].delete
end

def rest_client
raise 'You have not configured perl-fetcher (Settings.purl_services_url).' unless Settings.purl_services_url

RestClient::Resource.new(Settings.purl_services_url)
end
end
2 changes: 1 addition & 1 deletion app/services/sdr_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# A client for talking to sdr-services-app
class SdrClient
def self.create
RestClient::Resource.new(Settings.SDR_URL, {})
RestClient::Resource.new(Settings.sdr_url, {})
end

def self.current_version(druid)
Expand Down
2 changes: 1 addition & 1 deletion app/services/workspace_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class WorkspaceService
# @param [Dor::Item] work the work to create the workspace for
# @param [String] source the path to create
def self.create(work, source)
druid = DruidTools::Druid.new(work.pid, Dor::Config.stacks.local_workspace_root)
druid = DruidTools::Druid.new(work.pid, Settings.stacks.local_workspace_root)
return druid.mkdir if source.nil?

druid.mkdir_with_final_link(source)
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
config.use_env = true
config.env_prefix = 'SETTINGS'
config.env_separator = '__'
config.env_converter = nil # don't downcase
config.env_converter = :downcase
end
92 changes: 19 additions & 73 deletions config/initializers/dor_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,97 +2,43 @@

Dor.configure do
ssl do
cert_file Settings.SSL.CERT_FILE
key_file Settings.SSL.KEY_FILE
key_pass Settings.SSL.KEY_PASS
cert_file Settings.ssl.cert_file
key_file Settings.ssl.key_file
key_pass Settings.ssl.key_pass
end

fedora do
url Settings.FEDORA_URL
url Settings.fedora_url
end

solr do
url Settings.solr.url
end

workflow do
url Settings.WORKFLOW_URL
logfile Settings.WORKFLOW.LOGFILE
shift_age Settings.WORKFLOW.SHIFT_AGE
end

dor_services do
url Settings.DOR_SERVICES_URL
url Settings.workflow_url
logfile Settings.workflow.logfile
shift_age Settings.workflow.shift_age
end

suri do
mint_ids Settings.SURI.MINT_IDS
id_namespace Settings.SURI.ID_NAMESPACE
url Settings.SURI.URL
user Settings.SURI.USER
pass Settings.SURI.PASS
end

stomp do
client_id Settings.STOMP_CLIENT_ID
end

content do
content_user Settings.CONTENT.USER
content_base_dir Settings.CONTENT.BASE_DIR
content_server Settings.CONTENT.SERVER_HOST
sdr_server Settings.CONTENT.SDR_SERVER_URL
sdr_user Settings.CONTENT.SDR_USER
sdr_pass Settings.CONTENT.SDR_PASSWORD
end

status do
indexer_url Settings.STATUS_INDEXER_URL
mint_ids Settings.suri.mint_ids
id_namespace Settings.suri.id_namespace
url Settings.suri.url
user Settings.suri.user
pass Settings.suri.pass
end

stacks do
document_cache_storage_root Settings.STACKS.DOCUMENT_CACHE_STORAGE_ROOT
document_cache_host Settings.STACKS.DOCUMENT_CACHE_HOST
document_cache_user Settings.STACKS.DOCUMENT_CACHE_USER
local_workspace_root Settings.STACKS.LOCAL_WORKSPACE_ROOT
storage_root Settings.STACKS.STORAGE_ROOT
host Settings.STACKS.HOST
user Settings.STACKS.USER
local_stacks_root Settings.STACKS.LOCAL_STACKS_ROOT
local_document_cache_root Settings.STACKS.LOCAL_DOCUMENT_CACHE_ROOT
local_recent_changes Settings.STACKS.LOCAL_RECENT_CHANGES
url Settings.STACKS.URL
iiif_profile 'http://iiif.io/api/image/2/level1.json'
end

indexing_svc do
log Settings.INDEXER.LOG
log_date_format_str Settings.DATE_FORMAT_STR
log_rotation_interval Settings.INDEXER.LOG_ROTATION_INTERVAL
document_cache_host Settings.stacks.document_cache_host
local_workspace_root Settings.stacks.local_workspace_root
local_stacks_root Settings.stacks.local_stacks_root
local_document_cache_root Settings.stacks.local_document_cache_root
end

cleanup do
local_workspace_root Settings.CLEANUP.LOCAL_WORKSPACE_ROOT
local_assembly_root Settings.CLEANUP.LOCAL_ASSEMBLY_ROOT
local_export_home Settings.CLEANUP.LOCAL_EXPORT_HOME
end

release do
symphony_path Settings.RELEASE.SYMPHONY_PATH
write_marc_script Settings.RELEASE.WRITE_MARC_SCRIPT
purl_base_uri Settings.RELEASE.PURL_BASE_URI
end

goobi do
url Settings.GOOBI.URL
dpg_workflow_name Settings.GOOBI.DPG_WORKFLOW_NAME # the dpg workflow name to put into the XML
default_goobi_workflow_name Settings.GOOBI.DEFAULT_GOOBI_WORKFLOW_NAME # the default goobi workflow name to use if none found in the object
max_tries Settings.GOOBI.MAX_TRIES # the number of attempts to retry service calls before failing
max_sleep_seconds Settings.GOOBI.MAX_SLEEP_SECONDS # max sleep seconds between tries
base_sleep_seconds Settings.GOOBI.BASE_SLEEP_SECONDS # base sleep seconds between tries
end

purl_services do
url Settings.purl_services_url
local_workspace_root Settings.cleanup.local_workspace_root
local_assembly_root Settings.cleanup.local_assembly_root
local_export_home Settings.cleanup.local_export_home
end
end
2 changes: 1 addition & 1 deletion config/initializers/okcomputer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ def perform_request
end

OkComputer::Registry.register 'version', CustomAppVersionCheck.new
OkComputer::Registry.register 'external-symphony', SymphonyCheck.new(Settings.CATALOG.SYMPHONY.JSON_URL % { catkey: 12345 })
OkComputer::Registry.register 'external-symphony', SymphonyCheck.new(Settings.catalog.symphony.json_url % { catkey: 12345 })

OkComputer.make_optional %w(external-symphony)

0 comments on commit 75ca4fa

Please sign in to comment.