EASYRSA global object
This commit is contained in:
parent
c0388d58c1
commit
e6fe35d14e
2 changed files with 8 additions and 23 deletions
|
@ -4,7 +4,6 @@ Python interface to EasyRSA CA.
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import functools
|
|
||||||
import subprocess
|
import subprocess
|
||||||
from enum import Enum, auto
|
from enum import Enum, auto
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
@ -140,20 +139,6 @@ class EasyRSA:
|
||||||
None: {},
|
None: {},
|
||||||
}
|
}
|
||||||
|
|
||||||
@classmethod
|
|
||||||
@functools.lru_cache
|
|
||||||
def _load(cls) -> EasyRSA:
|
|
||||||
return cls()
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
@property
|
|
||||||
def _(cls) -> EasyRSA:
|
|
||||||
"""
|
|
||||||
Get the singleton
|
|
||||||
"""
|
|
||||||
|
|
||||||
return cls._load()
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def output_directory(self) -> Path:
|
def output_directory(self) -> Path:
|
||||||
"""
|
"""
|
||||||
|
@ -300,14 +285,14 @@ class EasyRSA:
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
EASYRSA = EasyRSA()
|
||||||
|
|
||||||
|
|
||||||
# some basic test
|
# some basic test
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
easy_rsa = EasyRSA()
|
ca = EASYRSA.build_ca()
|
||||||
easy_rsa.init_pki()
|
server = EASYRSA.issue(CertificateType.server)
|
||||||
|
|
||||||
ca = easy_rsa.build_ca()
|
|
||||||
server = easy_rsa.issue(CertificateType.server)
|
|
||||||
client = None
|
client = None
|
||||||
|
|
||||||
# check if configured
|
# check if configured
|
||||||
|
@ -316,7 +301,7 @@ if __name__ == "__main__":
|
||||||
Connection.connect(current_config.db.uri)
|
Connection.connect(current_config.db.uri)
|
||||||
|
|
||||||
if (device := Device.get(1)) is not None:
|
if (device := Device.get(1)) is not None:
|
||||||
client = easy_rsa.issue(
|
client = EASYRSA.issue(
|
||||||
dn=DistinguishedName.build(device)
|
dn=DistinguishedName.build(device)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
from fastapi import APIRouter, Depends, HTTPException, status
|
from fastapi import APIRouter, Depends, HTTPException, status
|
||||||
|
|
||||||
from ..db import Device, DeviceCreate, DeviceRead, User
|
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,
|
from ._common import (Responses, get_current_user, get_device_by_id,
|
||||||
get_user_by_name)
|
get_user_by_name)
|
||||||
|
|
||||||
|
@ -111,7 +111,7 @@ async def request_certificate_issuance(
|
||||||
|
|
||||||
if device.approved:
|
if device.approved:
|
||||||
# issue the certificate immediately
|
# issue the certificate immediately
|
||||||
if (certificate := EasyRSA._.issue(
|
if (certificate := EASYRSA.issue(
|
||||||
dn=DistinguishedName.build(device)
|
dn=DistinguishedName.build(device)
|
||||||
)) is not None:
|
)) is not None:
|
||||||
device.expiry = certificate.not_valid_after
|
device.expiry = certificate.not_valid_after
|
||||||
|
|
Loading…
Reference in a new issue