Fix UA flag setting (and set more of them)

This commit is contained in:
Peter Eckersley
2017-04-28 18:02:34 -07:00
parent 5be0811bdc
commit 0a4ee306a9
2 changed files with 37 additions and 12 deletions
+34 -11
View File
@@ -58,27 +58,50 @@ def determine_user_agent(config):
auto = cli.cli_command
else:
auto = "other"
flags = "dup" if config.duplicate else ""
flags += "force" if config.renew_by_default else ""
ua = ("CertbotACMEClient/{0} ({1}; {2}) Authenticator/{3} Installer/{4} "
"({5}; flags: {6}) Py/{7}")
ua = ua.format(certbot.__version__, auto, util.get_os_info_ua(),
config.authenticator, config.installer, config.verb, flags,
platform.python_version())
config.authenticator, config.installer, config.verb,
ua_flags(config), platform.python_version())
else:
ua = config.user_agent
return ua
def ua_flags(config):
"Turn some very important CLI flags into clues in the user agent."
if isinstance(config, DummyConfig):
return "FLAGS"
flags = []
if config.duplicate:
flags.append("dup")
if config.renew_by_default:
flags.append("frn")
if config.allow_subset_of_names:
flags.append("asn")
if config.noninteractive_mode:
flags.append("n")
hook_names = ("pre", "post", "renew", "manual_auth", "manual_cleanup")
hooks = [getattr(config, h + "_hook") for h in hook_names]
if any(hooks):
flags.append("hook")
return " ".join(flags)
class DummyConfig(object):
"Shim for computing a sample user agent."
def __init__(self):
self.authenticator = "XXX"
self.installer = "YYY"
self.user_agent = None
self.verb = "SUBCOMMAND"
def __getattr__(self, name):
"Any config properties we might have are None."
return None
def sample_user_agent():
"Document what this Certbot's user agent string will be like."
class DummyConfig(object):
"Shim for computing a sample user agent."
def __init__(self):
self.authenticator = "XXX"
self.installer = "YYY"
self.user_agent = None
self.verb = "SUBCOMMAND"
return determine_user_agent(DummyConfig())