zulip_tools: Add a get_config_bool to match Puppet logic.

Unfortunately, the existing use of this logic in `process_fts_updates`
cannot switch to using this code, as that code cannot import
zulip_tools.
This commit is contained in:
Alex Vandiver 2022-01-20 04:14:57 +00:00 committed by Tim Abbott
parent 4d02ac6fb1
commit 530980cf31
2 changed files with 12 additions and 1 deletions

View File

@ -6,7 +6,8 @@ module Puppet::Parser::Functions
output = `/usr/bin/crudini --get #{zulip_conf_path} #{joined} 2>&1`; result = $?.success?
if result
if [true, false].include? default
# If the default is a bool, coerce into a bool
# If the default is a bool, coerce into a bool. This list is also
# maintained in scripts/lib/zulip_tools.py
['1','y','t','true','yes','enable','enabled'].include? output.strip.downcase
else
output.strip

View File

@ -595,6 +595,16 @@ def get_config(
return default_value
def get_config_bool(
config_file: configparser.RawConfigParser, section: str, key: str, default_value: bool = False
) -> bool:
if config_file.has_option(section, key):
val = config_file.get(section, key)
# This list is parallel to puppet/zulip/lib/puppet/parser/functions/zulipconf.rb
return val in ["1", "y", "t", "true", "yes", "enable", "enabled"]
return default_value
def get_config_file() -> configparser.RawConfigParser:
config_file = configparser.RawConfigParser()
config_file.read("/etc/zulip/zulip.conf")