Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
73 views
in Technique[技术] by (71.8m points)

java - Make Azure calls only through proxy

I'm trying to make my Azure instance use a proxy server for all the calls he makes. Im creating an azure instance: Azure azure = Azure.configure().withProxy(createProxy(hasProxy)).authenticate(credentials).withSubscription(subscriptionId)

My create proxy method:

    private static Proxy createProxy(String hostPort) throws ServiceWareException {
        String[] arr = hostPort.split(":");
        String host = arr[0];
        String port = arr[1];
        SocketAddress addr = new InetSocketAddress(host, Integer.parseInt(port));
        return new Proxy(Proxy.Type.HTTP, addr);
    }

After doing this I can see in my proxy server call to login.microsoftonline.com:443. The problem is this is the only time Azure making calls through my proxy.

Im listing VMs,networkWatchers, loadbalances and etc... everything with azure variable I've created before.

EDIT: to be more precise, I doesn't make sense to me that azure making only one request through my proxy server while I'm making the actions above, so I'm trying to figure out why.

question from:https://stackoverflow.com/questions/65888236/make-azure-calls-only-through-proxy

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Regarding the issue, please refer to the following code

ApplicationTokenCredentials credentials = new ApplicationTokenCredentials(clientId,
                tenant,
                clientSecret,
                AzureEnvironment.AZURE);
        credentials.withProxy(createProxy());

        Azure azure = Azure.configure()
                .withProxy(createProxy())
                .withLogLevel(LogLevel.BODY_AND_HEADERS)
                .authenticate(credentials)
                .withSubscription(subId);

private static Proxy createProxy() {

        SocketAddress addr = new InetSocketAddress("", Integer.parseInt(""));
        return new Proxy(Proxy.Type.HTTP, addr);

    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...