Skip to content

Commit

Permalink
fix OpenAPI schema generation in other environments
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiasertl committed Jul 30, 2023
1 parent ad0e2cc commit e401f0b
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 7 deletions.
1 change: 1 addition & 0 deletions ca/ca/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
# 'django.contrib.admindocs',
"django_object_actions",
"django_ca",
"ninja",
)

TEMPLATES = [
Expand Down
6 changes: 3 additions & 3 deletions ca/django_ca/api/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
from django_ca.models import Certificate, CertificateAuthority
from django_ca.profiles import profiles
from django_ca.querysets import CertificateAuthorityQuerySet, CertificateQuerySet
from django_ca.typehints import ExtensionDict

api = NinjaAPI(title="django-ca API", version=__version__, urls_namespace="django_ca:api")

Expand Down Expand Up @@ -94,14 +93,15 @@ def sign_certificate(request: WSGIRequest, serial: str, data: SignCertificateSch
profile = profiles[data.profile]
subject = x509.Name.from_rfc4514_string(data.subject)
algorithm = expires = None
extensions: List[x509.Extension[x509.ExtensionType]] = []

if data.algorithm is not None:
algorithm = constants.HASH_ALGORITHM_TYPES[data.algorithm]()
if data.expires is not None:
expires = data.expires
if data.extensions is not None:
extensions: List[x509.Extension[x509.ExtensionType]] = []
for key, extension_data in data.extensions.items():
extensions.append(parse_extension(key, extension_data.dict()))
extensions.append(parse_extension(key, extension_data.dict())) # type: ignore[arg-type]

cert = Certificate.objects.create_cert(
ca,
Expand Down
2 changes: 2 additions & 0 deletions ca/django_ca/api/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@


class SubjectAlternativeNameSchema(Schema):
"""Schema for a Subject Alternative Name extension."""

critical: bool = constants.EXTENSION_DEFAULT_CRITICAL[ExtensionOID.SUBJECT_ALTERNATIVE_NAME]
value: List[str]

Expand Down
1 change: 0 additions & 1 deletion ca/django_ca/tests/api/test_sign_cert.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ def test_sign_certificate_with_extensions(self) -> None:

# Test extensions
extensions = cert.x509_extensions
print(extensions[ExtensionOID.SUBJECT_ALTERNATIVE_NAME])
self.assertEqual(
extensions[ExtensionOID.SUBJECT_ALTERNATIVE_NAME],
self.subject_alternative_name(
Expand Down
4 changes: 2 additions & 2 deletions ca/django_ca/tests/base/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,9 @@ def uri(url: str) -> x509.UniformResourceIdentifier: # just a shortcut
return x509.UniformResourceIdentifier(url)


def ip(
def ip( # pylint: disable=invalid-name # just a shortcut
name: Union[ipaddress.IPv4Address, ipaddress.IPv6Address, ipaddress.IPv4Network, ipaddress.IPv6Network]
) -> x509.IPAddress: # just a shortcut
) -> x509.IPAddress:
"""Shortcut to get a :py:class:`cg:cryptography.x509.IPAddress`."""
return x509.IPAddress(name)

Expand Down
2 changes: 1 addition & 1 deletion docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ source/_files/docker-compose.yml:
cp ../docker-compose.yml source/_files/

source/_files/openapi.json:
python ../ca/manage.py export_openapi_schema --api django_ca.api.endpoints.api > source/_files/openapi.json
DJANGO_SETTINGS_MODULE=ca.test_settings python ../ca/manage.py export_openapi_schema --api django_ca.api.endpoints.api > source/_files/openapi.json

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ module = [
# https://github.com/docker/docker-py/issues/2796
"docker",
"enchant.tokenize",
"httpcore",
# psycopg and psycopg_c are not installed in isolated mypy envs (tox, ...)
"psycopg",
"psycopg_c",
Expand Down

0 comments on commit e401f0b

Please sign in to comment.