def bypass_proxies(url, no_proxy): """Returns whether we should bypass proxies or not.""" parsed = urlparse(url) bypass = False if no_proxy == "": return False no_proxy = (host for host in no_proxy.replace(' ', '').split(',') if host) host_with_port = parsed.hostname if parsed.port: host_with_port += ':{0}'.format(parsed.port) chars = ("*", "*.", ".") for host in no_proxy: if host == "*": bypass = True if host == parsed.hostname or host == host_with_port: bypass = True if host.startswith(chars): host = host.lstrip('*') host = host.lstrip('.') if parsed.hostname.endswith(host) or host_with_port.endswith(host): bypass = True if is_ipv4_address(parsed.hostname): if is_valid_cidr(host): if address_in_network(host_with_port, host): bypass = True return bypass
def validate_azure_additional_networks(self, mgmt_networks): """Validate 'Additional Mgmt Networks' attribute. :param list[str] mgmt_networks: :return: """ self._logger.info( "Validating Deploy App 'Additional Mgmt Networks' attribute") for cidr in mgmt_networks: if not is_valid_cidr(cidr): msg = ( f"CIDR {cidr} under the 'Additional Mgmt Networks' attribute " f"is not in the valid format") self._logger.exception(msg) raise Exception(msg)
def _get_sandbox_subnet_name(self, subnet_id, resource_group_name): """Get Sandbox subnet name from the subnet ID. In a single subnet scenario (default subnet), the subnet id will be a simple CIDR that looks like this: 10.0.3.0/24 In multiple subnets mode, a subnet id will look like this: *4032ffa7-ada9-4ee4-9d33-70ce3c1b06e1_10.0.3.0-24 :param str subnet_id: :param str resource_group_name: :return: """ network_actions = NetworkActions(azure_client=self._azure_client, logger=self._logger) if is_valid_cidr(subnet_id): return network_actions.prepare_sandbox_subnet_name( resource_group_name=resource_group_name, cidr=subnet_id) return get_name_from_resource_id(subnet_id)
def test_is_valid_cidr(self): from requests.utils import is_valid_cidr assert not is_valid_cidr("8.8.8.8") assert is_valid_cidr("192.168.1.0/24")
def test_is_valid_cidr(self): from requests.utils import is_valid_cidr assert not is_valid_cidr('8.8.8.8') assert is_valid_cidr('192.168.1.0/24')
def test_invalid(self, value): assert not is_valid_cidr(value)
def test_valid(self): assert is_valid_cidr('192.168.1.0/24')