  def _NormaliseFirewalls(self, interface_rules: Dict[str, Any]) -> List[Any]:
    """Normalise firewall policies and VPC firewalls into a common format.

    Args:
      interface_rules: the effective firewalls for an interface.

    Returns:
      List[Dict[str, Any]]: The normalised firewall rules for an interface with
        individual rules in the following format:
        {
          'type': 'policy' or 'firewall',
          'policy_level': int,
          'priority': int,
          'direction': 'INGRESS' or 'EGRESS',
          'l4config': [
            {
              'ip_protocol': str,
              'ports': List[str]
            }]
          'ips': List[str],
          'action': 'allow' or 'deny' or 'goto_next'
        }
    """

    normalised_rules = []
    firewall_policies = interface_rules.get('firewallPolicys', [])
    firewalls = interface_rules.get('firewalls', [])

    for policy_level, policy in enumerate(firewall_policies):
      for rule in policy['rules']:
        is_ingress = rule['direction'] == 'INGRESS'
        normalised_rule = {
            'type':
                'policy',
            'policy_level':
                policy_level,
            'priority':
                rule['priority'],
            'direction':
                rule['direction'],
            'l4config':
                self._NormaliseFirewallL4Config(rule['match']['layer4Configs']),
            'ips': (
                rule['match'].get('srcIpRanges', []) if is_ingress else
                rule['match'].get('destIpRanges', [])
            ),
            'action':
                rule['action']
        }
        normalised_rules.append(normalised_rule)

    for rule in firewalls:
      is_ingress = rule['direction'] == 'INGRESS'
      is_allow = 'allowed' in rule
      normalised_rule = {
          'type':
              'firewall',
          'policy_level':
              NON_HIERARCHICAL_FW_POLICY_LEVEL,
          'priority':
              rule['priority'],
          'direction':
              rule['direction'],
          'l4config':
              self._NormaliseFirewallL4Config(
                  rule['allowed'] if is_allow else rule['denied']),
          'ips': (
              rule.get('sourceRanges', []) if is_ingress else
              rule.get('destinationRanges', [])
          ),
          'action':
              'allow' if is_allow else 'deny'
      }
      normalised_rules.append(normalised_rule)

    return normalised_rules
Normalise firewall policies and VPC firewalls into a common format.

Args:
interface_rules: the effective firewalls for an interface.

Returns:
List[Dict[str, Any]]: The normalised firewall rules for an interface with
individual rules in the following format:
{
'type': 'policy' or 'firewall',
'policy_level': int,
'priority': int,
'direction': 'INGRESS' or 'EGRESS',
'l4config': [
{
'ip_protocol': str,
'ports': List[str]
}]
'ips': List[str],
'action': 'allow' or 'deny' or 'goto_next'
}
libcloudforensics/providers/gcp/internal/compute.py