-
Notifications
You must be signed in to change notification settings - Fork 813
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Db/proxy cfg cmdline #3470
Db/proxy cfg cmdline #3470
Changes from all commits
44feadb
fcc5220
6187caa
4080b58
841bc8d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,13 +17,29 @@ | |
|
||
log = logging.getLogger(__name__) | ||
|
||
config_attributes = ['api_key', 'tags', 'hostname', 'proxy_host', 'proxy_port', 'proxy_user', 'proxy_password'] | ||
|
||
def remove_registry_conf(): | ||
try: | ||
with _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, | ||
WINDOWS_REG_PATH, 0, _winreg.KEY_WRITE) as reg_key: | ||
for attribute in config_attributes: | ||
try: | ||
_winreg.DeleteValue(reg_key, attribute) | ||
except Exception as e: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will it error if the key doesn't exists? In that case, it seems like we would want to ignore that error instead of logging it. |
||
log.error("Failed to delete value %s %s", attribute, str(e)) | ||
# it's ok if it's not there. | ||
pass | ||
except Exception: | ||
# also OK if the whole tree isn't there | ||
pass | ||
|
||
def get_registry_conf(agentConfig): | ||
registry_conf = {} | ||
try: | ||
with _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, | ||
WINDOWS_REG_PATH) as reg_key: | ||
for attribute in ['api_key', 'tags', 'hostname']: | ||
for attribute in config_attributes: | ||
option = _winreg.QueryValueEx(reg_key, attribute)[0] | ||
if option != '': | ||
registry_conf[attribute] = option | ||
|
@@ -99,5 +115,6 @@ def update_conf_file(registry_conf, config_path): | |
os.rename(temp_config_path, config_path) | ||
except OSError as e: | ||
log.exception('Unable to save new datadog.conf') | ||
raise | ||
else: | ||
log.debug('Successfully saved the new datadog.conf') |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,7 @@ | |
from config import get_config, get_config_path, get_confd_path | ||
from jmxfetch import JMXFetch | ||
from utils.jmx import JMXFiles | ||
from utils.windows_configuration import get_registry_conf, update_conf_file | ||
from utils.windows_configuration import get_registry_conf, update_conf_file, remove_registry_conf | ||
|
||
|
||
log = logging.getLogger('service') | ||
|
@@ -134,7 +134,12 @@ def _update_config_file(self, config): | |
config.update(registry_conf) | ||
if registry_conf: | ||
log.info('Updating conf file options: %s', registry_conf.keys()) | ||
update_conf_file(registry_conf, get_config_path()) | ||
try: | ||
update_conf_file(registry_conf, get_config_path()) | ||
log.info('update succeeded, deleting old values') | ||
remove_registry_conf() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just curious, why do we want to remove it from the registry? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wanted to remove the values from the registry so we don't end up with "two masters"... you put something on the install config. Then the install works. Then you change the config, but this is still lingering in the registry, waiting to be written back out to the config file (and killing your changes) |
||
except Exception: | ||
log.warning('Failed to update config file; registry configuration persisted') | ||
|
||
def SvcStop(self): | ||
# Stop all services. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🍰