From f21029e15b571476642083ff1aff8ee3b1d37a82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= <40151420+ldericher@users.noreply.github.com> Date: Thu, 7 Apr 2022 10:27:08 +0000 Subject: [PATCH] get_certificate cleanup --- api/kiwi_vpn_api/easyrsa.py | 17 ++++++++--------- api/kiwi_vpn_api/routers/_common.py | 2 +- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/api/kiwi_vpn_api/easyrsa.py b/api/kiwi_vpn_api/easyrsa.py index c833338..3edae71 100644 --- a/api/kiwi_vpn_api/easyrsa.py +++ b/api/kiwi_vpn_api/easyrsa.py @@ -237,9 +237,14 @@ class EasyRSA: def get_certificate( self, - cert_type: CertificateType | None, + *, + cert_type: CertificateType | None = None, dn: DistinguishedName | None = None, ) -> x509.Certificate | None: + """ + Get a certificate from the PKI directory + """ + if cert_type is CertificateType.ca: cert_filename = self.output_directory.joinpath("ca.crt") @@ -279,10 +284,7 @@ class EasyRSA: EASYRSA_REQ_CN="kiwi-vpn-ca", ) - cert = self.get_certificate( - cert_type=CertificateType.ca, - dn=None, - ) + cert = self.get_certificate(cert_type=CertificateType.ca) assert cert is not None # # this takes long! @@ -340,10 +342,7 @@ class EasyRSA: **dn.easyrsa_env, ) - return self.get_certificate( - cert_type=None, - dn=dn, - ) + return self.get_certificate(dn=dn) def revoke( self, diff --git a/api/kiwi_vpn_api/routers/_common.py b/api/kiwi_vpn_api/routers/_common.py index 3aba42e..d44dd3d 100644 --- a/api/kiwi_vpn_api/routers/_common.py +++ b/api/kiwi_vpn_api/routers/_common.py @@ -145,7 +145,7 @@ async def get_pki() -> EasyRSA: - 425: EasyRSA not initialized """ - if EASYRSA.get_certificate(CertificateType.ca) is None: + if EASYRSA.get_certificate(cert_type=CertificateType.ca) is None: raise HTTPException(status_code=status.HTTP_425_TOO_EARLY) return EASYRSA