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

Fix access to environments outside AzureCloud #1158

Merged
merged 2 commits into from
Oct 4, 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
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package com.microsoft.azure.management.batch.implementation;

import com.microsoft.azure.AzureEnvironment;
import com.microsoft.azure.RestClient;
import com.microsoft.azure.credentials.AzureTokenCredentials;
import com.microsoft.azure.management.batch.BatchAccounts;
import com.microsoft.azure.management.resources.fluentcore.arm.AzureConfigurable;
import com.microsoft.azure.management.resources.fluentcore.arm.implementation.AzureConfigurableImpl;
import com.microsoft.azure.management.resources.fluentcore.arm.implementation.Manager;
import com.microsoft.azure.management.storage.implementation.StorageManager;
import com.microsoft.rest.credentials.ServiceClientCredentials;

/**
* Entry point to Azure Batch Account resource management.
Expand Down Expand Up @@ -42,8 +41,8 @@ public static Configurable configure() {
* @param subscriptionId the subscription
* @return the BatchManager
*/
public static BatchManager authenticate(ServiceClientCredentials credentials, String subscriptionId) {
return new BatchManager(AzureEnvironment.AZURE.newRestClientBuilder()
public static BatchManager authenticate(AzureTokenCredentials credentials, String subscriptionId) {
return new BatchManager(credentials.getEnvironment().newRestClientBuilder()
.withCredentials(credentials)
.build(), subscriptionId);
}
Expand All @@ -70,15 +69,15 @@ public interface Configurable extends AzureConfigurable<Configurable> {
* @param subscriptionId the subscription
* @return the BatchManager
*/
BatchManager authenticate(ServiceClientCredentials credentials, String subscriptionId);
BatchManager authenticate(AzureTokenCredentials credentials, String subscriptionId);
}

/**
* The implementation for Configurable interface.
*/
private static final class ConfigurableImpl extends AzureConfigurableImpl<Configurable> implements Configurable {
@Override
public BatchManager authenticate(ServiceClientCredentials credentials, String subscriptionId) {
public BatchManager authenticate(AzureTokenCredentials credentials, String subscriptionId) {
return BatchManager.authenticate(buildRestClient(credentials), subscriptionId);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.microsoft.azure.management.compute.implementation;

import com.microsoft.azure.AzureEnvironment;
import com.microsoft.azure.RestClient;
import com.microsoft.azure.credentials.AzureTokenCredentials;
import com.microsoft.azure.management.compute.AvailabilitySets;
import com.microsoft.azure.management.compute.VirtualMachineExtensionImages;
import com.microsoft.azure.management.compute.VirtualMachineImages;
Expand All @@ -11,8 +12,6 @@
import com.microsoft.azure.management.resources.fluentcore.arm.implementation.AzureConfigurableImpl;
import com.microsoft.azure.management.resources.fluentcore.arm.implementation.Manager;
import com.microsoft.azure.management.storage.implementation.StorageManager;
import com.microsoft.azure.RestClient;
import com.microsoft.rest.credentials.ServiceClientCredentials;

/**
* Entry point to Azure compute resource management.
Expand Down Expand Up @@ -44,8 +43,8 @@ public static Configurable configure() {
* @param subscriptionId the subscription
* @return the ComputeManager
*/
public static ComputeManager authenticate(ServiceClientCredentials credentials, String subscriptionId) {
return new ComputeManager(AzureEnvironment.AZURE.newRestClientBuilder()
public static ComputeManager authenticate(AzureTokenCredentials credentials, String subscriptionId) {
return new ComputeManager(credentials.getEnvironment().newRestClientBuilder()
.withCredentials(credentials)
.build(), subscriptionId);
}
Expand All @@ -72,15 +71,15 @@ public interface Configurable extends AzureConfigurable<Configurable> {
* @param subscriptionId the subscription
* @return the ComputeManager
*/
ComputeManager authenticate(ServiceClientCredentials credentials, String subscriptionId);
ComputeManager authenticate(AzureTokenCredentials credentials, String subscriptionId);
}

/**
* The implementation for Configurable interface.
*/
private static final class ConfigurableImpl extends AzureConfigurableImpl<Configurable> implements Configurable {
@Override
public ComputeManager authenticate(ServiceClientCredentials credentials, String subscriptionId) {
public ComputeManager authenticate(AzureTokenCredentials credentials, String subscriptionId) {
return ComputeManager.authenticate(buildRestClient(credentials), subscriptionId);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

package com.microsoft.azure.management.graphrbac.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.ServicePrincipals;
import com.microsoft.azure.management.graphrbac.Users;
import com.microsoft.azure.management.resources.fluentcore.arm.AzureConfigurable;
import com.microsoft.azure.management.resources.fluentcore.arm.implementation.AzureConfigurableImpl;
import com.microsoft.rest.credentials.ServiceClientCredentials;

/**
* Entry point to Azure resource management.
Expand All @@ -26,21 +26,6 @@ public final class GraphRbacManager {
private Users users;
private ServicePrincipals servicePrincipals;

/**
* Creates an instance of GraphRbacManager that exposes resource management API entry points.
*
* @param credentials the credentials to use
* @param tenantId the tenantId in Active Directory
* @return the GraphRbacManager instance
*/
public static GraphRbacManager authenticate(ServiceClientCredentials credentials, String tenantId) {
return new GraphRbacManager(new RestClient.Builder()
.withBaseUrl("https://graph.windows.net")
.withInterceptor(new RequestIdHeaderInterceptor())
.withCredentials(credentials)
.build(), tenantId);
}

/**
* Creates an instance of GraphRbacManager that exposes resource management API entry points.
*
Expand All @@ -49,7 +34,7 @@ public static GraphRbacManager authenticate(ServiceClientCredentials credentials
*/
public static GraphRbacManager authenticate(AzureTokenCredentials credentials) {
return new GraphRbacManager(new RestClient.Builder()
.withBaseUrl("https://graph.windows.net")
.withBaseUrl(credentials.getEnvironment().getGraphEndpoint())
.withInterceptor(new RequestIdHeaderInterceptor())
.withCredentials(credentials)
.build(), credentials.getDomain());
Expand Down Expand Up @@ -79,15 +64,6 @@ public static Configurable configure() {
* The interface allowing configurations to be set.
*/
public interface Configurable extends AzureConfigurable<Configurable> {
/**
* Creates an instance of GraphRbacManager that exposes resource management API entry points.
*
* @param credentials the credentials to use
* @param tenantId the tenantId in Active Directory
* @return the interface exposing resource management API entry points that work across subscriptions
*/
GraphRbacManager authenticate(ServiceClientCredentials credentials, String tenantId);

/**
* Creates an instance of GraphRbacManager that exposes resource management API entry points.
*
Expand All @@ -103,16 +79,12 @@ public interface Configurable extends AzureConfigurable<Configurable> {
private static class ConfigurableImpl extends AzureConfigurableImpl<Configurable> implements Configurable {
protected ConfigurableImpl() {
super.restClientBuilder = new RestClient.Builder()
.withBaseUrl("https://graph.windows.net")
.withBaseUrl(AzureEnvironment.AZURE.getGraphEndpoint()) // default to public cloud
.withInterceptor(new RequestIdHeaderInterceptor());
}

public GraphRbacManager authenticate(ServiceClientCredentials credentials, String tenantId) {
return GraphRbacManager.authenticate(buildRestClient(credentials), tenantId);
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
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;
import com.microsoft.azure.management.keyvault.Vaults;
import com.microsoft.azure.management.resources.fluentcore.arm.AzureConfigurable;
import com.microsoft.azure.management.resources.fluentcore.arm.implementation.AzureConfigurableImpl;
import com.microsoft.azure.management.resources.fluentcore.arm.implementation.Manager;
import com.microsoft.rest.credentials.ServiceClientCredentials;

/**
* Entry point to Azure storage resource management.
Expand All @@ -40,14 +40,13 @@ public static Configurable configure() {
* Creates an instance of StorageManager that exposes storage resource management API entry points.
*
* @param credentials the credentials to use
* @param tenantId the tenant UUID
* @param subscriptionId the subscription UUID
* @return the StorageManager
*/
public static KeyVaultManager authenticate(ServiceClientCredentials credentials, String tenantId, String subscriptionId) {
return new KeyVaultManager(AzureEnvironment.AZURE.newRestClientBuilder()
public static KeyVaultManager authenticate(AzureTokenCredentials credentials, String subscriptionId) {
return new KeyVaultManager(credentials.getEnvironment().newRestClientBuilder()
.withCredentials(credentials)
.build(), tenantId, subscriptionId);
.build(), credentials.getDomain(), subscriptionId);
}

/**
Expand All @@ -74,25 +73,29 @@ public interface Configurable extends AzureConfigurable<Configurable> {
* @param subscriptionId the subscription UUID
* @return the interface exposing storage management API entry points that work across subscriptions
*/
KeyVaultManager authenticate(ServiceClientCredentials credentials, String tenantId, String subscriptionId);
KeyVaultManager authenticate(AzureTokenCredentials credentials, String tenantId, String subscriptionId);
}

/**
* The implementation for Configurable interface.
*/
private static final class ConfigurableImpl extends AzureConfigurableImpl<Configurable> implements Configurable {
public KeyVaultManager authenticate(ServiceClientCredentials credentials, String tenantId, String subscriptionId) {
public KeyVaultManager authenticate(AzureTokenCredentials credentials, String tenantId, String subscriptionId) {
return KeyVaultManager.authenticate(buildRestClient(credentials), tenantId, subscriptionId);
}
}

private KeyVaultManager(RestClient restClient, String tenantId, String subscriptionId) {
private KeyVaultManager(final RestClient restClient, String tenantId, String subscriptionId) {
super(
restClient,
subscriptionId,
new KeyVaultManagementClientImpl(restClient).withSubscriptionId(subscriptionId));
String graphEndpoint = AzureEnvironment.AZURE.getGraphEndpoint();
if (restClient.credentials() instanceof AzureTokenCredentials) {
graphEndpoint = ((AzureTokenCredentials) restClient.credentials()).getEnvironment().getGraphEndpoint();
}
graphRbacManager = GraphRbacManager.authenticate(new RestClient.Builder()
.withBaseUrl("https://graph.windows.net")
.withBaseUrl(graphEndpoint)
.withInterceptor(new RequestIdHeaderInterceptor())
.withCredentials(restClient.credentials())
.build(), tenantId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@
*/
package com.microsoft.azure.management.network.implementation;

import com.microsoft.azure.AzureEnvironment;
import com.microsoft.azure.management.network.NetworkSecurityGroups;
import com.microsoft.azure.RestClient;
import com.microsoft.azure.credentials.AzureTokenCredentials;
import com.microsoft.azure.management.network.LoadBalancers;
import com.microsoft.azure.management.network.NetworkInterfaces;
import com.microsoft.azure.management.network.NetworkSecurityGroups;
import com.microsoft.azure.management.network.Networks;
import com.microsoft.azure.management.network.PublicIpAddresses;
import com.microsoft.azure.management.resources.fluentcore.arm.AzureConfigurable;
import com.microsoft.azure.management.resources.fluentcore.arm.implementation.AzureConfigurableImpl;
import com.microsoft.azure.management.resources.fluentcore.arm.implementation.Manager;
import com.microsoft.azure.RestClient;
import com.microsoft.rest.credentials.ServiceClientCredentials;

/**
* Entry point to Azure network management.
Expand Down Expand Up @@ -46,8 +45,8 @@ public static Configurable configure() {
* @param subscriptionId the subscription UUID
* @return the NetworkManager
*/
public static NetworkManager authenticate(ServiceClientCredentials credentials, String subscriptionId) {
return new NetworkManager(AzureEnvironment.AZURE.newRestClientBuilder()
public static NetworkManager authenticate(AzureTokenCredentials credentials, String subscriptionId) {
return new NetworkManager(credentials.getEnvironment().newRestClientBuilder()
.withCredentials(credentials)
.build(), subscriptionId);
}
Expand All @@ -74,7 +73,7 @@ public interface Configurable extends AzureConfigurable<Configurable> {
* @param subscriptionId the subscription UUID
* @return the interface exposing network management API entry points that work across subscriptions
*/
NetworkManager authenticate(ServiceClientCredentials credentials, String subscriptionId);
NetworkManager authenticate(AzureTokenCredentials credentials, String subscriptionId);
}

/**
Expand All @@ -84,7 +83,7 @@ private static class ConfigurableImpl
extends AzureConfigurableImpl<Configurable>
implements Configurable {

public NetworkManager authenticate(ServiceClientCredentials credentials, String subscriptionId) {
public NetworkManager authenticate(AzureTokenCredentials credentials, String subscriptionId) {
return NetworkManager.authenticate(buildRestClient(credentials), subscriptionId);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@

package com.microsoft.azure.management.redis.implementation;

import com.microsoft.azure.AzureEnvironment;
import com.microsoft.azure.RestClient;
import com.microsoft.azure.credentials.AzureTokenCredentials;
import com.microsoft.azure.management.redis.RedisCaches;
import com.microsoft.azure.management.resources.fluentcore.arm.AzureConfigurable;
import com.microsoft.azure.management.resources.fluentcore.arm.implementation.AzureConfigurableImpl;
import com.microsoft.azure.management.resources.fluentcore.arm.implementation.Manager;
import com.microsoft.rest.credentials.ServiceClientCredentials;

/**
* Entry point to Azure redis resource management.
Expand Down Expand Up @@ -44,8 +43,8 @@ public static Configurable configure() {
* @param subscriptionId the subscription UUID
* @return the RedisManager
*/
public static RedisManager authenticate(ServiceClientCredentials credentials, String subscriptionId) {
return new RedisManager(AzureEnvironment.AZURE.newRestClientBuilder()
public static RedisManager authenticate(AzureTokenCredentials credentials, String subscriptionId) {
return new RedisManager(credentials.getEnvironment().newRestClientBuilder()
.withCredentials(credentials)
.build(), subscriptionId);
}
Expand Down Expand Up @@ -85,14 +84,14 @@ public interface Configurable extends AzureConfigurable<Configurable> {
* @param subscriptionId the subscription UUID
* @return the interface exposing Redis management API entry points that work across subscriptions
*/
RedisManager authenticate(ServiceClientCredentials credentials, String subscriptionId);
RedisManager authenticate(AzureTokenCredentials credentials, String subscriptionId);
}

/**
* The implementation for Configurable interface.
*/
private static final class ConfigurableImpl extends AzureConfigurableImpl<Configurable> implements Configurable {
public RedisManager authenticate(ServiceClientCredentials credentials, String subscriptionId) {
public RedisManager authenticate(AzureTokenCredentials credentials, String subscriptionId) {
return RedisManager.authenticate(buildRestClient(credentials), subscriptionId);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
* Enumeration of the Azure datacenter regions. See https://azure.microsoft.com/regions/
*/
public enum Region {
// CHECKSTYLE IGNORE Javadoc FOR NEXT 18 LINES
// CHECKSTYLE IGNORE Javadoc FOR NEXT 21 LINES
US_WEST("westus", "West US"),
US_WEST2("westus2", "West US 2"),
US_CENTRAL("centralus", "Central US"),
US_EAST("eastus", "East US"),
US_EAST2("eastus2", "East US 2"),
Expand All @@ -28,7 +29,9 @@ public enum Region {
AUSTRALIA_SOUTHEAST("australiasoutheast", "Australia Southeast"),
INDIA_CENTRAL("centralindia", "Central India"),
INDIA_SOUTH("southindia", "South India"),
INDIA_WEST("westindia", "West India");
INDIA_WEST("westindia", "West India"),
CHINA_NORTH("chinanorth", "China North"),
CHINA_EAST("chinaeast", "China East");

private final String name;
private final String label;
Expand Down
Loading