From 433300e6fd9702ccde1de50f2173ee468010f247 Mon Sep 17 00:00:00 2001 From: Hugo Haakseth Date: Wed, 10 Apr 2024 00:35:25 +0200 Subject: [PATCH] Support for pure yaml in is_master.rb --- lib/facter/is_master.rb | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/lib/facter/is_master.rb b/lib/facter/is_master.rb index c225b4b0b..0ba35a6ce 100644 --- a/lib/facter/is_master.rb +++ b/lib/facter/is_master.rb @@ -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