2016-02-22 23:39:04 +00:00
|
|
|
/**
|
|
|
|
* An element which displays the vulnerabilities in an image.
|
|
|
|
*/
|
|
|
|
angular.module('quay').directive('imageVulnerabilityView', function () {
|
|
|
|
var directiveDefinitionObject = {
|
|
|
|
priority: 0,
|
|
|
|
templateUrl: '/static/directives/image-vulnerability-view.html',
|
|
|
|
replace: false,
|
|
|
|
transclude: true,
|
|
|
|
restrict: 'C',
|
|
|
|
scope: {
|
|
|
|
'repository': '=repository',
|
|
|
|
'image': '=image',
|
|
|
|
'isEnabled': '=isEnabled'
|
|
|
|
},
|
2017-06-23 18:53:02 +00:00
|
|
|
controller: function($scope, $element, $routeParams, Config, ApiService, VulnerabilityService, ViewArray, TableService) {
|
2016-02-22 23:39:04 +00:00
|
|
|
$scope.options = {
|
2016-03-09 20:28:21 +00:00
|
|
|
'filter': null,
|
2017-03-15 21:14:59 +00:00
|
|
|
'fixableVulns': $routeParams['fixable'] == 'true',
|
2016-02-22 23:39:04 +00:00
|
|
|
'predicate': 'score',
|
|
|
|
'reverse': false,
|
|
|
|
};
|
|
|
|
|
2016-03-09 20:28:21 +00:00
|
|
|
$scope.TableService = TableService;
|
2016-12-14 05:50:06 +00:00
|
|
|
$scope.loading = false;
|
2016-02-22 23:39:04 +00:00
|
|
|
|
|
|
|
$scope.toggleDetails = function(vuln) {
|
|
|
|
vuln.expanded = !vuln.expanded;
|
|
|
|
};
|
|
|
|
|
2016-03-09 20:28:21 +00:00
|
|
|
$scope.getDistro = function(vuln) {
|
2016-03-10 20:02:38 +00:00
|
|
|
if (vuln['severity'] == 'Defcon 1') {
|
|
|
|
return 'the Quay Engineering Team';
|
|
|
|
}
|
|
|
|
|
2016-03-09 20:28:21 +00:00
|
|
|
return vuln['namespace'].split(':', 1);
|
|
|
|
};
|
2016-02-22 23:39:04 +00:00
|
|
|
|
2016-03-09 20:28:21 +00:00
|
|
|
$scope.getSeverityTooltip = function(vuln) {
|
2016-03-10 20:02:38 +00:00
|
|
|
var distro = $scope.getDistro(vuln);
|
2016-02-22 23:39:04 +00:00
|
|
|
|
2016-03-09 20:28:21 +00:00
|
|
|
if (vuln.scoreDivergence != 'adjusted-lower') {
|
|
|
|
return 'Marked with a ' + vuln['severity'] + ' severity by ' + distro;
|
|
|
|
}
|
2016-02-22 23:39:04 +00:00
|
|
|
|
2016-03-09 20:28:21 +00:00
|
|
|
return 'Note: This vulnerability was originally given a CVSSv2 score ' +
|
|
|
|
'of ' + vuln['cvssScore'] + ' by NVD, but was subsequently reclassifed as a ' +
|
|
|
|
vuln['severity'] + ' issue by ' + distro;
|
|
|
|
};
|
2016-02-22 23:39:04 +00:00
|
|
|
|
2016-03-09 20:28:21 +00:00
|
|
|
var buildOrderedVulnerabilities = function() {
|
|
|
|
if (!$scope.vulnerabilitiesInfo) {
|
|
|
|
return;
|
2016-02-22 23:39:04 +00:00
|
|
|
}
|
|
|
|
|
2016-03-09 20:28:21 +00:00
|
|
|
var vulnerabilities = $scope.vulnerabilitiesInfo.vulnerabilities;
|
|
|
|
$scope.orderedVulnerabilities = TableService.buildOrderedItems(vulnerabilities, $scope.options,
|
|
|
|
['name', 'featureName', 'imageCommand'],
|
|
|
|
['score'],
|
|
|
|
function(item) {
|
|
|
|
return !$scope.options.fixableVulns || item['fixedInVersion'];
|
|
|
|
})
|
2016-02-22 23:39:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
var buildChart = function() {
|
2016-03-09 20:28:21 +00:00
|
|
|
var chartData = $scope.vulnerabilitiesInfo.severityBreakdown;
|
|
|
|
if (chartData.length == 0) {
|
2016-02-22 23:39:04 +00:00
|
|
|
chartData = [{
|
|
|
|
'label': 'None',
|
|
|
|
'value': 1,
|
|
|
|
'color': '#2FC98E'
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
var colors = [];
|
|
|
|
for (var i = 0; i < chartData.length; ++i) {
|
|
|
|
colors.push(chartData[i].color);
|
|
|
|
}
|
|
|
|
|
|
|
|
nv.addGraph(function() {
|
|
|
|
var chart = nv.models.pieChart()
|
|
|
|
.x(function(d) { return d.label })
|
|
|
|
.y(function(d) { return d.value })
|
|
|
|
.margin({left: -10, right: -10, top: -10, bottom: -10})
|
|
|
|
.showLegend(false)
|
|
|
|
.showLabels(true)
|
|
|
|
.labelThreshold(.05)
|
|
|
|
.labelType("percent")
|
|
|
|
.donut(true)
|
|
|
|
.color(colors)
|
|
|
|
.donutRatio(0.5);
|
|
|
|
|
|
|
|
d3.select("#vulnDonutChart svg")
|
|
|
|
.datum(chartData)
|
|
|
|
.transition()
|
|
|
|
.duration(350)
|
|
|
|
.call(chart);
|
|
|
|
|
|
|
|
return chart;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
var loadImageVulnerabilities = function() {
|
2016-12-14 05:50:06 +00:00
|
|
|
if ($scope.loading) {
|
2016-02-22 23:39:04 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-12-14 05:50:06 +00:00
|
|
|
$scope.loading = true;
|
|
|
|
VulnerabilityService.loadImageVulnerabilities($scope.repository, $scope.image.id, function(resp) {
|
2016-02-22 23:39:04 +00:00
|
|
|
$scope.securityStatus = resp.status;
|
2016-03-09 20:28:21 +00:00
|
|
|
$scope.vulnerabilitiesInfo = VulnerabilityService.buildVulnerabilitiesInfo($scope.image, resp);
|
|
|
|
|
|
|
|
buildOrderedVulnerabilities();
|
2016-02-22 23:39:04 +00:00
|
|
|
buildChart();
|
|
|
|
return resp;
|
2016-12-14 05:50:06 +00:00
|
|
|
}, function() {
|
|
|
|
$scope.securityStatus = 'error';
|
2016-02-22 23:39:04 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.$watch('options.predicate', buildOrderedVulnerabilities);
|
|
|
|
$scope.$watch('options.reverse', buildOrderedVulnerabilities);
|
2016-03-09 20:28:21 +00:00
|
|
|
$scope.$watch('options.filter', buildOrderedVulnerabilities);
|
2016-02-22 23:39:04 +00:00
|
|
|
$scope.$watch('options.fixableVulns', buildOrderedVulnerabilities);
|
|
|
|
|
2017-05-10 08:05:03 +00:00
|
|
|
$scope.$watch('repository', function(repository) {
|
|
|
|
if ($scope.isEnabled && $scope.repository && $scope.image) {
|
|
|
|
loadImageVulnerabilities();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$scope.$watch('image', function(image) {
|
|
|
|
if ($scope.isEnabled && $scope.repository && $scope.image) {
|
|
|
|
loadImageVulnerabilities();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-02-22 23:39:04 +00:00
|
|
|
$scope.$watch('isEnabled', function(isEnabled) {
|
|
|
|
if ($scope.isEnabled && $scope.repository && $scope.image) {
|
|
|
|
loadImageVulnerabilities();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
return directiveDefinitionObject;
|
|
|
|
});
|