Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "read only mode" which only looks for CA but does not create any directories. #96

Open
anschweitzer opened this issue Jul 11, 2023 · 0 comments

Comments

@anschweitzer
Copy link

anschweitzer commented Jul 11, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant