From 65c87d55df2c0c12ed0effa3c6351d943dd5ea0c Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Thu, 14 May 2020 03:56:32 +0200 Subject: [PATCH] Try to not have weird warnings if no diagnosis ran yet... --- src/yunohost/certificate.py | 19 +++++++++---------- src/yunohost/diagnosis.py | 5 +++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/yunohost/certificate.py b/src/yunohost/certificate.py index 366f45462..4b5adb754 100644 --- a/src/yunohost/certificate.py +++ b/src/yunohost/certificate.py @@ -103,10 +103,16 @@ def certificate_status(domain_list, full=False): if not full: del status["subject"] del status["CA_name"] - del status["ACME_eligible"] status["CA_type"] = status["CA_type"]["verbose"] status["summary"] = status["summary"]["verbose"] + if full: + try: + _check_domain_is_ready_for_ACME(domain) + status["ACME_eligible"] = True + except: + status["ACME_eligible"] = False + del status["domain"] certificates[domain] = status @@ -700,12 +706,6 @@ def _get_status(domain): "verbose": "Unknown?", } - try: - _check_domain_is_ready_for_ACME(domain) - ACME_eligible = True - except: - ACME_eligible = False - return { "domain": domain, "subject": cert_subject, @@ -713,7 +713,6 @@ def _get_status(domain): "CA_type": CA_type, "validity": days_remaining, "summary": status_summary, - "ACME_eligible": ACME_eligible } # @@ -791,8 +790,8 @@ def _backup_current_cert(domain): def _check_domain_is_ready_for_ACME(domain): - dnsrecords = Diagnoser.get_cached_report("dnsrecords", item={"domain": domain, "category": "basic"}) or {} - httpreachable = Diagnoser.get_cached_report("web", item={"domain": domain}) or {} + dnsrecords = Diagnoser.get_cached_report("dnsrecords", item={"domain": domain, "category": "basic"}, warn_if_no_cache=False) or {} + httpreachable = Diagnoser.get_cached_report("web", item={"domain": domain}, warn_if_no_cache=False) or {} if not dnsrecords or not httpreachable: raise YunohostError('certmanager_domain_not_diagnosed_yet', domain=domain) diff --git a/src/yunohost/diagnosis.py b/src/yunohost/diagnosis.py index 806285f52..3f34f206e 100644 --- a/src/yunohost/diagnosis.py +++ b/src/yunohost/diagnosis.py @@ -427,10 +427,11 @@ class Diagnoser(): return os.path.join(DIAGNOSIS_CACHE, "%s.json" % id_) @staticmethod - def get_cached_report(id_, item=None): + def get_cached_report(id_, item=None, warn_if_no_cache=True): cache_file = Diagnoser.cache_file(id_) if not os.path.exists(cache_file): - logger.warning(m18n.n("diagnosis_no_cache", category=id_)) + if warn_if_no_cache: + logger.warning(m18n.n("diagnosis_no_cache", category=id_)) report = {"id": id_, "cached_for": -1, "timestamp": -1,