def _get_firewall_rules(self):
        """Retrieves firewall rules.

        Returns:
            list: FirewallRule
        """
        return firewall_rule_dao.FirewallRuleDao(self.global_configs).\
                        get_firewall_rules(self.snapshot_timestamp)
def _create_dao_map(global_configs):
    """Create a map of DAOs.

    These will be reusable so that the db connection can apply across
    different pipelines.

    Args:
        global_configs (dict): Global configurations.

    Returns:
        dict: Dictionary of DAOs.
    """
    try:
        return {
            'appengine_dao':
            appengine_dao.AppEngineDao(global_configs),
            'backend_service_dao':
            backend_service_dao.BackendServiceDao(global_configs),
            'bucket_dao':
            bucket_dao.BucketDao(global_configs),
            'cloudsql_dao':
            cloudsql_dao.CloudsqlDao(global_configs),
            'dao':
            dao.Dao(global_configs),
            'firewall_rule_dao':
            firewall_rule_dao.FirewallRuleDao(global_configs),
            'folder_dao':
            folder_dao.FolderDao(global_configs),
            'forseti_system_dao':
            forseti_system_dao.ForsetiSystemDao(global_configs),
            'forwarding_rules_dao':
            forwarding_rules_dao.ForwardingRulesDao(global_configs),
            'ke_dao':
            ke_dao.KeDao(global_configs),
            'instance_dao':
            instance_dao.InstanceDao(global_configs),
            'instance_group_dao':
            instance_group_dao.InstanceGroupDao(global_configs),
            'instance_group_manager_dao':
            instance_group_manager_dao.InstanceGroupManagerDao(global_configs),
            'instance_template_dao':
            instance_template_dao.InstanceTemplateDao(global_configs),
            'organization_dao':
            organization_dao.OrganizationDao(global_configs),
            'project_dao':
            project_dao.ProjectDao(global_configs),
            'service_account_dao':
            service_account_dao.ServiceAccountDao(global_configs),
        }
    except data_access_errors.MySQLError as e:
        LOGGER.error('Error to creating DAO map.\n%s', e)
        sys.exit()
Exemple #3
0
    def _retrieve(self):
        """Retrieves the data for scanner.

        Returns:
            list: List of firewall policy data.
            int: The resource count.
        """
        firewall_policies = (firewall_rule_dao.FirewallRuleDao(
            self.global_configs).get_firewall_rules(self.snapshot_timestamp))

        if not firewall_policies:
            LOGGER.warn('No firewall policies found. Exiting.')
            sys.exit(1)

        resource_counts = {
            resource_type.ResourceType.FIREWALL_RULE: len(firewall_policies),
        }

        return firewall_policies, resource_counts