From 02d711282de1848025a5228f173699fbbf1c51a3 Mon Sep 17 00:00:00 2001 From: sayali Date: Mon, 14 Sep 2020 18:12:33 -0700 Subject: [PATCH 1/4] New column key_type commenting conflicting property for now --- lemur/certificates/models.py | 3 +++ lemur/migrations/versions/434c29e40511_.py | 26 ++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 lemur/migrations/versions/434c29e40511_.py diff --git a/lemur/certificates/models.py b/lemur/certificates/models.py index 675cecb4..af70c1e8 100644 --- a/lemur/certificates/models.py +++ b/lemur/certificates/models.py @@ -154,6 +154,7 @@ class Certificate(db.Model): Integer, ForeignKey("authorities.id", ondelete="CASCADE") ) rotation_policy_id = Column(Integer, ForeignKey("rotation_policies.id")) + key_type = Column(String(128)) notifications = relationship( "Notification", @@ -297,6 +298,7 @@ class Certificate(db.Model): def distinguished_name(self): return self.parsed_cert.subject.rfc4514_string() + """ @property def key_type(self): if isinstance(self.parsed_cert.public_key(), rsa.RSAPublicKey): @@ -305,6 +307,7 @@ class Certificate(db.Model): ) elif isinstance(self.parsed_cert.public_key(), ec.EllipticCurvePublicKey): return get_key_type_from_ec_curve(self.parsed_cert.public_key().curve.name) + """ @property def validity_remaining(self): diff --git a/lemur/migrations/versions/434c29e40511_.py b/lemur/migrations/versions/434c29e40511_.py new file mode 100644 index 00000000..677be1d9 --- /dev/null +++ b/lemur/migrations/versions/434c29e40511_.py @@ -0,0 +1,26 @@ +"""empty message + +Revision ID: 434c29e40511 +Revises: 8323a5ea723a +Create Date: 2020-09-11 17:24:51.344585 + +""" + +# revision identifiers, used by Alembic. +revision = '434c29e40511' +down_revision = '8323a5ea723a' + +from alembic import op +import sqlalchemy as sa + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('certificates', sa.Column('key_type', sa.String(length=128), nullable=True)) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column('certificates', 'key_type') + # ### end Alembic commands ### From 676562ffdea03035a4c35d1af41a01746f2f304c Mon Sep 17 00:00:00 2001 From: sayali Date: Mon, 14 Sep 2020 18:13:35 -0700 Subject: [PATCH 2/4] Match column type to db schema No functional change --- lemur/dns_providers/models.py | 2 +- lemur/migrations/env.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lemur/dns_providers/models.py b/lemur/dns_providers/models.py index eb8cdff9..0e301e7b 100644 --- a/lemur/dns_providers/models.py +++ b/lemur/dns_providers/models.py @@ -12,7 +12,7 @@ class DnsProvider(db.Model): __tablename__ = "dns_providers" id = Column(Integer(), primary_key=True) name = Column(String(length=256), unique=True, nullable=True) - description = Column(Text(), nullable=True) + description = Column(String(length=1024), nullable=True) provider_type = Column(String(length=256), nullable=True) credentials = Column(Vault, nullable=True) api_endpoint = Column(String(length=256), nullable=True) diff --git a/lemur/migrations/env.py b/lemur/migrations/env.py index 008a9952..3acefc3a 100644 --- a/lemur/migrations/env.py +++ b/lemur/migrations/env.py @@ -67,7 +67,8 @@ def run_migrations_online(): context.configure( connection=connection, target_metadata=target_metadata, - **current_app.extensions["migrate"].configure_args + **current_app.extensions["migrate"].configure_args, + compare_type=True ) try: From 5ae65c2c4dc4c8c609ede2725a35f59d1c24a555 Mon Sep 17 00:00:00 2001 From: sayali Date: Tue, 15 Sep 2020 14:55:04 -0700 Subject: [PATCH 3/4] Remove unused import --- lemur/certificates/models.py | 2 -- lemur/dns_providers/models.py | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/lemur/certificates/models.py b/lemur/certificates/models.py index af70c1e8..eb49fbd5 100644 --- a/lemur/certificates/models.py +++ b/lemur/certificates/models.py @@ -9,10 +9,8 @@ from datetime import timedelta import arrow from cryptography import x509 -from cryptography.hazmat.primitives.asymmetric import rsa, ec from flask import current_app from idna.core import InvalidCodepoint -from lemur.common.utils import get_key_type_from_ec_curve from sqlalchemy import ( event, Integer, diff --git a/lemur/dns_providers/models.py b/lemur/dns_providers/models.py index 0e301e7b..7ad51308 100644 --- a/lemur/dns_providers/models.py +++ b/lemur/dns_providers/models.py @@ -1,4 +1,4 @@ -from sqlalchemy import Column, Integer, String, text, Text +from sqlalchemy import Column, Integer, String, text from sqlalchemy.dialects.postgresql import JSON from sqlalchemy.orm import relationship from sqlalchemy_utils import ArrowType From 51549ae79597db068340d77be3eaf2d7b3bd8e51 Mon Sep 17 00:00:00 2001 From: sayali Date: Tue, 15 Sep 2020 17:37:58 -0700 Subject: [PATCH 4/4] Adding comment for the property to be removed --- lemur/certificates/models.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lemur/certificates/models.py b/lemur/certificates/models.py index eb49fbd5..f71d2199 100644 --- a/lemur/certificates/models.py +++ b/lemur/certificates/models.py @@ -297,6 +297,7 @@ class Certificate(db.Model): return self.parsed_cert.subject.rfc4514_string() """ + # Commenting this property as key_type is now added as a column. This code can be removed in future. @property def key_type(self): if isinstance(self.parsed_cert.public_key(), rsa.RSAPublicKey):