From 5beb319b2785866d6b84a111d559e041891483d8 Mon Sep 17 00:00:00 2001 From: Curtis Castrapel Date: Tue, 10 Apr 2018 16:04:07 -0700 Subject: [PATCH] more stuff --- lemur/__init__.py | 2 + lemur/dns_providers/models.py | 20 ++++++ lemur/dns_providers/service.py | 10 +++ lemur/dns_providers/views.py | 72 +++++++++++++++++++ lemur/migrations/versions/3adfdd6598df_.py | 39 ++++++++++ lemur/migrations/versions/4e78b9e4e1dd_.py | 22 ++++++ lemur/models.py | 13 ---- .../certificates/certificate/options.tpl.html | 9 +++ 8 files changed, 174 insertions(+), 13 deletions(-) create mode 100644 lemur/dns_providers/models.py create mode 100644 lemur/dns_providers/service.py create mode 100644 lemur/dns_providers/views.py create mode 100644 lemur/migrations/versions/3adfdd6598df_.py create mode 100644 lemur/migrations/versions/4e78b9e4e1dd_.py diff --git a/lemur/__init__.py b/lemur/__init__.py index 6f29733c..402bde71 100644 --- a/lemur/__init__.py +++ b/lemur/__init__.py @@ -28,6 +28,7 @@ from lemur.endpoints.views import mod as endpoints_bp from lemur.logs.views import mod as logs_bp from lemur.api_keys.views import mod as api_key_bp from lemur.pending_certificates.views import mod as pending_certificates_bp +from lemur.dns_providers.views import mod as dns_providers_bp from lemur.__about__ import ( __author__, __copyright__, __email__, __license__, __summary__, __title__, @@ -56,6 +57,7 @@ LEMUR_BLUEPRINTS = ( logs_bp, api_key_bp, pending_certificates_bp, + dns_providers_bp, ) diff --git a/lemur/dns_providers/models.py b/lemur/dns_providers/models.py new file mode 100644 index 00000000..809c5247 --- /dev/null +++ b/lemur/dns_providers/models.py @@ -0,0 +1,20 @@ +from sqlalchemy import Column, Integer, PrimaryKeyConstraint, String, text, UniqueConstraint +from sqlalchemy.dialects.postgresql import JSON +from sqlalchemy_utils import ArrowType + +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 diff --git a/lemur/dns_providers/service.py b/lemur/dns_providers/service.py new file mode 100644 index 00000000..3a376040 --- /dev/null +++ b/lemur/dns_providers/service.py @@ -0,0 +1,10 @@ +from lemur.dns_providers.models import DnsProviders + + +def get_all_dns_providers(status="active"): + """ + Retrieves all certificates within Lemur. + + :return: + """ + return DnsProviders.query.all(status=status) \ No newline at end of file diff --git a/lemur/dns_providers/views.py b/lemur/dns_providers/views.py new file mode 100644 index 00000000..faa76aac --- /dev/null +++ b/lemur/dns_providers/views.py @@ -0,0 +1,72 @@ +""" +.. module: lemur.dns)providers.views + :platform: Unix + :copyright: (c) 2015 by Netflix Inc., see AUTHORS for more + :license: Apache, see LICENSE for more details. +.. moduleauthor:: Curtis Castrapel +""" +from flask import Blueprint +from flask_restful import reqparse, Api + + +from lemur.auth.service import AuthenticatedResource + +from lemur.dns_providers import service + +mod = Blueprint('dns_providers', __name__) +api = Api(mod) + + +class DnsProvidersList(AuthenticatedResource): + """ Defines the 'dns_providers' endpoint """ + def __init__(self): + self.reqparse = reqparse.RequestParser() + super(DnsProvidersList, self).__init__() + + def get(self): + """ + .. http:get:: /dns_providers + + The current list of DNS Providers + + **Example request**: + + .. sourcecode:: http + + GET /dns_providers HTTP/1.1 + Host: example.com + Accept: application/json, text/javascript + + **Example response**: + + .. sourcecode:: http + + HTTP/1.1 200 OK + Vary: Accept + Content-Type: text/javascript + + { + "items": [{ + "id": 1, + "name": "test", + "description": "test", + "provider_type": "dyn", + "status": "active", + }], + "total": 1 + } + + :query sortBy: field to sort on + :query sortDir: asc or desc + :query page: int. default is 1 + :query filter: key value pair format is k;v + :query count: count number. default is 10 + :reqheader Authorization: OAuth token to authenticate + :statuscode 200: no error + :statuscode 403: unauthenticated + + """ + return service.get_all_dns_providers() + + +api.add_resource(DnsProvidersList, '/dns_providers', endpoint='dns_providers') diff --git a/lemur/migrations/versions/3adfdd6598df_.py b/lemur/migrations/versions/3adfdd6598df_.py new file mode 100644 index 00000000..07918a0f --- /dev/null +++ b/lemur/migrations/versions/3adfdd6598df_.py @@ -0,0 +1,39 @@ +"""Create dns_providers table + +Revision ID: 3adfdd6598df +Revises: 556ceb3e3c3e +Create Date: 2018-04-10 13:25:47.007556 + +""" + +# revision identifiers, used by Alembic. +revision = '3adfdd6598df' +down_revision = '556ceb3e3c3e' + +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects.postgresql import JSON + +from sqlalchemy_utils import ArrowType + + +def upgrade(): + # create provider table + op.create_table( + 'dns_providers', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('name', sa.String(length=256), nullable=True), + sa.Column('description', sa.String(length=1024), nullable=True), + sa.Column('provider_type', sa.String(length=256), nullable=True), + sa.Column('credentials', sa.String(length=256), nullable=True), + sa.Column('api_endpoint', sa.String(length=256), nullable=True), + sa.Column('date_created', ArrowType(), server_default=sa.text('now()'), nullable=False), + sa.Column('status', sa.String(length=128), nullable=True), + sa.Column('options', JSON), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('name') + ) + + +def downgrade(): + op.drop_table('dns_providers') diff --git a/lemur/migrations/versions/4e78b9e4e1dd_.py b/lemur/migrations/versions/4e78b9e4e1dd_.py new file mode 100644 index 00000000..bde8c5d4 --- /dev/null +++ b/lemur/migrations/versions/4e78b9e4e1dd_.py @@ -0,0 +1,22 @@ +"""Add dns_provider id column to certificates table + +Revision ID: 4e78b9e4e1dd +Revises: 3adfdd6598df +Create Date: 2018-04-10 14:00:30.701669 + +""" + +# revision identifiers, used by Alembic. +revision = '4e78b9e4e1dd' +down_revision = '3adfdd6598df' + +from alembic import op +import sqlalchemy as sa + + +def upgrade(): + op.add_column('certificates', sa.Column('dns_provider_id', sa.Integer(), nullable=True)) + + +def downgrade(): + op.drop_column('certificates', 'dns_provider_id') diff --git a/lemur/models.py b/lemur/models.py index 3a9cf121..9f352bb9 100644 --- a/lemur/models.py +++ b/lemur/models.py @@ -132,16 +132,3 @@ pending_cert_role_associations = db.Table('pending_cert_role_associations', ) Index('pending_cert_role_associations_ix', pending_cert_role_associations.c.pending_cert_id, pending_cert_role_associations.c.role_id) - -dns_providers = 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')) diff --git a/lemur/static/app/angular/certificates/certificate/options.tpl.html b/lemur/static/app/angular/certificates/certificate/options.tpl.html index a52ee387..6f955ce2 100644 --- a/lemur/static/app/angular/certificates/certificate/options.tpl.html +++ b/lemur/static/app/angular/certificates/certificate/options.tpl.html @@ -231,6 +231,15 @@ + +