diff --git a/src/nethsec/inventory/__init__.py b/src/nethsec/inventory/__init__.py index 4ebc857e..e122867c 100644 --- a/src/nethsec/inventory/__init__.py +++ b/src/nethsec/inventory/__init__.py @@ -80,6 +80,25 @@ def fact_custom_certificates(uci: EUci): pass return ret +def fact_acme_certificates(uci: EUci): + ret = { + 'count': 0, + 'issued': 0, + 'pending': 0, + } + requested_certificates = utils.get_all_by_type(uci, 'acme', 'cert') + enabled_certificates = [certificate for certificate in requested_certificates + if requested_certificates[certificate]['enabled'] == '1'] + for certificate in enabled_certificates: + ret['count'] += 1 + domain = requested_certificates[certificate]['domains'][0] + cert_path = f'/etc/ssl/acme/{domain}.fullchain.crt' + if os.path.isfile(cert_path): + ret['issued'] += 1 + else: + ret['pending'] += 1 + return ret + def fact_subscription_status(uci: EUci): return { 'status': uci.get('ns-plug', 'config', 'type', default='no') }