Black lint all the things
This commit is contained in:
@ -13,7 +13,7 @@ from lemur.plugins.base import plugins
|
||||
|
||||
|
||||
class Destination(db.Model):
|
||||
__tablename__ = 'destinations'
|
||||
__tablename__ = "destinations"
|
||||
id = Column(Integer, primary_key=True)
|
||||
label = Column(String(32))
|
||||
options = Column(JSONType)
|
||||
|
@ -30,7 +30,7 @@ class DestinationOutputSchema(LemurOutputSchema):
|
||||
@post_dump
|
||||
def fill_object(self, data):
|
||||
if data:
|
||||
data['plugin']['pluginOptions'] = data['options']
|
||||
data["plugin"]["pluginOptions"] = data["options"]
|
||||
return data
|
||||
|
||||
|
||||
|
@ -26,10 +26,12 @@ def create(label, plugin_name, options, description=None):
|
||||
"""
|
||||
# remove any sub-plugin objects before try to save the json options
|
||||
for option in options:
|
||||
if 'plugin' in option['type']:
|
||||
del option['value']['plugin_object']
|
||||
if "plugin" in option["type"]:
|
||||
del option["value"]["plugin_object"]
|
||||
|
||||
destination = Destination(label=label, options=options, plugin_name=plugin_name, description=description)
|
||||
destination = Destination(
|
||||
label=label, options=options, plugin_name=plugin_name, description=description
|
||||
)
|
||||
current_app.logger.info("Destination: %s created", label)
|
||||
|
||||
# add the destination as source, to avoid new destinations that are not in source, as long as an AWS destination
|
||||
@ -85,7 +87,7 @@ def get_by_label(label):
|
||||
:param label:
|
||||
:return:
|
||||
"""
|
||||
return database.get(Destination, label, field='label')
|
||||
return database.get(Destination, label, field="label")
|
||||
|
||||
|
||||
def get_all():
|
||||
@ -99,17 +101,19 @@ def get_all():
|
||||
|
||||
|
||||
def render(args):
|
||||
filt = args.pop('filter')
|
||||
certificate_id = args.pop('certificate_id', None)
|
||||
filt = args.pop("filter")
|
||||
certificate_id = args.pop("certificate_id", None)
|
||||
|
||||
if certificate_id:
|
||||
query = database.session_query(Destination).join(Certificate, Destination.certificate)
|
||||
query = database.session_query(Destination).join(
|
||||
Certificate, Destination.certificate
|
||||
)
|
||||
query = query.filter(Certificate.id == certificate_id)
|
||||
else:
|
||||
query = database.session_query(Destination)
|
||||
|
||||
if filt:
|
||||
terms = filt.split(';')
|
||||
terms = filt.split(";")
|
||||
query = database.filter(query, Destination, terms)
|
||||
|
||||
return database.sort_and_page(query, Destination, args)
|
||||
@ -122,9 +126,15 @@ def stats(**kwargs):
|
||||
:param kwargs:
|
||||
:return:
|
||||
"""
|
||||
items = database.db.session.query(Destination.label, func.count(certificate_destination_associations.c.certificate_id))\
|
||||
.join(certificate_destination_associations)\
|
||||
.group_by(Destination.label).all()
|
||||
items = (
|
||||
database.db.session.query(
|
||||
Destination.label,
|
||||
func.count(certificate_destination_associations.c.certificate_id),
|
||||
)
|
||||
.join(certificate_destination_associations)
|
||||
.group_by(Destination.label)
|
||||
.all()
|
||||
)
|
||||
|
||||
keys = []
|
||||
values = []
|
||||
@ -132,4 +142,4 @@ def stats(**kwargs):
|
||||
keys.append(key)
|
||||
values.append(count)
|
||||
|
||||
return {'labels': keys, 'values': values}
|
||||
return {"labels": keys, "values": values}
|
||||
|
@ -15,15 +15,20 @@ from lemur.auth.permissions import admin_permission
|
||||
from lemur.common.utils import paginated_parser
|
||||
|
||||
from lemur.common.schema import validate_schema
|
||||
from lemur.destinations.schemas import destinations_output_schema, destination_input_schema, destination_output_schema
|
||||
from lemur.destinations.schemas import (
|
||||
destinations_output_schema,
|
||||
destination_input_schema,
|
||||
destination_output_schema,
|
||||
)
|
||||
|
||||
|
||||
mod = Blueprint('destinations', __name__)
|
||||
mod = Blueprint("destinations", __name__)
|
||||
api = Api(mod)
|
||||
|
||||
|
||||
class DestinationsList(AuthenticatedResource):
|
||||
""" Defines the 'destinations' endpoint """
|
||||
|
||||
def __init__(self):
|
||||
self.reqparse = reqparse.RequestParser()
|
||||
super(DestinationsList, self).__init__()
|
||||
@ -176,7 +181,12 @@ class DestinationsList(AuthenticatedResource):
|
||||
:reqheader Authorization: OAuth token to authenticate
|
||||
:statuscode 200: no error
|
||||
"""
|
||||
return service.create(data['label'], data['plugin']['slug'], data['plugin']['plugin_options'], data['description'])
|
||||
return service.create(
|
||||
data["label"],
|
||||
data["plugin"]["slug"],
|
||||
data["plugin"]["plugin_options"],
|
||||
data["description"],
|
||||
)
|
||||
|
||||
|
||||
class Destinations(AuthenticatedResource):
|
||||
@ -325,16 +335,22 @@ class Destinations(AuthenticatedResource):
|
||||
:reqheader Authorization: OAuth token to authenticate
|
||||
:statuscode 200: no error
|
||||
"""
|
||||
return service.update(destination_id, data['label'], data['plugin']['plugin_options'], data['description'])
|
||||
return service.update(
|
||||
destination_id,
|
||||
data["label"],
|
||||
data["plugin"]["plugin_options"],
|
||||
data["description"],
|
||||
)
|
||||
|
||||
@admin_permission.require(http_exception=403)
|
||||
def delete(self, destination_id):
|
||||
service.delete(destination_id)
|
||||
return {'result': True}
|
||||
return {"result": True}
|
||||
|
||||
|
||||
class CertificateDestinations(AuthenticatedResource):
|
||||
""" Defines the 'certificate/<int:certificate_id/destinations'' endpoint """
|
||||
|
||||
def __init__(self):
|
||||
super(CertificateDestinations, self).__init__()
|
||||
|
||||
@ -401,25 +417,31 @@ class CertificateDestinations(AuthenticatedResource):
|
||||
"""
|
||||
parser = paginated_parser.copy()
|
||||
args = parser.parse_args()
|
||||
args['certificate_id'] = certificate_id
|
||||
args["certificate_id"] = certificate_id
|
||||
return service.render(args)
|
||||
|
||||
|
||||
class DestinationsStats(AuthenticatedResource):
|
||||
""" Defines the 'certificates' stats endpoint """
|
||||
|
||||
def __init__(self):
|
||||
self.reqparse = reqparse.RequestParser()
|
||||
super(DestinationsStats, self).__init__()
|
||||
|
||||
def get(self):
|
||||
self.reqparse.add_argument('metric', type=str, location='args')
|
||||
self.reqparse.add_argument("metric", type=str, location="args")
|
||||
args = self.reqparse.parse_args()
|
||||
items = service.stats(**args)
|
||||
return dict(items=items, total=len(items))
|
||||
|
||||
|
||||
api.add_resource(DestinationsList, '/destinations', endpoint='destinations')
|
||||
api.add_resource(Destinations, '/destinations/<int:destination_id>', endpoint='destination')
|
||||
api.add_resource(CertificateDestinations, '/certificates/<int:certificate_id>/destinations',
|
||||
endpoint='certificateDestinations')
|
||||
api.add_resource(DestinationsStats, '/destinations/stats', endpoint='destinationStats')
|
||||
api.add_resource(DestinationsList, "/destinations", endpoint="destinations")
|
||||
api.add_resource(
|
||||
Destinations, "/destinations/<int:destination_id>", endpoint="destination"
|
||||
)
|
||||
api.add_resource(
|
||||
CertificateDestinations,
|
||||
"/certificates/<int:certificate_id>/destinations",
|
||||
endpoint="certificateDestinations",
|
||||
)
|
||||
api.add_resource(DestinationsStats, "/destinations/stats", endpoint="destinationStats")
|
||||
|
Reference in New Issue
Block a user