class CloudFoundryService implements CloudService {

    Optional<ProxyConfiguration> proxyConfiguration () {
        List<Proxy> proxies = ProxySelector.getDefault().select(URI.create("https://" + apiHost + ":" + port));
        if (proxies == null || proxies.isEmpty() || proxies.get(0).equals(Proxy.NO_PROXY)) {
            return Optional.empty();
        }
        Proxy proxy = proxies.get(0);
        SocketAddress proxyAddress = proxy.address();
        if (!(proxyAddress instanceof InetSocketAddress)) {
            return Optional.empty();
        }
        InetSocketAddress inetSocketAddress = (InetSocketAddress) proxyAddress;
        String proxyHost = inetSocketAddress.getHostString();
        int proxyPort = inetSocketAddress.getPort();
        return Optional.of(ProxyConfiguration.builder().host(proxyHost).port(proxyPort).build());
    }

}