Treat empty SSH settings in the config as not set
The example config has empty remote_sudo and numeric_ids values, which made getboolean fail with "Bad configuration file" if the [server] section was uncommented, and an empty ssh_keyfile was used as the key path. Treat empty values as false or not set, and show false in the example config.
This commit is contained in:
@@ -18,5 +18,5 @@ keep=-1
|
|||||||
# ssh_host=
|
# ssh_host=
|
||||||
# ssh_user=
|
# ssh_user=
|
||||||
# ssh_keyfile=
|
# ssh_keyfile=
|
||||||
# remote_sudo=
|
# remote_sudo=false
|
||||||
# numeric_ids=
|
# numeric_ids=false
|
||||||
|
|||||||
@@ -849,26 +849,14 @@ def _read_config(config_file, user: Optional[str] = None):
|
|||||||
config_args['ssh_host'] = config.get('server', 'ssh_host', fallback='').strip() or None
|
config_args['ssh_host'] = config.get('server', 'ssh_host', fallback='').strip() or None
|
||||||
config_args['ssh_user'] = config.get('server', 'ssh_user', fallback='').strip() or None
|
config_args['ssh_user'] = config.get('server', 'ssh_user', fallback='').strip() or None
|
||||||
|
|
||||||
try:
|
config_args['ssh_keyfile'] = config.get('server', 'ssh_keyfile', fallback='').strip() or None
|
||||||
ssh_keyfile = config.get('server', 'ssh_keyfile')
|
|
||||||
except (configparser.NoSectionError, configparser.NoOptionError):
|
|
||||||
ssh_keyfile = None
|
|
||||||
|
|
||||||
config_args['ssh_keyfile'] = ssh_keyfile
|
# Empty values (as in the example config) count as false
|
||||||
|
for key in ['remote_sudo', 'numeric_ids']:
|
||||||
try:
|
if config.get('server', key, fallback='').strip() == '':
|
||||||
remote_sudo = config.getboolean('server', 'remote_sudo')
|
config_args[key] = False
|
||||||
except (configparser.NoSectionError, configparser.NoOptionError):
|
else:
|
||||||
remote_sudo = False
|
config_args[key] = config.getboolean('server', key)
|
||||||
|
|
||||||
config_args['remote_sudo'] = remote_sudo
|
|
||||||
|
|
||||||
try:
|
|
||||||
numeric_ids = config.getboolean('server', 'numeric_ids')
|
|
||||||
except (configparser.NoSectionError, configparser.NoOptionError):
|
|
||||||
numeric_ids = False
|
|
||||||
|
|
||||||
config_args['numeric_ids'] = numeric_ids
|
|
||||||
|
|
||||||
return config_args
|
return config_args
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user