ownca
ownca copied to clipboard
Add "read only mode" which only looks for CA but does not create any directories.
As far as I can tell, it isn't possible to use construct a CertificateAuthority
object or call ownca_directory()
without creating certificate directories if those don't exist. Ideally there would be a read-only mode which can check for the presence of an existing CA without touching the file system. I would like to allow the user to call these functions without worrying about current working directory or what file system changes might be made.
I think allowing ownca_directory()
to not modify the file system with a parameter would be sufficient. Then you could call that to check for an existing CA before calling the constructor.
I think something like this would do it:
from ownca._constants import CA_CERTS_DIR
from ownca._constants import CA_PRIVATE_DIR
from ownca.utils import file_data_status
from ownca.utils import ownca_directory
def ca_dirs_exist(ca_storage: str = "") -> bool:
if (
ca_storage and
os.path.exists(ca_storage) and
os.path.exists(os.path.join(ca_storage, CA_CERTS_DIR)) and
os.path.exists(os.path.join(ca_storage, CA_PRIVATE_DIR))
):
return True
return False
def ca_exists(ca_storage: str = "") -> Optional[bool]:
if ca_dirs_exist(ca_storage):
return file_data_status(ownca_directory(ca_storage))
return None
Thanks
Andy