From 5842336e6668e1f5452cb0448e560ddab5d480ba Mon Sep 17 00:00:00 2001 From: Sebb Date: Thu, 3 Oct 2024 22:01:24 +0100 Subject: [PATCH] Fetch rwhosts from ldap misc file --- lib/whimsy/asf/ldap.rb | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/whimsy/asf/ldap.rb b/lib/whimsy/asf/ldap.rb index 081e2a6fd8..0e41194b7e 100644 --- a/lib/whimsy/asf/ldap.rb +++ b/lib/whimsy/asf/ldap.rb @@ -52,6 +52,7 @@ module LDAP CONNECT_LOCK = Mutex.new LDAP_CREDS = ASF::Config.get(:ldap_creds) + LDAP_MISC = '/usr/local/etc/asfldapmisc.yml' # connect to LDAP def self.connect(hosts = nil) @@ -151,7 +152,26 @@ def self.host def self.rwhosts return @rwhosts if @rwhosts # cache the rwhosts list rwhosts = Array(ASF::Config.get(:ldaprw)) # allow separate override for RW LDAP - rwhosts = hosts if rwhosts.empty? # default to RO hosts + if rwhosts.empty? + if File.exist? LDAP_MISC + begin + ldap_misc = YAML.safe_load(File.read(LDAP_MISC)) + rwhosts = Array(ldap_misc['ldapclient_asf']['write_uri']) + rescue StandardError => e + Wunderbar.warn "Could not parse write_uri: #{e.inspect}" + end + else + Wunderbar.warn "Could not find #{LDAP_MISC}" + end + if rwhosts.empty? # default to RO hosts + rwhosts = hosts + Wunderbar.debug 'Using rwhosts from hosts' + else + Wunderbar.debug 'Using rwhosts from LDAP_MISC' + end + else + Wunderbar.debug 'Using rwhosts from Whimsy config' + end raise 'Cannot determine writable LDAP URI from ldap.conf or local config!' if rwhosts.empty? @rwhosts = rwhosts end