crypto: return private key's type (required for some oauth2 providers)
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
7c55616e29
commit
b19da6d774
|
@ -1,4 +1,6 @@
|
|||
"""Crypto API Views"""
|
||||
from typing import Optional
|
||||
|
||||
from cryptography.hazmat.backends import default_backend
|
||||
from cryptography.hazmat.primitives.serialization import load_pem_private_key
|
||||
from cryptography.x509 import load_pem_x509_certificate
|
||||
|
@ -31,6 +33,7 @@ class CertificateKeyPairSerializer(ModelSerializer):
|
|||
cert_expiry = DateTimeField(source="certificate.not_valid_after", read_only=True)
|
||||
cert_subject = SerializerMethodField()
|
||||
private_key_available = SerializerMethodField()
|
||||
private_key_type = SerializerMethodField()
|
||||
|
||||
certificate_download_url = SerializerMethodField()
|
||||
private_key_download_url = SerializerMethodField()
|
||||
|
@ -43,6 +46,13 @@ class CertificateKeyPairSerializer(ModelSerializer):
|
|||
"""Show if this keypair has a private key configured or not"""
|
||||
return instance.key_data != "" and instance.key_data is not None
|
||||
|
||||
def get_private_key_type(self, instance: CertificateKeyPair) -> Optional[str]:
|
||||
"""Get the private key's type, if set"""
|
||||
key = instance.private_key
|
||||
if key:
|
||||
return key.__class__.__name__.replace("_", "").lower().replace("privatekey", "")
|
||||
return None
|
||||
|
||||
def get_certificate_download_url(self, instance: CertificateKeyPair) -> str:
|
||||
"""Get URL to download certificate"""
|
||||
return (
|
||||
|
@ -98,6 +108,7 @@ class CertificateKeyPairSerializer(ModelSerializer):
|
|||
"cert_expiry",
|
||||
"cert_subject",
|
||||
"private_key_available",
|
||||
"private_key_type",
|
||||
"certificate_download_url",
|
||||
"private_key_download_url",
|
||||
"managed",
|
||||
|
|
|
@ -20221,6 +20221,10 @@ components:
|
|||
private_key_available:
|
||||
type: boolean
|
||||
readOnly: true
|
||||
private_key_type:
|
||||
type: string
|
||||
nullable: true
|
||||
readOnly: true
|
||||
certificate_download_url:
|
||||
type: string
|
||||
readOnly: true
|
||||
|
@ -20245,6 +20249,7 @@ components:
|
|||
- pk
|
||||
- private_key_available
|
||||
- private_key_download_url
|
||||
- private_key_type
|
||||
CertificateKeyPairRequest:
|
||||
type: object
|
||||
description: CertificateKeyPair Serializer
|
||||
|
|
|
@ -195,7 +195,7 @@ ${this.instance?.redirectUris}</textarea
|
|||
value=${ifDefined(key.pk)}
|
||||
?selected=${selected}
|
||||
>
|
||||
${key.name}
|
||||
${key.name} (${key.privateKeyType?.toUpperCase()})
|
||||
</option>`;
|
||||
});
|
||||
}),
|
||||
|
|
Reference in a new issue