From 23198585867395900a0d1264ee582aabaf5d1a1f Mon Sep 17 00:00:00 2001 From: Marti Raudsepp Date: Tue, 18 Jun 2019 09:43:00 +0300 Subject: [PATCH] Expose new certificate field hasPrivateKey We can also now disable the 'private key' tab when cert doesn't have a private key. --- lemur/certificates/models.py | 10 +++++++++- lemur/certificates/schemas.py | 1 + .../static/app/angular/certificates/view/view.tpl.html | 4 ++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lemur/certificates/models.py b/lemur/certificates/models.py index 978acd7a..0a76cd6b 100644 --- a/lemur/certificates/models.py +++ b/lemur/certificates/models.py @@ -137,7 +137,7 @@ class Certificate(db.Model): not_before = Column(ArrowType) not_after = Column(ArrowType) - not_after_ix = Index('ix_certificates_not_after', not_after.desc()) + not_after_ix = Index("ix_certificates_not_after", not_after.desc()) date_created = Column(ArrowType, PassiveDefault(func.now()), nullable=False) @@ -337,6 +337,14 @@ class Certificate(db.Model): def revoked(cls): return case([(cls.status == "revoked", True)], else_=False) + @hybrid_property + def has_private_key(self): + return self.private_key is not None + + @has_private_key.expression + def has_private_key(cls): + return case([(cls.private_key.is_(None), True)], else_=False) + @hybrid_property def in_rotation_window(self): """ diff --git a/lemur/certificates/schemas.py b/lemur/certificates/schemas.py index bf950e70..7f3c2ac0 100644 --- a/lemur/certificates/schemas.py +++ b/lemur/certificates/schemas.py @@ -247,6 +247,7 @@ class CertificateOutputSchema(LemurOutputSchema): # Note aliasing is the first step in deprecating these fields. notify = fields.Boolean() active = fields.Boolean(attribute="notify") + has_private_key = fields.Boolean() cn = fields.String() common_name = fields.String(attribute="cn") diff --git a/lemur/static/app/angular/certificates/view/view.tpl.html b/lemur/static/app/angular/certificates/view/view.tpl.html index fbed4ca5..9d5c7772 100644 --- a/lemur/static/app/angular/certificates/view/view.tpl.html +++ b/lemur/static/app/angular/certificates/view/view.tpl.html @@ -203,10 +203,10 @@
{{ certificate.body }}
- + Private Key - +
{{ certificate.privateKey }}