crypto: add filter for key-pairs with private key
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
051c5672b9
commit
7a0ebbdc53
|
@ -1,4 +1,5 @@
|
||||||
"""Crypto API Views"""
|
"""Crypto API Views"""
|
||||||
|
import django_filters
|
||||||
from cryptography.hazmat.backends import default_backend
|
from cryptography.hazmat.backends import default_backend
|
||||||
from cryptography.hazmat.primitives.serialization import load_pem_private_key
|
from cryptography.hazmat.primitives.serialization import load_pem_private_key
|
||||||
from cryptography.x509 import load_pem_x509_certificate
|
from cryptography.x509 import load_pem_x509_certificate
|
||||||
|
@ -95,11 +96,29 @@ class CertificateGenerationSerializer(PassiveSerializer):
|
||||||
validity_days = IntegerField(initial=365)
|
validity_days = IntegerField(initial=365)
|
||||||
|
|
||||||
|
|
||||||
|
class CertificateKeyPairFilter(django_filters.FilterSet):
|
||||||
|
"""Filter for certificates"""
|
||||||
|
|
||||||
|
has_key = django_filters.BooleanFilter(
|
||||||
|
label="Only return certificate-key pairs with keys", method="filter_has_key"
|
||||||
|
)
|
||||||
|
|
||||||
|
# pylint: disable=unused-argument
|
||||||
|
def filter_has_key(self, queryset, name, value):
|
||||||
|
"""Only return certificate-key pairs with keys"""
|
||||||
|
return queryset.exclude(key_data__exact="")
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = CertificateKeyPair
|
||||||
|
fields = ["name"]
|
||||||
|
|
||||||
|
|
||||||
class CertificateKeyPairViewSet(ModelViewSet):
|
class CertificateKeyPairViewSet(ModelViewSet):
|
||||||
"""CertificateKeyPair Viewset"""
|
"""CertificateKeyPair Viewset"""
|
||||||
|
|
||||||
queryset = CertificateKeyPair.objects.all()
|
queryset = CertificateKeyPair.objects.all()
|
||||||
serializer_class = CertificateKeyPairSerializer
|
serializer_class = CertificateKeyPairSerializer
|
||||||
|
filterset_class = CertificateKeyPairFilter
|
||||||
|
|
||||||
@permission_required(None, ["authentik_crypto.add_certificatekeypair"])
|
@permission_required(None, ["authentik_crypto.add_certificatekeypair"])
|
||||||
@swagger_auto_schema(
|
@swagger_auto_schema(
|
||||||
|
|
80
swagger.yaml
80
swagger.yaml
|
@ -2290,6 +2290,16 @@ paths:
|
||||||
operationId: crypto_certificatekeypairs_list
|
operationId: crypto_certificatekeypairs_list
|
||||||
description: CertificateKeyPair Viewset
|
description: CertificateKeyPair Viewset
|
||||||
parameters:
|
parameters:
|
||||||
|
- name: name
|
||||||
|
in: query
|
||||||
|
description: ''
|
||||||
|
required: false
|
||||||
|
type: string
|
||||||
|
- name: has_key
|
||||||
|
in: query
|
||||||
|
description: ''
|
||||||
|
required: false
|
||||||
|
type: string
|
||||||
- name: ordering
|
- name: ordering
|
||||||
in: query
|
in: query
|
||||||
description: Which field to use when ordering the results.
|
description: Which field to use when ordering the results.
|
||||||
|
@ -16548,10 +16558,10 @@ definitions:
|
||||||
title: Expression
|
title: Expression
|
||||||
type: string
|
type: string
|
||||||
minLength: 1
|
minLength: 1
|
||||||
object_field:
|
object_type:
|
||||||
title: Object field
|
title: Object type
|
||||||
type: string
|
type: string
|
||||||
minLength: 1
|
readOnly: true
|
||||||
verbose_name:
|
verbose_name:
|
||||||
title: Verbose name
|
title: Verbose name
|
||||||
type: string
|
type: string
|
||||||
|
@ -16560,11 +16570,15 @@ definitions:
|
||||||
title: Verbose name plural
|
title: Verbose name plural
|
||||||
type: string
|
type: string
|
||||||
readOnly: true
|
readOnly: true
|
||||||
|
object_field:
|
||||||
|
title: Object field
|
||||||
|
type: string
|
||||||
|
minLength: 1
|
||||||
SAMLPropertyMapping:
|
SAMLPropertyMapping:
|
||||||
required:
|
required:
|
||||||
- name
|
- name
|
||||||
- saml_name
|
|
||||||
- expression
|
- expression
|
||||||
|
- saml_name
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
pk:
|
pk:
|
||||||
|
@ -16576,6 +16590,22 @@ definitions:
|
||||||
title: Name
|
title: Name
|
||||||
type: string
|
type: string
|
||||||
minLength: 1
|
minLength: 1
|
||||||
|
expression:
|
||||||
|
title: Expression
|
||||||
|
type: string
|
||||||
|
minLength: 1
|
||||||
|
object_type:
|
||||||
|
title: Object type
|
||||||
|
type: string
|
||||||
|
readOnly: true
|
||||||
|
verbose_name:
|
||||||
|
title: Verbose name
|
||||||
|
type: string
|
||||||
|
readOnly: true
|
||||||
|
verbose_name_plural:
|
||||||
|
title: Verbose name plural
|
||||||
|
type: string
|
||||||
|
readOnly: true
|
||||||
saml_name:
|
saml_name:
|
||||||
title: SAML Name
|
title: SAML Name
|
||||||
type: string
|
type: string
|
||||||
|
@ -16584,23 +16614,11 @@ definitions:
|
||||||
title: Friendly name
|
title: Friendly name
|
||||||
type: string
|
type: string
|
||||||
x-nullable: true
|
x-nullable: true
|
||||||
expression:
|
|
||||||
title: Expression
|
|
||||||
type: string
|
|
||||||
minLength: 1
|
|
||||||
verbose_name:
|
|
||||||
title: Verbose name
|
|
||||||
type: string
|
|
||||||
readOnly: true
|
|
||||||
verbose_name_plural:
|
|
||||||
title: Verbose name plural
|
|
||||||
type: string
|
|
||||||
readOnly: true
|
|
||||||
ScopeMapping:
|
ScopeMapping:
|
||||||
required:
|
required:
|
||||||
- name
|
- name
|
||||||
- scope_name
|
|
||||||
- expression
|
- expression
|
||||||
|
- scope_name
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
pk:
|
pk:
|
||||||
|
@ -16612,6 +16630,22 @@ definitions:
|
||||||
title: Name
|
title: Name
|
||||||
type: string
|
type: string
|
||||||
minLength: 1
|
minLength: 1
|
||||||
|
expression:
|
||||||
|
title: Expression
|
||||||
|
type: string
|
||||||
|
minLength: 1
|
||||||
|
object_type:
|
||||||
|
title: Object type
|
||||||
|
type: string
|
||||||
|
readOnly: true
|
||||||
|
verbose_name:
|
||||||
|
title: Verbose name
|
||||||
|
type: string
|
||||||
|
readOnly: true
|
||||||
|
verbose_name_plural:
|
||||||
|
title: Verbose name plural
|
||||||
|
type: string
|
||||||
|
readOnly: true
|
||||||
scope_name:
|
scope_name:
|
||||||
title: Scope name
|
title: Scope name
|
||||||
description: Scope used by the client
|
description: Scope used by the client
|
||||||
|
@ -16622,18 +16656,6 @@ definitions:
|
||||||
description: Description shown to the user when consenting. If left empty,
|
description: Description shown to the user when consenting. If left empty,
|
||||||
the user won't be informed.
|
the user won't be informed.
|
||||||
type: string
|
type: string
|
||||||
expression:
|
|
||||||
title: Expression
|
|
||||||
type: string
|
|
||||||
minLength: 1
|
|
||||||
verbose_name:
|
|
||||||
title: Verbose name
|
|
||||||
type: string
|
|
||||||
readOnly: true
|
|
||||||
verbose_name_plural:
|
|
||||||
title: Verbose name plural
|
|
||||||
type: string
|
|
||||||
readOnly: true
|
|
||||||
OAuth2ProviderSetupURLs:
|
OAuth2ProviderSetupURLs:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
|
|
Reference in New Issue