# Path: capirca/lib/gcp.py
# class Error(Exception):
# class TermError(Error):
# class HeaderError(Error):
# class UnsupportedFilterTypeError(Error):
# class Term(aclgenerator.Term):
# class GCP(aclgenerator.ACLGenerator):
#   _ALLOW_PROTO_NAME = frozenset(
#       ['tcp', 'udp', 'icmp', 'esp', 'ah', 'ipip', 'sctp',
#        'all'
#       ])
#   _GOOD_DIRECTION = ['INGRESS', 'EGRESS']
#   def _GetPorts(self):
#   def _GetLoggingSetting(self):
#   def __str__(self):
# def IsDefaultDeny(term):
# def IsProjectIDValid(project):
# def IsVPCNameValid(vpc):
# def TruncateString(raw_string, max_length):
# def GetIpv6TermName(term_name):
# 
# Path: capirca/lib/nacaddr.py
# def IP(ip, comment='', token='', strict=True):
# def _is_subnet_of(a, b):  # pylint: disable=invalid-name
#   def __init__(self, ip_string, comment='', token='', strict=True):
#   def subnet_of(self, other):
#   def supernet_of(self, other):
#   def __deepcopy__(self, memo):
#   def AddComment(self, comment=''):
#   def supernet(self, prefixlen_diff=1):
#   def __init__(self, ip_string, comment='', token='', strict=True):
#   def subnet_of(self, other):
#   def supernet_of(self, other):
#   def __deepcopy__(self, memo):
#   def supernet(self, prefixlen_diff=1):
#   def AddComment(self, comment=''):
# def _InNetList(adders, ip):
# def IsSuperNet(supernets, subnets):
# def CollapseAddrListPreserveTokens(addresses):
# def _SafeToMerge(address, merge_target, check_addresses):
# def _CollapseAddrListInternal(addresses, complements_by_network):
# def CollapseAddrList(addresses, complement_addresses=None):
# def SortAddrList(addresses):
# def RemoveAddressFromList(superset, exclude):
# def AddressListExclude(superset, excludes, collapse_addrs=True):
# class IPv4(ipaddress.IPv4Network):
# class IPv6(ipaddress.IPv6Network):
# class PrefixlenDiffInvalidError(ipaddress.NetmaskValueError):


import copy
import re
from typing import Dict, Any
from absl import logging
from capirca.lib import gcp
from capirca.lib import nacaddr
      # represented as "all"
      protocols_and_ports = [{'ipProtocol': 'all'}]
    else:
      for proto in filtered_protocols:
        # If the protocol name is not supported, use the protocol number.
        if proto not in self._ALLOW_PROTO_NAME:
          proto = str(self.PROTO_MAP[proto])
          logging.info('INFO: Term %s is being rendered using protocol number',
                       self.term.name)
        proto_ports = {'ipProtocol': proto}
        if self.term.destination_port:
          ports = self._GetPorts()
          if ports:  # Only set when non-empty.
            proto_ports['ports'] = ports
        protocols_and_ports.append(proto_ports)

    if self.api_version == 'ga':
      term_dict['match'] = {layer_4_config: protocols_and_ports}
    else:
      term_dict['match'] = {'config': {layer_4_config: protocols_and_ports}}

    # match needs a field called versionedExpr with value FIREWALL
    # See documentation:
    # https://cloud.google.com/compute/docs/reference/rest/beta/organizationSecurityPolicies/addRule
    term_dict['match']['versionedExpr'] = 'FIREWALL'

    ip_version = self.AF_MAP[self.address_family]
    if ip_version == 4:
      any_ip = [nacaddr.IP('0.0.0.0/0')]
    else:

# Path: capirca/lib/gcp.py
# class Error(Exception):
# class TermError(Error):
# class HeaderError(Error):
# class UnsupportedFilterTypeError(Error):
# class Term(aclgenerator.Term):
# class GCP(aclgenerator.ACLGenerator):
#   _ALLOW_PROTO_NAME = frozenset(
#       ['tcp', 'udp', 'icmp', 'esp', 'ah', 'ipip', 'sctp',
#        'all'
#       ])
#   _GOOD_DIRECTION = ['INGRESS', 'EGRESS']
#   def _GetPorts(self):
#   def _GetLoggingSetting(self):
#   def __str__(self):
# def IsDefaultDeny(term):
# def IsProjectIDValid(project):
# def IsVPCNameValid(vpc):
# def TruncateString(raw_string, max_length):
# def GetIpv6TermName(term_name):
# 
# Path: capirca/lib/nacaddr.py
# def IP(ip, comment='', token='', strict=True):
# def _is_subnet_of(a, b):  # pylint: disable=invalid-name
#   def __init__(self, ip_string, comment='', token='', strict=True):
#   def subnet_of(self, other):
#   def supernet_of(self, other):
#   def __deepcopy__(self, memo):
#   def AddComment(self, comment=''):
#   def supernet(self, prefixlen_diff=1):
#   def __init__(self, ip_string, comment='', token='', strict=True):
#   def subnet_of(self, other):
#   def supernet_of(self, other):
#   def __deepcopy__(self, memo):
#   def supernet(self, prefixlen_diff=1):
#   def AddComment(self, comment=''):
# def _InNetList(adders, ip):
# def IsSuperNet(supernets, subnets):
# def CollapseAddrListPreserveTokens(addresses):
# def _SafeToMerge(address, merge_target, check_addresses):
# def _CollapseAddrListInternal(addresses, complements_by_network):
# def CollapseAddrList(addresses, complement_addresses=None):
# def SortAddrList(addresses):
# def RemoveAddressFromList(superset, exclude):
# def AddressListExclude(superset, excludes, collapse_addrs=True):
# class IPv4(ipaddress.IPv4Network):
# class IPv6(ipaddress.IPv6Network):
# class PrefixlenDiffInvalidError(ipaddress.NetmaskValueError):


# Path: capirca/lib/gcp_hf.py
import copy
import re
from typing import Dict, Any
from absl import logging
from capirca.lib import gcp
from capirca.lib import nacaddr

      # represented as "all"
      protocols_and_ports = [{'ipProtocol': 'all'}]
    else:
      for proto in filtered_protocols:
        # If the protocol name is not supported, use the protocol number.
        if proto not in self._ALLOW_PROTO_NAME:
          proto = str(self.PROTO_MAP[proto])
          logging.info('INFO: Term %s is being rendered using protocol number',
                       self.term.name)
        proto_ports = {'ipProtocol': proto}
        if self.term.destination_port:
          ports = self._GetPorts()
          if ports:  # Only set when non-empty.
            proto_ports['ports'] = ports
        protocols_and_ports.append(proto_ports)

    if self.api_version == 'ga':
      term_dict['match'] = {layer_4_config: protocols_and_ports}
    else:
      term_dict['match'] = {'config': {layer_4_config: protocols_and_ports}}

    # match needs a field called versionedExpr with value FIREWALL
    # See documentation:
    # https://cloud.google.com/compute/docs/reference/rest/beta/organizationSecurityPolicies/addRule
    term_dict['match']['versionedExpr'] = 'FIREWALL'

    ip_version = self.AF_MAP[self.address_family]
    if ip_version == 4:
      any_ip = [nacaddr.IP('0.0.0.0/0')]
    else:

      any_ip = [nacaddr.IPv6('::/0')]