Skip to content

Commit

Permalink
Adding basic endpoint GUI.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevgliss committed Jun 6, 2016
1 parent 4af6489 commit 0278e65
Show file tree
Hide file tree
Showing 8 changed files with 213 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lemur/certificates/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from marshmallow.exceptions import ValidationError

from lemur.schemas import AssociatedAuthoritySchema, AssociatedDestinationSchema, AssociatedCertificateSchema, \
AssociatedNotificationSchema, PluginInputSchema, ExtensionSchema, AssociatedRoleSchema
AssociatedNotificationSchema, PluginInputSchema, ExtensionSchema, AssociatedRoleSchema, EndpointNestedOutputSchema

from lemur.authorities.schemas import AuthorityNestedOutputSchema
from lemur.destinations.schemas import DestinationNestedOutputSchema
Expand Down Expand Up @@ -120,7 +120,7 @@ class CertificateOutputSchema(LemurOutputSchema):
replaces = fields.Nested(CertificateNestedOutputSchema, many=True)
authority = fields.Nested(AuthorityNestedOutputSchema)
roles = fields.Nested(RoleNestedOutputSchema, many=True)
endpoints = fields.List(fields.Dict(), missing=[])
endpoints = fields.Nested(EndpointNestedOutputSchema, many=True, missing=[])


class CertificateUploadInputSchema(CertificateSchema):
Expand Down
24 changes: 23 additions & 1 deletion lemur/endpoints/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,42 @@
:license: Apache, see LICENSE for more details.
.. moduleauthor:: Kevin Glisson <[email protected]>
"""
from marshmallow import fields
from marshmallow import fields, post_dump

from lemur.common.schema import LemurOutputSchema
from lemur.certificates.schemas import CertificateNestedOutputSchema


BAD_CIPHERS = [
'Protocol-SSLv3',
'Protocol-SSLv2'
'Protocol-TLSv1'
]


class PolicyNestedOutputSchema(LemurOutputSchema):
id = fields.Integer()
name = fields.String()
ciphers = fields.Dict()

@post_dump
def add_warnings(self, data):
for cipher in data['ciphers']:
if cipher['name'] in BAD_CIPHERS:
cipher['deprecated'] = True
return data


class EndpointOutputSchema(LemurOutputSchema):
id = fields.Integer()
description = fields.String()
name = fields.String()
dnsname = fields.String()
owner = fields.Email()
type = fields.String()
active = fields.Boolean()
certificate = fields.Nested(CertificateNestedOutputSchema)
policy = fields.Nested(PolicyNestedOutputSchema)


endpoint_output_schema = EndpointOutputSchema()
Expand Down
23 changes: 23 additions & 0 deletions lemur/endpoints/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from lemur.extensions import metrics
from lemur.endpoints.models import Endpoint, Policy

from sqlalchemy import func


def get_all():
"""
Expand Down Expand Up @@ -98,3 +100,24 @@ def render(args):
query = query.filter(Endpoint.id.in_(endpoint_ids))

return database.sort_and_page(query, Endpoint, args)


def stats(**kwargs):
"""
Helper that defines some useful statistics about endpoints.
:param kwargs:
:return:
"""
attr = getattr(Endpoint, kwargs.get('metric'))
query = database.db.session.query(attr, func.count(attr))

items = query.group_by(attr).all()

keys = []
values = []
for key, count in items:
keys.append(key)
values.append(count)

return {'labels': keys, 'values': values}
11 changes: 11 additions & 0 deletions lemur/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,14 @@ class ExtensionSchema(BaseExtensionSchema):
authority_key_identifier = fields.Nested(AuthorityKeyIdentifierSchema)
certificate_info_access = fields.Nested(CertificateInfoAccessSchema)
custom = fields.List(fields.Nested(CustomOIDSchema))


class EndpointNestedOutputSchema(LemurOutputSchema):
__envelope__ = False
id = fields.Integer()
description = fields.String()
name = fields.String()
dnsname = fields.String()
owner = fields.Email()
type = fields.String()
active = fields.Boolean()
21 changes: 21 additions & 0 deletions lemur/static/app/angular/endpoints/services.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';
angular.module('lemur')
.service('EndpointApi', function (LemurRestangular) {
return LemurRestangular.all('endpoints');
})
.service('EndpointService', function ($location, EndpointApi) {
var EndpointService = this;
EndpointService.findEndpointsByName = function (filterValue) {
return EndpointApi.getList({'filter[label]': filterValue})
.then(function (endpoints) {
return endpoints;
});
};

EndpointService.getCertificates = function (endpoint) {
endpoint.getList('certificates').then(function (certificates) {
endpoint.certificates = certificates;
});
};
return EndpointService;
});
42 changes: 42 additions & 0 deletions lemur/static/app/angular/endpoints/view/view.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
'use strict';

angular.module('lemur')

.config(function config($stateProvider) {
$stateProvider.state('endpoints', {
url: '/endpoints',
templateUrl: '/angular/endpoints/view/view.tpl.html',
controller: 'EndpointsViewController'
});
})

.controller('EndpointsViewController', function ($q, $scope, $uibModal, EndpointApi, EndpointService, MomentService, ngTableParams, toaster) {
$scope.filter = {};
$scope.endpointsTable = new ngTableParams({
page: 1, // show first page
count: 10, // count per page
sorting: {
id: 'desc' // initial sorting
},
filter: $scope.filter
}, {
total: 0, // length of data
getData: function ($defer, params) {
EndpointApi.getList(params.url()).then(
function (data) {
params.total(data.total);
$defer.resolve(data);
}
);
}
});

$scope.toggleFilter = function (params) {
params.settings().$scope.show_filter = !params.settings().$scope.show_filter;
};

$scope.momentService = MomentService;

$scope.endpointService = EndpointService;

});
90 changes: 90 additions & 0 deletions lemur/static/app/angular/endpoints/view/view.tpl.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<div class="row">
<div class="col-md-12">
<h2 class="featurette-heading">Endpoints
<span class="text-muted"><small>443 or bust</small></span></h2>
<div class="panel panel-default">
<div class="panel-heading">
<div class="btn-group">
<button ng-click="toggleFilter(endpointsTable)" class="btn btn-default">Filter</button>
</div>
<div class="clearfix"></div>
</div>
<div class="table-responsive">
<table ng-table="endpointsTable" class="table table-striped" show-filter="false" template-pagination="angular/pager.html" >
<tbody>
<tr ng-repeat-start="endpoint in $data track by $index">
<td data-title="'Name'" sortable="'name'" filter="{ 'name': 'text' }">
<ul class="list-unstyled">
<li>{{ endpoint.name }}</li>
<li><span class="text-muted">{{ endpoint.dnsname }}</span></li>
</ul>
</td>
<td data-title="'Type'">
<ul class="list-unstyled">
<li><label class="label label-default text-uppercase">{{ endpoint.type }}</label></li>
</ul>
</td>
<td data-title="''">
<div class="btn-group-vertical pull-right">
<button ng-model="endpoint.toggle" class="btn btn-sm btn-info" uib-btn-checkbox
btn-checkbox-true="1"
btn-checkbox-false="0">More
</button>
</div>
</td>
</tr>
<tr class="warning" ng-if="endpoint.toggle" ng-repeat-end>
<td colspan="12">
<uib-tabset justified="true" class="col-md-6">
<uib-tab>
<uib-tab-heading>Certificate</uib-tab-heading>
<ul class="list-group">
<li class="list-group-item">
<strong>Name</strong>
<span class="pull-right">
{{ endpoint.certificate.name }}
</span>
</li>
<li class="list-group-item">
<strong>Not Before</strong>
<span class="pull-right" uib-tooltip="{{ endpoint.certificate.notBefore }}">
{{ momentService.createMoment(endpoint.certificate.notBefore) }}
</span>
</li>
<li class="list-group-item">
<strong>Not After</strong>
<span class="pull-right" uib-tooltip="{{ endpoint.certificate.notAfter }}">
{{ momentService.createMoment(endpoint.certificate.notAfter) }}
</span>
</li>
<li class="list-group-item">
<strong>Description</strong>
<p>{{ endpoint.certificate.description }}</p>
</li>
</ul>
</uib-tab>
</uib-tabset>
<uib-tabset justified="true" class="col-md-6">
<uib-tab>
<uib-tab-heading>
Ciphers
</uib-tab-heading>
<ul class="list-group">
<li class="list-group-item" ng-repeat="cipher in endpoint.policy.ciphers">
<strong ng-class="{'text-danger': cipher.deprecated}">{{ cipher.name }}</strong>
<span class="pull-right">
<i ng-if=cipher.value ng-class="{'text-danger': cipher.deprecated}" class="fa fa-check" aria-hidden="true"></i>
<i ng-if="!cipher.value" ng-class="{'text-danger': cipher.deprecated}" class="fa fa-times" aria-hidden="true"></i>
</span>
</li>
</ul>
</uib-tab>
</uib-tabset>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
1 change: 1 addition & 0 deletions lemur/static/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<li><a ui-sref="dashboard">Dashboard</a></li>
<li><a ui-sref="certificates">Certificates</a></li>
<li><a ui-sref="authorities">Authorities</a></li>
<li><a ui-sref="endpoints">Endpoints</a></li>
<li><a ui-sref="notifications">Notifications</a></li>
<li><a ui-sref="destinations">Destinations</a></li>
<li><a ui-sref="sources">Sources</a></li>
Expand Down

0 comments on commit 0278e65

Please sign in to comment.