From ff30fb71d2cabeae6951d3c77ed536fe1070c415 Mon Sep 17 00:00:00 2001 From: Joona Hoikkala Date: Fri, 29 Apr 2016 15:31:59 +0300 Subject: [PATCH] New method for determining UA string --- certbot/client.py | 2 +- certbot/le_util.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/certbot/client.py b/certbot/client.py index 60e37a787..4c90a84ca 100644 --- a/certbot/client.py +++ b/certbot/client.py @@ -52,7 +52,7 @@ def _determine_user_agent(config): if config.user_agent is None: ua = "CertbotACMEClient/{0} ({1}) Authenticator/{2} Installer/{3}" - ua = ua.format(certbot.__version__, " ".join(le_util.get_os_info()), + ua = ua.format(certbot.__version__, le_util.get_os_info_ua(), config.authenticator, config.installer) else: ua = config.user_agent diff --git a/certbot/le_util.py b/certbot/le_util.py index c1f4d1acd..fcde840c9 100644 --- a/certbot/le_util.py +++ b/certbot/le_util.py @@ -228,6 +228,24 @@ def get_os_info(filepath="/etc/os-release"): return get_python_os_info() +def get_os_info_ua(filepath="/etc/os-release"): + """ + Get OS name and version string for User Agent + + :param str filepath: File path of os-release file + :returns: os_ua + :rtype: `str` + """ + + if os.path.isfile(filepath): + os_ua = _get_systemd_os_release_var("NAME", filepath=filepath) + if os_ua: + return os_ua + + # Fallback + return " ".join(get_python_os_info()) + + def get_systemd_os_info(filepath="/etc/os-release"): """ Parse systemd /etc/os-release for distribution information