Skip to content

Commit

Permalink
♻️ Leverage more of Blacklight's Solr URL (#6647)
Browse files Browse the repository at this point in the history
Prior to this commit, our defaults were not considering scheme, core,
password, nor user from the Blacklight URL.

What this meant was that the generated URL could strip away useful
information from the configured URL; in particular the user and password
information.

With this change, we utilize more of the underlying Blacklight
configuration; a net positive.

Co-authored-by: Daniel Pierce <[email protected]>
  • Loading branch information
jeremyf and dlpierce authored Feb 1, 2024
1 parent 1fe4a2f commit d74e9e9
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions lib/valkyrie/indexing/solr/indexing_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,14 @@ def blacklight_based_config
return {}
end

{ 'host' => bl_index.host,
{
'host' => bl_index.host,
'user' => bl_index.user,
'password' => bl_index.password,
'scheme' => bl_index.scheme,
'port' => bl_index.port,
'core' => 'hyrax-valkyrie' }
'core' => bl_index.path.split("/")[2] || 'hyrax-valkyrie'
}.compact
end

def connection_url
Expand All @@ -78,12 +83,17 @@ def connection_url
{}
end

# if any configuration is missing, derive it from Blacklight
# Given how we're building blacklight_based_config, there won't be a URL. So let's avoid
# that whole logic path.
return config['url'] if config['url'].present?

# Derive any missing configuration from Blacklight.
config = blacklight_based_config.with_indifferent_access.merge(config)

return config['url'] if config['url'].present?
url = "#{config.fetch('scheme', 'http')}://"
url = "#{url}#{config['user']}:#{config['password']}@" if config.key?('user') && config.key?('password')

"http://#{config['host']}:#{config['port']}/solr/#{config['core']}"
"#{url}#{config['host']}:#{config['port']}/solr/#{config['core']}"
end

def default_connection
Expand Down

0 comments on commit d74e9e9

Please sign in to comment.