EASYRSA global object

This commit is contained in:
Jörn-Michael Miehe 2022-04-05 22:39:09 +00:00
parent c0388d58c1
commit e6fe35d14e
2 changed files with 8 additions and 23 deletions

View file

@ -4,7 +4,6 @@ Python interface to EasyRSA CA.
from __future__ import annotations
import functools
import subprocess
from enum import Enum, auto
from pathlib import Path
@ -140,20 +139,6 @@ class EasyRSA:
None: {},
}
@classmethod
@functools.lru_cache
def _load(cls) -> EasyRSA:
return cls()
@classmethod
@property
def _(cls) -> EasyRSA:
"""
Get the singleton
"""
return cls._load()
@property
def output_directory(self) -> Path:
"""
@ -300,14 +285,14 @@ class EasyRSA:
)
EASYRSA = EasyRSA()
# some basic test
if __name__ == "__main__":
easy_rsa = EasyRSA()
easy_rsa.init_pki()
ca = easy_rsa.build_ca()
server = easy_rsa.issue(CertificateType.server)
ca = EASYRSA.build_ca()
server = EASYRSA.issue(CertificateType.server)
client = None
# check if configured
@ -316,7 +301,7 @@ if __name__ == "__main__":
Connection.connect(current_config.db.uri)
if (device := Device.get(1)) is not None:
client = easy_rsa.issue(
client = EASYRSA.issue(
dn=DistinguishedName.build(device)
)

View file

@ -5,7 +5,7 @@
from fastapi import APIRouter, Depends, HTTPException, status
from ..db import Device, DeviceCreate, DeviceRead, User
from ..easyrsa import DistinguishedName, EasyRSA
from ..easyrsa import EASYRSA, DistinguishedName
from ._common import (Responses, get_current_user, get_device_by_id,
get_user_by_name)
@ -111,7 +111,7 @@ async def request_certificate_issuance(
if device.approved:
# issue the certificate immediately
if (certificate := EasyRSA._.issue(
if (certificate := EASYRSA.issue(
dn=DistinguishedName.build(device)
)) is not None:
device.expiry = certificate.not_valid_after