private static URL getProxyUrl(Config config) throws MalformedURLException { URL master = new URL(config.getMasterUrl()); String host = master.getHost(); if (config.getNoProxy() != null) { for (String noProxy : config.getNoProxy()) { if (isIpAddress(noProxy)) { if (new IpAddressMatcher(noProxy).matches(host)) { return null; } } else { if (host.contains(noProxy)) { return null; } } } } String proxy = config.getHttpsProxy(); if (master.getProtocol().equals("http")) { proxy = config.getHttpProxy(); } if (proxy != null) { return new URL(proxy); } return null; }
@Test public void testIpRangeMatcher() { Assert.assertTrue(new IpAddressMatcher("192.168.10.110").matches("192.168.10.110")); Assert.assertTrue(new IpAddressMatcher("192.168.1.0/8").matches("192.168.10.110")); Assert.assertTrue(new IpAddressMatcher("192.168.1.0/24").matches("192.168.1.100")); Assert.assertFalse(new IpAddressMatcher("192.168.1.0/24").matches("193.168.1.10")); Assert.assertFalse(new IpAddressMatcher("192.168.1.0/24").matches("192.168.2.10")); Assert.assertFalse(new IpAddressMatcher("192.168.1.0/24").matches("192.168.2.10")); Assert.assertFalse(new IpAddressMatcher("192.168.1.0/8").matches("193.168.1.10")); Assert.assertFalse(new IpAddressMatcher(Config.KUBERNETES_NO_PROXY).matches("kubernetes.default.svc")); }