Beispiel #1
0
def _build_scan_summary(all_violations, total_resources):
    """Build the scan summary.

    Args:
        all_violations: List of violations.
        total_resources: A dict of the resources and their count.

    Returns:
        Total counts and summaries.
    """
    resource_summaries = {}
    total_violations = 0
    # Build a summary of the violations and counts for the email.
    # resource summary:
    # {
    #     RESOURCE_TYPE: {
    #         'total': TOTAL,
    #         'ids': [...] # resource_ids
    #     },
    #     ...
    # }
    for violation in all_violations:
        resource_type = violation.resource_type
        if resource_type not in resource_summaries:
            resource_summaries[resource_type] = {
                'pluralized_resource_type':
                ResourceUtil.pluralize(resource_type),
                'total': total_resources[resource_type],
                'violations': {}
            }

        # Keep track of # of violations per resource id.
        if (violation.resource_id
                not in resource_summaries[resource_type]['violations']):
            resource_summaries[resource_type]['violations'][
                violation.resource_id] = 0

        # Make sure to count each member violation as a separate one.
        for member in violation.members:
            resource_summaries[resource_type]['violations'][
                violation.resource_id] += 1

            total_violations += 1

    return total_violations, resource_summaries
Beispiel #2
0
 def test_plural_is_correct(self):
     """Test that the resource type is pluralized correctly."""
     self.assertEqual('Organizations',
                      ResourceUtil.pluralize(ResourceType.ORGANIZATION))
     self.assertEqual('Projects',
                      ResourceUtil.pluralize(ResourceType.PROJECT))