/** * Old image security view until formally released. */ angular.module('quay').directive('oldImageSecurityView', function () { var directiveDefinitionObject = { priority: 0, templateUrl: '/static/directives/old-image-security-view.html', replace: false, transclude: true, restrict: 'C', scope: { 'repository': '=repository', 'image': '=image', 'isEnabled': '=isEnabled', 'view': '@view' }, controller: function($scope, $element, Config, ApiService, Features, VulnerabilityService, ImageMetadataService) { var loadImageSecurity = function() { if (!Features.SECURITY_SCANNER || $scope.securityResource) { return; } $scope.VulnerabilityLevels = VulnerabilityService.getLevels(); $scope.options = { 'vulnFilter': '', 'packageFilter': '' }; var params = { 'repository': $scope.repository.namespace + '/' + $scope.repository.name, 'imageid': $scope.image.id, 'vulnerabilities': true, }; $scope.securityResource = ApiService.getRepoImageSecurityAsResource(params).get(function(resp) { $scope.securityStatus = resp.status; $scope.securityFeatures = []; $scope.securityVulnerabilities = []; if (resp.data && resp.data.Layer && resp.data.Layer.Features) { resp.data.Layer.Features.forEach(function(feature) { feature_obj = { 'name': feature.Name, 'namespace': feature.Namespace, 'version': feature.Version, 'addedBy': feature.AddedBy, } feature_vulnerabilities = [] if (feature.Vulnerabilities) { feature.Vulnerabilities.forEach(function(vuln) { vuln_obj = { 'name': vuln.Name, 'namespace': vuln.Namespace, 'description': vuln.Description, 'link': vuln.Link, 'severity': vuln.Severity, 'metadata': vuln.Metadata, 'feature': jQuery.extend({}, feature_obj), 'fixedBy': vuln.FixedBy, 'index': VulnerabilityService.LEVELS[vuln['Severity']]['index'], } feature_vulnerabilities.push(vuln_obj) $scope.securityVulnerabilities.push(vuln_obj); }); } feature_obj['vulnerabilities'] = feature_vulnerabilities $scope.securityFeatures.push(feature_obj); }); } return resp; }); }; $scope.$watch('isEnabled', function(isEnabled) { if ($scope.isEnabled && $scope.repository && $scope.image) { loadImageSecurity(); } }); } }; return directiveDefinitionObject; });