From f6fd2626180c476958dd10bd736ad4bf61189888 Mon Sep 17 00:00:00 2001 From: Curtis Castrapel Date: Wed, 11 Apr 2018 15:56:00 -0700 Subject: [PATCH] DNS Providers list returned --- lemur/certificates/models.py | 2 +- lemur/defaults/schemas.py | 2 ++ lemur/defaults/views.py | 8 +++++-- lemur/dns_providers/models.py | 22 +++++++++---------- lemur/dns_providers/schemas.py | 20 +++++++++++++++++ lemur/dns_providers/service.py | 8 ++++++- .../certificates/certificate/options.tpl.html | 20 ++++++++++------- .../app/angular/certificates/services.js | 1 + .../destinations/destination/destination.js | 2 +- .../angular/pending_certificates/services.js | 1 + 10 files changed, 61 insertions(+), 25 deletions(-) create mode 100644 lemur/dns_providers/schemas.py diff --git a/lemur/certificates/models.py b/lemur/certificates/models.py index d8354d94..63d2ea7c 100644 --- a/lemur/certificates/models.py +++ b/lemur/certificates/models.py @@ -102,7 +102,7 @@ class Certificate(db.Model): serial = Column(String(128)) cn = Column(String(128)) deleted = Column(Boolean, index=True) - dns_provider = Column(Integer(), nullable=True) + dns_provider_id = Column(Integer(), nullable=True) not_before = Column(ArrowType) not_after = Column(ArrowType) diff --git a/lemur/defaults/schemas.py b/lemur/defaults/schemas.py index c03d6d85..58ba31af 100644 --- a/lemur/defaults/schemas.py +++ b/lemur/defaults/schemas.py @@ -8,6 +8,7 @@ from marshmallow import fields from lemur.common.schema import LemurOutputSchema from lemur.authorities.schemas import AuthorityNestedOutputSchema +from lemur.dns_providers.schemas import DnsProvidersNestedOutputSchema class DefaultOutputSchema(LemurOutputSchema): @@ -18,6 +19,7 @@ class DefaultOutputSchema(LemurOutputSchema): organization = fields.String() organizational_unit = fields.String() issuer_plugin = fields.String() + dns_providers = fields.List(fields.Nested(DnsProvidersNestedOutputSchema)) default_output_schema = DefaultOutputSchema() diff --git a/lemur/defaults/views.py b/lemur/defaults/views.py index db849011..7ba38fa0 100644 --- a/lemur/defaults/views.py +++ b/lemur/defaults/views.py @@ -9,6 +9,7 @@ from flask_restful import Api from lemur.common.schema import validate_schema from lemur.authorities.service import get_by_name from lemur.auth.service import AuthenticatedResource +from lemur.dns_providers.service import get_all_dns_providers from lemur.defaults.schemas import default_output_schema @@ -50,7 +51,8 @@ class LemurDefaults(AuthenticatedResource): "state": "CA", "location": "Los Gatos", "organization": "Netflix", - "organizationalUnit": "Operations" + "organizationalUnit": "Operations", + "dnsProviders": [{"name": "test", ...}, {...}], } :reqheader Authorization: OAuth token to authenticate @@ -59,6 +61,7 @@ class LemurDefaults(AuthenticatedResource): """ default_authority = get_by_name(current_app.config.get('LEMUR_DEFAULT_AUTHORITY')) + dns_providers = get_all_dns_providers() return dict( country=current_app.config.get('LEMUR_DEFAULT_COUNTRY'), @@ -67,7 +70,8 @@ class LemurDefaults(AuthenticatedResource): organization=current_app.config.get('LEMUR_DEFAULT_ORGANIZATION'), organizational_unit=current_app.config.get('LEMUR_DEFAULT_ORGANIZATIONAL_UNIT'), issuer_plugin=current_app.config.get('LEMUR_DEFAULT_ISSUER_PLUGIN'), - authority=default_authority + authority=default_authority, + dns_providers=dns_providers, ) diff --git a/lemur/dns_providers/models.py b/lemur/dns_providers/models.py index 809c5247..f43aac0b 100644 --- a/lemur/dns_providers/models.py +++ b/lemur/dns_providers/models.py @@ -6,15 +6,13 @@ from lemur.database import db class DnsProviders(db.Model): - db.Table('dns_providers', - Column('id', Integer(), nullable=False), - Column('name', String(length=256), nullable=True), - Column('description', String(length=1024), nullable=True), - Column('provider_type', String(length=256), nullable=True), - Column('credentials', String(length=256), nullable=True), - Column('api_endpoint', String(length=256), nullable=True), - Column('date_created', ArrowType(), server_default=text('now()'), nullable=False), - Column('status', String(length=128), nullable=True), - Column('options', JSON), - PrimaryKeyConstraint('id'), - UniqueConstraint('name')) \ No newline at end of file + __tablename__ = 'dns_providers' + id = Column(Integer(), primary_key=True) + name = Column(String(length=256), unique=True, nullable=True) + description = Column(String(length=1024), nullable=True) + provider_type = Column(String(length=256), nullable=True) + credentials = Column(String(length=256), nullable=True) + api_endpoint = Column(String(length=256), nullable=True) + date_created = Column(ArrowType(), server_default=text('now()'), nullable=False) + status = Column(String(length=128), nullable=True) + options = Column(JSON) diff --git a/lemur/dns_providers/schemas.py b/lemur/dns_providers/schemas.py new file mode 100644 index 00000000..bae9570c --- /dev/null +++ b/lemur/dns_providers/schemas.py @@ -0,0 +1,20 @@ +from lemur.common.fields import ArrowDateTime +from lemur.common.schema import LemurOutputSchema + +from marshmallow import fields + + +class DnsProvidersNestedOutputSchema(LemurOutputSchema): + __envelope__ = False + id = fields.Integer() + name = fields.String() + description = fields.String() + provider_type = fields.String() + credentials = fields.String() + api_endpoint = fields.String() + date_created = ArrowDateTime() + status = fields.String() + options = fields.String() + + +default_output_schema = DnsProvidersNestedOutputSchema() diff --git a/lemur/dns_providers/service.py b/lemur/dns_providers/service.py index 0ed27315..fa752d09 100644 --- a/lemur/dns_providers/service.py +++ b/lemur/dns_providers/service.py @@ -7,4 +7,10 @@ def get_all_dns_providers(status="active"): :return: """ - return DnsProviders.query.all(status=status) + all_dns_providers = DnsProviders.query.all() + dns_provider_result = [] + for provider in all_dns_providers: + print(provider) + if provider.status == status: + dns_provider_result.append(provider.__dict__) + return dns_provider_result diff --git a/lemur/static/app/angular/certificates/certificate/options.tpl.html b/lemur/static/app/angular/certificates/certificate/options.tpl.html index 6f955ce2..6fa84984 100644 --- a/lemur/static/app/angular/certificates/certificate/options.tpl.html +++ b/lemur/static/app/angular/certificates/certificate/options.tpl.html @@ -231,14 +231,18 @@ - +
+ +
+ +
+ +
+
+ +
diff --git a/lemur/static/app/angular/certificates/services.js b/lemur/static/app/angular/certificates/services.js index 22c8d80b..e3bd5c64 100644 --- a/lemur/static/app/angular/certificates/services.js +++ b/lemur/static/app/angular/certificates/services.js @@ -243,6 +243,7 @@ angular.module('lemur') certificate.authority = defaults.authority; } } + certificate.dns_providers = defaults.dnsProviders; }); }; diff --git a/lemur/static/app/angular/destinations/destination/destination.js b/lemur/static/app/angular/destinations/destination/destination.js index f5210074..21f624c8 100644 --- a/lemur/static/app/angular/destinations/destination/destination.js +++ b/lemur/static/app/angular/destinations/destination/destination.js @@ -47,8 +47,8 @@ angular.module('lemur') PluginService.getByType('destination').then(function (plugins) { $scope.plugins = plugins; - _.each($scope.plugins, function (plugin) { + _.each($scope.plugins, function (plugin) { if (plugin.slug === $scope.destination.plugin.slug) { plugin.pluginOptions = $scope.destination.plugin.pluginOptions; $scope.destination.plugin = plugin; diff --git a/lemur/static/app/angular/pending_certificates/services.js b/lemur/static/app/angular/pending_certificates/services.js index 32b335ac..95637641 100644 --- a/lemur/static/app/angular/pending_certificates/services.js +++ b/lemur/static/app/angular/pending_certificates/services.js @@ -230,6 +230,7 @@ angular.module('lemur') certificate.authority = defaults.authority; } } + certificate.dns_providers = defaults.dnsProviders; }); };