Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce complexity in RestClient #1186

Merged
merged 2 commits into from
Oct 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions azure-mgmt-batch/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-client-runtime</artifactId>
<version>1.0.0-beta4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
Expand All @@ -64,7 +63,6 @@
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-client-authentication</artifactId>
<version>1.0.0-beta4-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
import com.microsoft.azure.management.resources.implementation.ResourceManager;
import okhttp3.logging.HttpLoggingInterceptor;

import java.io.File;
import java.io.IOException;

public abstract class BatchManagementTestBase {
protected static ResourceManager resourceManager;
protected static BatchManager batchManager;
Expand All @@ -21,7 +18,8 @@ public static void createClients() {
System.getenv("secret"),
AzureEnvironment.AZURE);

RestClient restClient = AzureEnvironment.AZURE.newRestClientBuilder()
RestClient restClient = new RestClient.Builder()
.withBaseUrl(AzureEnvironment.AZURE, AzureEnvironment.Endpoint.RESOURCE_MANAGER)
.withCredentials(credentials)
.withLogLevel(HttpLoggingInterceptor.Level.BODY)
.build();
Expand Down
2 changes: 0 additions & 2 deletions azure-mgmt-compute/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-client-runtime</artifactId>
<version>1.0.0-beta4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
Expand All @@ -74,7 +73,6 @@
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-client-authentication</artifactId>
<version>1.0.0-beta4-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public static void createClients() {
System.getenv("secret"),
AzureEnvironment.AZURE);

RestClient restClient = AzureEnvironment.AZURE.newRestClientBuilder()
RestClient restClient = new RestClient.Builder()
.withBaseUrl(AzureEnvironment.AZURE, AzureEnvironment.Endpoint.RESOURCE_MANAGER)
.withCredentials(credentials)
.withLogLevel(HttpLoggingInterceptor.Level.BODY)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static void createClients() {
AzureEnvironment.AZURE);

RestClient restClient = new RestClient.Builder()
.withDefaultBaseUrl(AzureEnvironment.AZURE)
.withBaseUrl(AzureEnvironment.AZURE, AzureEnvironment.Endpoint.RESOURCE_MANAGER)
.withCredentials(credentials)
.withLogLevel(HttpLoggingInterceptor.Level.BODY)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static void createClients() {
AzureEnvironment.AZURE);

RestClient restClient = new RestClient.Builder()
.withDefaultBaseUrl(com.microsoft.azure.AzureEnvironment.AZURE)
.withBaseUrl(AzureEnvironment.AZURE, AzureEnvironment.Endpoint.RESOURCE_MANAGER)
.withCredentials(credentials)
.withLogLevel(HttpLoggingInterceptor.Level.BODY)
.build();
Expand Down
2 changes: 0 additions & 2 deletions azure-mgmt-graph-rbac/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-client-runtime</artifactId>
<version>1.0.0-beta4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
Expand All @@ -64,7 +63,6 @@
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-client-authentication</artifactId>
<version>1.0.0-beta4-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,10 @@ public interface Configurable extends AzureConfigurable<Configurable> {
* The implementation for Configurable interface.
*/
private static class ConfigurableImpl extends AzureConfigurableImpl<Configurable> implements Configurable {
protected ConfigurableImpl() {
super.restClientBuilder = new RestClient.Builder()
.withBaseUrl(AzureEnvironment.AZURE.getGraphEndpoint()) // default to public cloud
.withInterceptor(new RequestIdHeaderInterceptor());
}

public GraphRbacManager authenticate(AzureTokenCredentials credentials) {
return GraphRbacManager.authenticate(buildRestClientForGraph(credentials), credentials.getDomain());
return GraphRbacManager.authenticate(
buildRestClient(credentials, AzureEnvironment.Endpoint.GRAPH),
credentials.getDomain());
}
}

Expand Down
2 changes: 0 additions & 2 deletions azure-mgmt-keyvault/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-client-runtime</artifactId>
<version>1.0.0-beta4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
Expand All @@ -69,7 +68,6 @@
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-client-authentication</artifactId>
<version>1.0.0-beta4-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
package com.microsoft.azure.management.keyvault.implementation;

import com.microsoft.azure.AzureEnvironment;
import com.microsoft.azure.RequestIdHeaderInterceptor;
import com.microsoft.azure.RestClient;
import com.microsoft.azure.credentials.AzureTokenCredentials;
import com.microsoft.azure.management.graphrbac.implementation.GraphRbacManager;
Expand Down Expand Up @@ -44,7 +43,8 @@ public static Configurable configure() {
* @return the StorageManager
*/
public static KeyVaultManager authenticate(AzureTokenCredentials credentials, String subscriptionId) {
return new KeyVaultManager(credentials.getEnvironment().newRestClientBuilder()
return new KeyVaultManager(credentials.getEnvironment()
.newRestClientBuilder()
.withCredentials(credentials)
.build(), credentials.getDomain(), subscriptionId);
}
Expand Down Expand Up @@ -81,7 +81,9 @@ public interface Configurable extends AzureConfigurable<Configurable> {
*/
private static final class ConfigurableImpl extends AzureConfigurableImpl<Configurable> implements Configurable {
public KeyVaultManager authenticate(AzureTokenCredentials credentials, String tenantId, String subscriptionId) {
return KeyVaultManager.authenticate(buildRestClient(credentials), tenantId, subscriptionId);
return KeyVaultManager.authenticate(
buildRestClient(credentials, AzureEnvironment.Endpoint.RESOURCE_MANAGER),
tenantId, subscriptionId);
}
}

Expand All @@ -94,10 +96,8 @@ private KeyVaultManager(final RestClient restClient, String tenantId, String sub
if (restClient.credentials() instanceof AzureTokenCredentials) {
graphEndpoint = ((AzureTokenCredentials) restClient.credentials()).getEnvironment().getGraphEndpoint();
}
graphRbacManager = GraphRbacManager.authenticate(new RestClient.Builder()
graphRbacManager = GraphRbacManager.authenticate(restClient.newBuilder()
.withBaseUrl(graphEndpoint)
.withInterceptor(new RequestIdHeaderInterceptor())
.withCredentials(restClient.credentials())
.build(), tenantId);
this.tenantId = tenantId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ protected static void createClients() {
System.getenv("secret"),
AzureEnvironment.AZURE);

RestClient restClient = AzureEnvironment.AZURE.newRestClientBuilder()
RestClient restClient = new RestClient.Builder()
.withBaseUrl(AzureEnvironment.AZURE, AzureEnvironment.Endpoint.RESOURCE_MANAGER)
.withCredentials(credentials)
.withLogLevel(HttpLoggingInterceptor.Level.BODY)
.build();
Expand Down
2 changes: 0 additions & 2 deletions azure-mgmt-network/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-client-runtime</artifactId>
<version>1.0.0-beta4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
Expand All @@ -64,7 +63,6 @@
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-client-authentication</artifactId>
<version>1.0.0-beta4-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.microsoft.azure.management.network;

import com.microsoft.azure.AzureEnvironment;
import com.microsoft.azure.RestClient;
import com.microsoft.azure.credentials.ApplicationTokenCredentials;
import com.microsoft.azure.management.network.implementation.NetworkManager;
import com.microsoft.azure.management.resources.implementation.ResourceManager;
import com.microsoft.azure.RestClient;

public abstract class NetworkManagementTestBase {
protected static ResourceManager resourceManager;
Expand All @@ -17,7 +17,8 @@ public static void createClients() {
System.getenv("secret"),
null);

RestClient restClient = AzureEnvironment.AZURE.newRestClientBuilder()
RestClient restClient = new RestClient.Builder()
.withBaseUrl(AzureEnvironment.AZURE, AzureEnvironment.Endpoint.RESOURCE_MANAGER)
.withCredentials(credentials)
//.withLogLevel(HttpLoggingInterceptor.Level.BASIC)
.build();
Expand Down
2 changes: 0 additions & 2 deletions azure-mgmt-redis/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-client-runtime</artifactId>
<version>1.0.0-beta4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
Expand All @@ -63,7 +62,6 @@
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-client-authentication</artifactId>
<version>1.0.0-beta4-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ protected static void createClients() {
System.getenv("secret"),
AzureEnvironment.AZURE);

RestClient restClient = AzureEnvironment.AZURE.newRestClientBuilder()
RestClient restClient = new RestClient.Builder()
.withBaseUrl(AzureEnvironment.AZURE, AzureEnvironment.Endpoint.RESOURCE_MANAGER)
.withCredentials(credentials)
.withLogLevel(HttpLoggingInterceptor.Level.BODY)
// uncomment for Fiddler tracing
Expand Down
2 changes: 0 additions & 2 deletions azure-mgmt-resources/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-client-runtime</artifactId>
<version>1.0.0-beta4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand All @@ -63,7 +62,6 @@
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-client-authentication</artifactId>
<version>1.0.0-beta4-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import okhttp3.Interceptor;
import okhttp3.logging.HttpLoggingInterceptor;

import java.lang.reflect.Field;
import java.net.Proxy;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
Expand All @@ -26,10 +25,10 @@
*/
public class AzureConfigurableImpl<T extends AzureConfigurable<T>>
implements AzureConfigurable<T> {
protected RestClient.Builder.Buildable restClientBuilder;
protected RestClient.Builder restClientBuilder;

protected AzureConfigurableImpl() {
this.restClientBuilder = AzureEnvironment.AZURE.newRestClientBuilder(); // default to public cloud
this.restClientBuilder = new RestClient.Builder(); // default to public cloud
}

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -88,28 +87,12 @@ public T withProxy(Proxy proxy) {
return (T) this;
}

protected RestClient buildRestClient(AzureTokenCredentials credentials) {
restClientBuilder = modifyBaseUrl(restClientBuilder, credentials.getEnvironment().getBaseUrl());
protected RestClient buildRestClient(AzureTokenCredentials credentials, AzureEnvironment.Endpoint endpoint) {
restClientBuilder = restClientBuilder.withBaseUrl(credentials.getEnvironment(), endpoint);
return restClientBuilder.withCredentials(credentials).build();
}

protected RestClient buildRestClientForGraph(AzureTokenCredentials credentials) {
restClientBuilder = modifyBaseUrl(restClientBuilder, credentials.getEnvironment().getGraphEndpoint());
return restClientBuilder.withCredentials(credentials).build();
}

private RestClient.Builder.Buildable modifyBaseUrl(RestClient.Builder.Buildable builder, String baseUrl) {
try {
// This reflection will be removed in next version of client runtime
Field enclosed = builder.getClass().getDeclaredField("this$0");
enclosed.setAccessible(true);
Object enclosedObj = enclosed.get(builder);
Field url = enclosedObj.getClass().getDeclaredField("baseUrl");
url.setAccessible(true);
url.set(enclosedObj, baseUrl);
} catch (IllegalAccessException | NoSuchFieldException ex) {
// swallow it to use default base url
}
return builder;
protected RestClient buildRestClient(AzureTokenCredentials credentials) {
return buildRestClient(credentials, AzureEnvironment.Endpoint.RESOURCE_MANAGER);
}
}
2 changes: 0 additions & 2 deletions azure-mgmt-search/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-client-runtime</artifactId>
<version>1.0.0-beta4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
Expand All @@ -65,7 +64,6 @@
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-client-authentication</artifactId>
<version>1.0.0-beta4-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
2 changes: 0 additions & 2 deletions azure-mgmt-storage/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-client-runtime</artifactId>
<version>1.0.0-beta4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
Expand All @@ -64,7 +63,6 @@
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-client-authentication</artifactId>
<version>1.0.0-beta4-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ protected static void createClients() {
System.getenv("secret"),
AzureEnvironment.AZURE);

RestClient restClient = AzureEnvironment.AZURE.newRestClientBuilder()
RestClient restClient = new RestClient.Builder()
.withBaseUrl(AzureEnvironment.AZURE, AzureEnvironment.Endpoint.RESOURCE_MANAGER)
.withCredentials(credentials)
.withLogLevel(HttpLoggingInterceptor.Level.BODY)
.withLogLevel(HttpLoggingInterceptor.Level.BASIC)
.build();

resourceManager = ResourceManager
Expand Down
1 change: 0 additions & 1 deletion azure-mgmt-website/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-client-runtime</artifactId>
<version>1.0.0-beta4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
Expand Down
2 changes: 0 additions & 2 deletions azure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,10 @@
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-client-runtime</artifactId>
<version>1.0.0-beta4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-client-authentication</artifactId>
<version>1.0.0-beta4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-client-runtime</artifactId>
<version>1.0.0-beta4-SNAPSHOT</version>
<version>1.0.0-beta4-20161011.232453-5</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-client-authentication</artifactId>
<version>1.0.0-beta4-SNAPSHOT</version>
<version>1.0.0-beta4-20161011.232500-5</version>
</dependency>
<!-- Test dependencies -->
<dependency>
Expand Down