Skip to content

Commit

Permalink
fix docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiasertl committed Mar 9, 2024
1 parent 8837a49 commit de55d20
Show file tree
Hide file tree
Showing 36 changed files with 69 additions and 66 deletions.
2 changes: 1 addition & 1 deletion ca/django_ca/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
}
)

DEFAULT_STORAGE_BACKEND = "django_ca.backends.storages.StoragesBackend"
DEFAULT_STORAGE_BACKEND = "django_ca.key_backends.storages.StoragesBackend"

#: Mapping of elliptic curve names to the implementing classes
ELLIPTIC_CURVE_TYPES: "MappingProxyType[EllipticCurves, Type[ec.EllipticCurve]]" = MappingProxyType(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@

"""Public exports of the backend module."""

from django_ca.backends.base import KeyBackend, key_backends
from django_ca.key_backends.base import KeyBackend, key_backends

__all__ = ["KeyBackend", "key_backends"]
23 changes: 12 additions & 11 deletions ca/django_ca/backends/base.py → ca/django_ca/key_backends/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ def add_create_private_key_group(self, parser: CommandParser) -> Optional[Argume
"""Add an argument group for arguments for private key generation with this backend.
By default, the title and description of the argument group is based on
:py:attr:`~django_ca.backends.base.KeyBackend.alias`,
:py:attr:`~django_ca.backends.base.KeyBackend.title` and
:py:attr:`~django_ca.backends.base.KeyBackend.description`.
:py:attr:`~django_ca.key_backends.base.KeyBackend.alias`,
:py:attr:`~django_ca.key_backends.base.KeyBackend.title` and
:py:attr:`~django_ca.key_backends.base.KeyBackend.description`.
Return ``None`` if you don't need to create such a group.
"""
Expand All @@ -92,16 +92,16 @@ def add_store_private_key_group(self, parser: CommandParser) -> Optional[Argumen
"""Add an argument group for storing private keys (when importing an existing CA).
By default, this method adds the same group as
:py:func:`~django_ca.backends.base.KeyBackend.add_create_private_key_group`
:py:func:`~django_ca.key_backends.base.KeyBackend.add_create_private_key_group`
"""
return self.add_create_private_key_group(parser)

def add_use_private_key_group(self, parser: CommandParser) -> Optional[ArgumentGroup]:
"""Add an argument group for arguments required for using a private key stored with this backend.
By default, the title and description of the argument group is based on
:py:attr:`~django_ca.backends.base.KeyBackend.alias` and
:py:attr:`~django_ca.backends.base.KeyBackend.title`.
:py:attr:`~django_ca.key_backends.base.KeyBackend.alias` and
:py:attr:`~django_ca.key_backends.base.KeyBackend.title`.
Return ``None`` if you don't need to create such a group.
"""
Expand All @@ -116,15 +116,15 @@ def add_create_private_key_arguments(self, group: ArgumentGroup) -> None:
Add arguments that can be used for generating private keys with your backend to `group`. The arguments
you add here are expected to be loaded (and validated) using
:py:func:`~django_ca.backends.base.KeyBackend.get_create_private_key_options`.
:py:func:`~django_ca.key_backends.base.KeyBackend.get_create_private_key_options`.
"""

@abc.abstractmethod
def add_use_parent_private_key_arguments(self, group: ArgumentGroup) -> None:
"""Add arguments for loading the private key of a parent certificate authority.
The arguments you add here are expected to be loaded (and validated) using
:py:func:`~django_ca.backends.base.KeyBackend.get_load_parent_private_key_options`.
:py:func:`~django_ca.key_backends.base.KeyBackend.get_use_parent_private_key_options`.
"""

@abc.abstractmethod
Expand All @@ -136,7 +136,7 @@ def add_use_private_key_arguments(self, group: ArgumentGroup) -> None:
"""Add arguments required for using private key stored with this backend.
The arguments you add here are expected to be loaded (and validated) using
:py:func:`~django_ca.backends.base.KeyBackend.get_load_parent_private_key_options`.
:py:func:`~django_ca.key_backends.base.KeyBackend.get_use_parent_private_key_options`.
"""
return None

Expand All @@ -147,7 +147,8 @@ def get_create_private_key_options(
"""Load options to create private keys into a Pydantic model.
`options` is the dictionary of arguments to ``manage.py init_ca`` (including default values). The
returned model will be passed to :py:func:`~django_ca.backends.base.KeyBackend.create_private_key`.
returned model will be passed to
:py:func:`~django_ca.key_backends.base.KeyBackend.create_private_key`.
"""

@abc.abstractmethod
Expand Down Expand Up @@ -179,7 +180,7 @@ def is_usable(
"""Boolean returning if the given `ca` can be used to sign new certificates (or CRLs).
The `options` are the options returned by
:py:func:`~django_ca.backends.base.KeyBackend.get_load_private_key_options`. It may be ``None`` in
:py:func:`~django_ca.key_backends.base.KeyBackend.get_use_private_key_options`. It may be ``None`` in
cases where key options cannot (yet) be loaded. If ``None``, the backend should return ``False`` if it
knows for sure that it will not be usable, and ``True`` if usability cannot be determined.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
from django.core.files.storage import storages

from django_ca import constants
from django_ca.backends.base import KeyBackend
from django_ca.key_backends.base import KeyBackend
from django_ca.management.actions import PasswordAction
from django_ca.management.base import add_elliptic_curve, add_key_size, add_password
from django_ca.typehints import AllowedHashTypes, ArgumentGroup, ParsableKeyType
Expand Down
2 changes: 1 addition & 1 deletion ca/django_ca/management/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
from django.core.validators import URLValidator

from django_ca import ca_settings, constants
from django_ca.backends import KeyBackend, key_backends
from django_ca.constants import EXTENSION_DEFAULT_CRITICAL, KEY_USAGE_NAMES, ReasonFlags
from django_ca.key_backends import KeyBackend, key_backends
from django_ca.models import Certificate, CertificateAuthority
from django_ca.typehints import AllowedHashTypes, AlternativeNameExtensionType, EllipticCurves
from django_ca.utils import is_power2, parse_encoding, parse_general_name
Expand Down
2 changes: 1 addition & 1 deletion ca/django_ca/management/commands/import_ca.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
from django.core.management.base import CommandError, CommandParser

from django_ca import ca_settings, constants
from django_ca.backends import KeyBackend, key_backends
from django_ca.constants import PRIVATE_KEY_TYPES, PUBLIC_KEY_TYPES
from django_ca.key_backends import KeyBackend, key_backends
from django_ca.management.actions import PasswordAction
from django_ca.management.base import BaseCommand
from django_ca.management.mixins import CertificateAuthorityDetailMixin, StorePrivateKeyMixin
Expand Down
2 changes: 1 addition & 1 deletion ca/django_ca/management/commands/init_ca.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from django.utils.translation import gettext_lazy as _

from django_ca import ca_settings, constants
from django_ca.backends import KeyBackend, key_backends
from django_ca.key_backends import KeyBackend, key_backends
from django_ca.management.actions import ExpiresAction, IntegerRangeAction, NameAction
from django_ca.management.base import BaseSignCommand
from django_ca.management.mixins import CertificateAuthorityDetailMixin, StorePrivateKeyMixin
Expand Down
2 changes: 1 addition & 1 deletion ca/django_ca/management/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
from django.core.management.base import BaseCommand, CommandError, CommandParser

from django_ca import ca_settings
from django_ca.backends import key_backends
from django_ca.extensions import extension_as_text, get_extension_name
from django_ca.key_backends import key_backends
from django_ca.management import actions
from django_ca.management.actions import IntegerRangeAction, KeyBackendAction
from django_ca.models import CertificateAuthority, X509CertMixin
Expand Down
7 changes: 4 additions & 3 deletions ca/django_ca/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
from django.urls import reverse

from django_ca import ca_settings, constants
from django_ca.backends.base import KeyBackend
from django_ca.extensions.utils import format_extensions, get_formatting_context
from django_ca.key_backends.base import KeyBackend
from django_ca.modelfields import LazyCertificateSigningRequest
from django_ca.openssh import SshHostCaExtension, SshUserCaExtension
from django_ca.profiles import Profile, profiles
Expand Down Expand Up @@ -270,8 +270,9 @@ def init( # noqa: PLR0912,PLR0913,PLR0915
----------
name : str
The name of the CA. This is a human-readable string and is used for administrative purposes only.
key_backend : :py:class:`~django_ca.backends.base.KeyBackend`
A subclass of :py:class:`~django_ca.backends.base.KeyBackend` to use for storing the private key.
key_backend : :py:class:`~django_ca.key_backends.base.KeyBackend`
A subclass of :py:class:`~django_ca.key_backends.base.KeyBackend` to use for storing the private
key.
key_backend_options : BaseModel
Parameters required for creating the private key using `key_backend`.
subject : :py:class:`cg:cryptography.x509.Name`
Expand Down
2 changes: 1 addition & 1 deletion ca/django_ca/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@

from django_ca import ca_settings, constants
from django_ca.acme.constants import BASE64_URL_ALPHABET, IdentifierType, Status
from django_ca.backends import KeyBackend, key_backends
from django_ca.constants import REVOCATION_REASONS, ReasonFlags
from django_ca.deprecation import not_valid_after, not_valid_before
from django_ca.extensions import get_extension_name
from django_ca.key_backends import KeyBackend, key_backends
from django_ca.managers import (
AcmeAccountManager,
AcmeAuthorizationManager,
Expand Down
2 changes: 1 addition & 1 deletion ca/django_ca/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def create_cert( # noqa: PLR0913
>>> from cryptography import x509
>>> from cryptography.x509.oid import NameOID
>>> from django_ca.backends.storages import UsePrivateKeyOptions
>>> from django_ca.key_backends.storages import UsePrivateKeyOptions
>>> subject = x509.Name([x509.NameAttribute(NameOID.COMMON_NAME, 'example.com')])
>>> key_backend_options = UsePrivateKeyOptions(password=None)
>>> profile = get_profile('webserver')
Expand Down
2 changes: 1 addition & 1 deletion ca/django_ca/tests/acme/views/test_revocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
from freezegun import freeze_time

from django_ca import ca_settings
from django_ca.backends.storages import UsePrivateKeyOptions
from django_ca.constants import ReasonFlags
from django_ca.key_backends.storages import UsePrivateKeyOptions
from django_ca.models import AcmeAccount, AcmeAuthorization, AcmeCertificate, AcmeOrder, Certificate
from django_ca.tests.acme.views.base import AcmeWithAccountViewTestCaseMixin
from django_ca.tests.base.constants import CERT_DATA, TIMESTAMPS
Expand Down
2 changes: 1 addition & 1 deletion ca/django_ca/tests/base/assertions.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@
import pytest

from django_ca import ca_settings
from django_ca.backends.storages import UsePrivateKeyOptions
from django_ca.deprecation import (
RemovedInDjangoCA200Warning,
crl_last_update,
crl_next_update,
revoked_certificate_revocation_date,
)
from django_ca.key_backends.storages import UsePrivateKeyOptions
from django_ca.models import Certificate, CertificateAuthority, X509CertMixin
from django_ca.signals import post_create_ca, post_issue_cert, pre_create_ca, pre_sign_cert
from django_ca.tests.base.mocks import mock_signal
Expand Down
2 changes: 1 addition & 1 deletion ca/django_ca/tests/commands/test_import_ca.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

from ca import settings
from django_ca import ca_settings
from django_ca.backends.storages import UsePrivateKeyOptions
from django_ca.key_backends.storages import UsePrivateKeyOptions
from django_ca.models import CertificateAuthority
from django_ca.tests.base.assertions import assert_command_error, assert_signature
from django_ca.tests.base.constants import CERT_DATA, TIMESTAMPS
Expand Down
2 changes: 1 addition & 1 deletion ca/django_ca/tests/commands/test_init_ca.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
from pytest_django.fixtures import SettingsWrapper

from django_ca import ca_settings
from django_ca.backends.storages import UsePrivateKeyOptions
from django_ca.constants import ExtendedKeyUsageOID
from django_ca.key_backends.storages import UsePrivateKeyOptions
from django_ca.models import Certificate, CertificateAuthority
from django_ca.signals import post_create_ca
from django_ca.tests.base.assertions import (
Expand Down
2 changes: 1 addition & 1 deletion ca/django_ca/tests/commands/test_regenerate_ocsp_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

from django.test import TestCase

from django_ca.backends.storages import UsePrivateKeyOptions
from django_ca.key_backends.storages import UsePrivateKeyOptions
from django_ca.models import Certificate, CertificateAuthority
from django_ca.tests.base.assertions import assert_command_error
from django_ca.tests.base.constants import CERT_DATA
Expand Down
6 changes: 3 additions & 3 deletions ca/django_ca/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@

from ca import settings_utils # noqa: F401 # to get rid of pytest warnings
from django_ca import ca_settings
from django_ca.backends import key_backends
from django_ca.backends.storages import StoragesBackend
from django_ca.key_backends import key_backends
from django_ca.key_backends.storages import StoragesBackend
from django_ca.models import Certificate, CertificateAuthority
from django_ca.profiles import profiles
from django_ca.tests.base.conftest_helpers import (
Expand Down Expand Up @@ -144,7 +144,7 @@ def hostname(ca_name: str) -> Iterator[str]:

@pytest.fixture()
def key_backend(request: "SubRequest") -> Iterator[StoragesBackend]:
"""Return a :py:class:`~django_ca.backends.storages.StoragesBackend` suitable for creating a new CA."""
"""Return a :py:class:`~django_ca.key_backends.storages.StoragesBackend` for creating a new CA."""
request.getfixturevalue("tmpcadir")
yield key_backends[ca_settings.CA_DEFAULT_KEY_BACKEND] # type: ignore[misc]

Expand Down
4 changes: 2 additions & 2 deletions ca/django_ca/tests/key_backends/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

import pytest

from django_ca.backends import key_backends
from django_ca.backends.base import KeyBackends
from django_ca.key_backends import key_backends
from django_ca.key_backends.base import KeyBackends


@pytest.fixture()
Expand Down
6 changes: 3 additions & 3 deletions ca/django_ca/tests/key_backends/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from pytest_django.fixtures import SettingsWrapper

from django_ca import ca_settings
from django_ca.backends import KeyBackend, key_backends
from django_ca.key_backends import KeyBackend, key_backends
from django_ca.models import CertificateAuthority
from django_ca.tests.base.assertions import assert_improperly_configured
from django_ca.typehints import AllowedHashTypes, ArgumentGroup, ParsableKeyType
Expand Down Expand Up @@ -116,7 +116,7 @@ def test_key_backends_getitem_with_default() -> None:

def test_key_backends_getitem_caching() -> None:
"""Test that lookups are cached properly."""
patch_target = "django_ca.backends.key_backends._get_key_backend"
patch_target = "django_ca.key_backends.key_backends._get_key_backend"
value = "xxx"
with patch(patch_target, autospec=True, return_value=value) as load_mock:
assert key_backends[ca_settings.CA_DEFAULT_KEY_BACKEND] == value # type: ignore[comparison-overlap]
Expand All @@ -139,7 +139,7 @@ def test_key_backends_iter(settings: SettingsWrapper) -> None:

settings.CA_KEY_BACKENDS = {
ca_settings.CA_DEFAULT_KEY_BACKEND: {
"BACKEND": "django_ca.backends.storages.StoragesBackend",
"BACKEND": "django_ca.key_backends.storages.StoragesBackend",
"OPTIONS": {"storage_alias": "django-ca"},
},
"test": {
Expand Down
6 changes: 3 additions & 3 deletions ca/django_ca/tests/key_backends/test_storages.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
from pytest_django.fixtures import SettingsWrapper

from django_ca import ca_settings
from django_ca.backends import key_backends
from django_ca.backends.storages import StoragesBackend, UsePrivateKeyOptions
from django_ca.key_backends import key_backends
from django_ca.key_backends.storages import StoragesBackend, UsePrivateKeyOptions
from django_ca.models import CertificateAuthority


Expand All @@ -27,7 +27,7 @@ def test_invalid_storages_alias(settings: SettingsWrapper) -> None:
"""Test configuring an invalid storage alias."""
settings.CA_KEY_BACKENDS = {
ca_settings.CA_DEFAULT_KEY_BACKEND: {
"BACKEND": "django_ca.backends.storages.StoragesBackend",
"BACKEND": "django_ca.key_backends.storages.StoragesBackend",
"OPTIONS": {"storage_alias": "invalid"},
},
}
Expand Down
6 changes: 3 additions & 3 deletions ca/django_ca/tests/test_management_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
import pytest
from pytest_django.fixtures import SettingsWrapper

from django_ca.backends import key_backends
from django_ca.constants import ReasonFlags
from django_ca.key_backends import key_backends
from django_ca.management import actions
from django_ca.models import Certificate, CertificateAuthority
from django_ca.tests.base.constants import CERT_DATA
Expand All @@ -51,11 +51,11 @@ def key_backend_parser(settings: SettingsWrapper) -> Iterator[argparse.ArgumentP
}
settings.CA_KEY_BACKENDS = {
"default": {
"BACKEND": "django_ca.backends.storages.StoragesBackend",
"BACKEND": "django_ca.key_backends.storages.StoragesBackend",
"OPTIONS": {"storage_alias": "django-ca"},
},
"other": {
"BACKEND": "django_ca.backends.storages.StoragesBackend",
"BACKEND": "django_ca.key_backends.storages.StoragesBackend",
"OPTIONS": {"storage_alias": "other-storage"},
},
}
Expand Down
2 changes: 1 addition & 1 deletion ca/django_ca/tests/test_managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
from pytest_django.fixtures import SettingsWrapper

from django_ca import ca_settings
from django_ca.backends.storages import CreatePrivateKeyOptions, StoragesBackend, UsePrivateKeyOptions
from django_ca.constants import ExtendedKeyUsageOID
from django_ca.key_backends.storages import CreatePrivateKeyOptions, StoragesBackend, UsePrivateKeyOptions
from django_ca.models import Certificate, CertificateAuthority
from django_ca.profiles import profiles
from django_ca.querysets import CertificateAuthorityQuerySet, CertificateQuerySet
Expand Down
2 changes: 1 addition & 1 deletion ca/django_ca/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@
from freezegun import freeze_time

from django_ca import ca_settings
from django_ca.backends.storages import UsePrivateKeyOptions
from django_ca.constants import ReasonFlags
from django_ca.deprecation import not_valid_after, not_valid_before
from django_ca.key_backends.storages import UsePrivateKeyOptions
from django_ca.modelfields import LazyCertificate, LazyCertificateSigningRequest
from django_ca.models import (
AcmeAccount,
Expand Down
2 changes: 1 addition & 1 deletion ca/django_ca/tests/test_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
import pytest

from django_ca import ca_settings
from django_ca.backends.storages import UsePrivateKeyOptions
from django_ca.constants import EXTENSION_DEFAULT_CRITICAL, EXTENSION_KEYS
from django_ca.deprecation import RemovedInDjangoCA128Warning
from django_ca.key_backends.storages import UsePrivateKeyOptions
from django_ca.models import Certificate, CertificateAuthority
from django_ca.profiles import Profile, get_profile, profile, profiles
from django_ca.signals import pre_sign_cert
Expand Down
2 changes: 1 addition & 1 deletion ca/django_ca/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
from freezegun import freeze_time

from django_ca import ca_settings, tasks
from django_ca.backends.storages import UsePrivateKeyOptions
from django_ca.key_backends.storages import UsePrivateKeyOptions
from django_ca.models import (
AcmeAccount,
AcmeAuthorization,
Expand Down
4 changes: 2 additions & 2 deletions ca/django_ca/tests/test_verification.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@

from freezegun import freeze_time

from django_ca.backends import key_backends
from django_ca.backends.storages import CreatePrivateKeyOptions
from django_ca.key_backends import key_backends
from django_ca.key_backends.storages import CreatePrivateKeyOptions
from django_ca.models import CertificateAuthority, X509CertMixin
from django_ca.tests.base.constants import CERT_DATA, TIMESTAMPS
from django_ca.tests.base.mixins import TestCaseMixin
Expand Down
Loading

0 comments on commit de55d20

Please sign in to comment.