mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
Filter out the __pub keys passed via **kwargs for dnsmasq.set_config
Fixes #34263
This commit is contained in:
parent
fd380c79b9
commit
c6a3476abb
@ -2,14 +2,15 @@
|
||||
'''
|
||||
Module for managing dnsmasq
|
||||
'''
|
||||
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import
|
||||
import logging
|
||||
import os
|
||||
|
||||
# Import salt libs
|
||||
import salt.utils
|
||||
|
||||
# Import python libs
|
||||
import os
|
||||
import logging
|
||||
from salt.exceptions import CommandExecutionError
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@ -98,20 +99,28 @@ def set_config(config_file='/etc/dnsmasq.conf', follow=True, **kwargs):
|
||||
if filename.endswith('#') and filename.endswith('#'):
|
||||
continue
|
||||
includes.append('{0}/{1}'.format(dnsopts['conf-dir'], filename))
|
||||
|
||||
ret_kwargs = {}
|
||||
for key in kwargs:
|
||||
# Filter out __pub keys as they should not be added to the config file
|
||||
# See Issue #34263 for more information
|
||||
if key.startswith('__'):
|
||||
continue
|
||||
ret_kwargs[key] = kwargs[key]
|
||||
|
||||
if key in dnsopts:
|
||||
if isinstance(dnsopts[key], str):
|
||||
for config in includes:
|
||||
__salt__['file.sed'](path=config,
|
||||
before='^{0}=.*'.format(key),
|
||||
after='{0}={1}'.format(key, kwargs[key]))
|
||||
before='^{0}=.*'.format(key),
|
||||
after='{0}={1}'.format(key, kwargs[key]))
|
||||
else:
|
||||
__salt__['file.append'](config_file,
|
||||
'{0}={1}'.format(key, kwargs[key]))
|
||||
'{0}={1}'.format(key, kwargs[key]))
|
||||
else:
|
||||
__salt__['file.append'](config_file,
|
||||
'{0}={1}'.format(key, kwargs[key]))
|
||||
return kwargs
|
||||
return ret_kwargs
|
||||
|
||||
|
||||
def get_config(config_file='/etc/dnsmasq.conf'):
|
||||
@ -148,6 +157,12 @@ def _parse_dnamasq(filename):
|
||||
Generic function for parsing dnsmasq files including includes.
|
||||
'''
|
||||
fileopts = {}
|
||||
|
||||
if not os.path.isfile(filename):
|
||||
raise CommandExecutionError(
|
||||
'Error: No such file \'{0}\''.format(filename)
|
||||
)
|
||||
|
||||
with salt.utils.fopen(filename, 'r') as fp_:
|
||||
for line in fp_:
|
||||
if not line.strip():
|
||||
|
Loading…
Reference in New Issue
Block a user