Skip to content
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

Merged
merged 5 commits into from
Aug 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion utils/windows_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,29 @@

log = logging.getLogger(__name__)

config_attributes = ['api_key', 'tags', 'hostname', 'proxy_host', 'proxy_port', 'proxy_user', 'proxy_password']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🍰


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:
Copy link
Contributor

Choose a reason for hiding this comment

The 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
Expand Down Expand Up @@ -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')
9 changes: 7 additions & 2 deletions win32/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, why do we want to remove it from the registry?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.
Expand Down