Skip to content

Commit

Permalink
Support for pure yaml in is_master.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
h-haaks committed Apr 9, 2024
1 parent 70dac73 commit 433300e
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions lib/facter/is_master.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,25 @@ def mongod_conf_file
def get_options_from_hash_config(config)
result = []

result << "--port #{config['net.port']}" unless config['net.port'].nil?
# use --tls and --host if:
# - tlsMode is "requireTLS"
# - Parameter --tlsCertificateKeyFile is set
# - Parameter --tlsCAFile is set
result << "--tls --host #{Facter.value(:fqdn)}" if config['net.tls.mode'] == 'requireTLS' || !config['net.tls.certificateKeyFile'].nil? || !config['net.tls.CAFile'].nil?
result << "--tlsCertificateKeyFile #{config['net.tls.certificateKeyFile']}" unless config['net.tls.certificateKeyFile'].nil?
result << "--tlsCAFile #{config['net.tls.CAFile']}" unless config['net.tls.CAFile'].nil?

result << '--ipv6' unless config['net.ipv6'].nil?
port = config['net.port']
port = config.fetch('net', {}).fetch('port', nil) if port.nil?
ipv6 = config['net.ipv6']
ipv6 = config.fetch('net', {}).fetch('ipv6', nil) if ipv6.nil?
tls_mode = config['net.tls.mode']
tls_mode = config.fetch('net', {}).fetch('tls', {}).fetch('mode', nil) if tls_mode.nil?

result << "--port #{port}" unless port.nil?
result << '--ipv6' if ipv6
unless tls_mode.nil? || tls_mode == 'diabled'
tls_cert_key = config['net.tls.certificateKeyFile']
tls_cert_key = config.fetch('net', {}).fetch('tls', {}).fetch('certificateKeyFile', nil) if tls_cert_key.nil?
tls_ca = config['net.tls.CAFile']
tls_ca = config.fetch('net', {}).fetch('tls', {}).fetch('CAFile', nil) if tls_ca.nil?

result << "--tls --host #{Facter.value(:fqdn)}"
result << "--tlsCertificateKeyFile #{tls_cert_key}" unless tls_cert_key.nil?
result << "--tlsCAFile #{tls_ca}" unless tls_ca.nil?
end

result.join(' ')
end
Expand Down

0 comments on commit 433300e

Please sign in to comment.