diff --git a/azure-mgmt-network/pom.xml b/azure-mgmt-network/pom.xml
index 0bcabdee9ac8..0c243d2da07d 100644
--- a/azure-mgmt-network/pom.xml
+++ b/azure-mgmt-network/pom.xml
@@ -55,7 +55,6 @@
com.microsoft.azure
azure-mgmt-resources
1.0.0-SNAPSHOT
- test
junit
diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/PublicIP.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/PublicIP.java
deleted file mode 100644
index 669f22fdfb86..000000000000
--- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/PublicIP.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package com.microsoft.azure.management.network;
-
-
-public interface PublicIP {
-}
diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/PublicIpAddress.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/PublicIpAddress.java
new file mode 100644
index 000000000000..3c797146ca41
--- /dev/null
+++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/PublicIpAddress.java
@@ -0,0 +1,83 @@
+/**
+ * Copyright (c) Microsoft Corporation. All rights reserved.
+ * Licensed under the MIT License. See License.txt in the project root for
+ * license information.
+ */
+package com.microsoft.azure.management.network;
+
+import com.microsoft.azure.management.network.implementation.api.PublicIPAddressInner;
+import com.microsoft.azure.management.resources.fluentcore.arm.models.GroupableResource;
+import com.microsoft.azure.management.resources.fluentcore.model.Provisionable;
+import com.microsoft.azure.management.resources.fluentcore.model.Refreshable;
+import com.microsoft.azure.management.resources.fluentcore.model.Wrapper;
+
+public interface PublicIpAddress extends
+ GroupableResource,
+ Refreshable,
+ Wrapper {
+
+ /***********************************************************
+ * Getters
+ ***********************************************************/
+ String ipAddress();
+ String leafDomainLabel();
+
+ /**************************************************************
+ * Fluent interfaces for provisioning
+ **************************************************************/
+ interface Definitions extends
+ DefinitionBlank,
+ DefinitionWithGroup,
+ DefinitionWithIpAddress,
+ DefinitionWithLeafDomainLabel,
+ DefinitionProvisionable {}
+
+
+ interface DefinitionBlank extends GroupableResource.DefinitionWithRegion {
+ }
+
+ interface DefinitionWithGroup extends GroupableResource.DefinitionWithGroup {
+ }
+
+ public interface DefinitionWithIpAddress {
+ /**
+ * Enables static IP address allocation. The actual IP address allocated for this resource by Azure can be obtained
+ * after the provisioning process is complete from ipAddress().
+ * @return The next stage of the public IP address definition
+ */
+ DefinitionProvisionable withStaticIp();
+
+ /**
+ * Enables dynamic IP address allocation.
+ * @return The next stage of the public IP address definition
+ */
+ DefinitionProvisionable withDynamicIp();
+ }
+
+ /**
+ * A public IP address definition allowing to specify the leaf domain label, if any
+ */
+ public interface DefinitionWithLeafDomainLabel {
+ /**
+ * Specifies the leaf domain label to associate with this public IP address. The fully qualified domain name (FQDN)
+ * will be constructed automatically by appending the rest of the domain to this label.
+ * @param dnsName The leaf domain label to use. This must follow the required naming convention for leaf domain names.
+ * @return The next stage of the public IP address definition
+ */
+ DefinitionProvisionable withLeafDomainLabel(String dnsName);
+
+ /**
+ * Ensures that no leaf domain label will be used. This means that this public IP address will not be associated with a domain name.
+ * @return The next stage of the public IP address definition
+ */
+ DefinitionProvisionable withoutLeafDomainLabel();
+ }
+
+
+ interface DefinitionProvisionable extends
+ Provisionable,
+ DefinitionWithLeafDomainLabel,
+ DefinitionWithIpAddress {
+ }
+}
+
diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/PublicIpAddresses.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/PublicIpAddresses.java
new file mode 100644
index 000000000000..facc59b0f940
--- /dev/null
+++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/PublicIpAddresses.java
@@ -0,0 +1,30 @@
+/**
+ * Copyright (c) Microsoft Corporation. All rights reserved.
+ * Licensed under the MIT License. See License.txt in the project root for
+ * license information.
+ */
+package com.microsoft.azure.management.network;
+
+import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsDeletingByGroup;
+import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingByGroup;
+import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsListingByGroup;
+import com.microsoft.azure.management.resources.fluentcore.collection.SupportsCreating;
+import com.microsoft.azure.management.resources.fluentcore.collection.SupportsDeleting;
+import com.microsoft.azure.management.resources.fluentcore.collection.SupportsGetting;
+import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListing;
+
+public interface PublicIpAddresses extends
+ SupportsCreating,
+ SupportsListing,
+ SupportsListingByGroup,
+ SupportsGetting,
+ SupportsGettingByGroup,
+ SupportsDeleting,
+ SupportsDeletingByGroup {
+
+ interface InGroup extends
+ SupportsListing,
+ SupportsCreating,
+ SupportsDeleting {
+ }
+}
diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkManager.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkManager.java
new file mode 100644
index 000000000000..a2c9e2429430
--- /dev/null
+++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkManager.java
@@ -0,0 +1,64 @@
+/**
+ * Copyright (c) Microsoft Corporation. All rights reserved.
+ * Licensed under the MIT License. See License.txt in the project root for
+ * license information.
+ */
+package com.microsoft.azure.management.network.implementation;
+
+import com.microsoft.azure.management.network.PublicIpAddresses;
+import com.microsoft.azure.management.network.implementation.api.NetworkManagementClientImpl;
+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.implementation.ResourceManager;
+import com.microsoft.rest.RestClient;
+import com.microsoft.rest.credentials.ServiceClientCredentials;
+
+public final class NetworkManager {
+ private final NetworkManagementClientImpl networkManagementClient;
+
+ // Dependent managers
+ private final ResourceManager resourceManager;
+
+ // Collections
+ private PublicIpAddresses publicIpAddresses;
+
+ public static Configurable configure() {
+ return new NetworkManager.ConfigurableImpl();
+ }
+
+ public static NetworkManager authenticate(ServiceClientCredentials credentials, String subscriptionId) {
+ return new NetworkManager(new RestClient
+ .Builder("https://management.azure.com")
+ .withCredentials(credentials)
+ .build(), subscriptionId);
+ }
+
+ public static NetworkManager authenticate(RestClient restClient, String subscriptionId) {
+ return new NetworkManager(restClient, subscriptionId);
+ }
+
+ public interface Configurable extends AzureConfigurable {
+ NetworkManager authenticate(ServiceClientCredentials credentials, String subscriptionId);
+ }
+
+ private static class ConfigurableImpl extends AzureConfigurableImpl implements Configurable {
+ public NetworkManager authenticate(ServiceClientCredentials credentials, String subscriptionId) {
+ return NetworkManager.authenticate(buildRestClient(credentials), subscriptionId);
+ }
+ }
+
+ private NetworkManager(RestClient restClient, String subscriptionId) {
+ networkManagementClient = new NetworkManagementClientImpl(restClient);
+ networkManagementClient.setSubscriptionId(subscriptionId);
+ this.resourceManager = ResourceManager.authenticate(restClient).withSubscription(subscriptionId);
+ }
+
+ public PublicIpAddresses publicIpAddresses() {
+ if(this.publicIpAddresses == null) {
+ this.publicIpAddresses = new PublicIpAddressesImpl(
+ this.networkManagementClient.publicIPAddresses(),
+ this.resourceManager.resourceGroups());
+ }
+ return this.publicIpAddresses;
+ }
+ }
diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/PublicIpAddressImpl.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/PublicIpAddressImpl.java
new file mode 100644
index 000000000000..f696c7b1e2cf
--- /dev/null
+++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/PublicIpAddressImpl.java
@@ -0,0 +1,112 @@
+/**
+ * Copyright (c) Microsoft Corporation. All rights reserved.
+ * Licensed under the MIT License. See License.txt in the project root for
+ * license information.
+ */
+package com.microsoft.azure.management.network.implementation;
+
+import com.microsoft.azure.management.network.PublicIpAddress;
+import com.microsoft.azure.management.network.implementation.api.PublicIPAddressDnsSettings;
+import com.microsoft.azure.management.network.implementation.api.PublicIPAddressInner;
+import com.microsoft.azure.management.network.implementation.api.PublicIPAddressesInner;
+import com.microsoft.azure.management.resources.ResourceGroups;
+import com.microsoft.azure.management.resources.fluentcore.arm.models.implementation.GroupableResourceImpl;
+import com.microsoft.rest.ServiceResponse;
+
+class PublicIpAddressImpl
+ extends GroupableResourceImpl
+ implements
+ PublicIpAddress,
+ PublicIpAddress.Definitions
+ {
+
+ private String name;
+
+ private final PublicIPAddressesInner client;
+
+ PublicIpAddressImpl(String name,
+ PublicIPAddressInner innerModel,
+ final PublicIPAddressesInner client,
+ final ResourceGroups resourceGroups) {
+ super(innerModel.id(), innerModel, resourceGroups);
+ this.name = name;
+ this.client = client;
+ }
+
+ @Override
+ public String name() {
+ return this.name;
+ }
+
+ @Override
+ public PublicIpAddress refresh() throws Exception {
+ ServiceResponse response =
+ this.client.get(this.group(), this.name());
+ PublicIPAddressInner inner = response.getBody();
+ this.setInner(inner);
+ clearWrapperProperties();
+ return this;
+ }
+
+ @Override
+ public PublicIpAddressImpl provision() throws Exception {
+ ensureGroup();
+
+ ServiceResponse response =
+ this.client.createOrUpdate(this.group(), this.name(), this.inner());
+ this.setInner(response.getBody());
+ clearWrapperProperties();
+ return this;
+ }
+
+ private void clearWrapperProperties() {
+
+ }
+
+
+ @Override
+ public PublicIpAddressImpl withStaticIp() {
+ this.inner().setPublicIPAllocationMethod("Static"); // TODO: Replace with IpAllocationMethod.STATIC
+ return this;
+ }
+
+
+ @Override
+ public PublicIpAddressImpl withDynamicIp() {
+ this.inner().setPublicIPAllocationMethod("Dynamic"); // TODO: Replace with IpAllocationMethod.DYNAMIC
+ return this;
+ }
+
+ @Override
+ public PublicIpAddressImpl withLeafDomainLabel(String dnsName) {
+ PublicIPAddressDnsSettings dnsSettings;
+ if(dnsName == null) {
+ this.inner().setDnsSettings(null);
+ return this;
+ } else if(null == (dnsSettings = this.inner().dnsSettings())) {
+ dnsSettings = new PublicIPAddressDnsSettings();
+ this.inner().setDnsSettings(dnsSettings);
+ }
+ dnsSettings.setDomainNameLabel(dnsName);
+ return this;
+ }
+
+ @Override
+ public PublicIpAddressImpl withoutLeafDomainLabel() {
+ return this.withLeafDomainLabel(null);
+ }
+
+ @Override
+ public String ipAddress() {
+ return this.inner().ipAddress();
+ }
+
+ @Override
+ public String leafDomainLabel() {
+ if(this.inner().dnsSettings() == null) {
+ return null;
+ } else {
+ return this.inner().dnsSettings().domainNameLabel();
+ }
+ }
+}
\ No newline at end of file
diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/PublicIpAddressesImpl.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/PublicIpAddressesImpl.java
new file mode 100644
index 000000000000..83f94224affc
--- /dev/null
+++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/PublicIpAddressesImpl.java
@@ -0,0 +1,105 @@
+/**
+ * Copyright (c) Microsoft Corporation. All rights reserved.
+ * Licensed under the MIT License. See License.txt in the project root for
+ * license information.
+ */
+package com.microsoft.azure.management.network.implementation;
+
+import com.microsoft.azure.CloudException;
+import com.microsoft.azure.Page;
+import com.microsoft.azure.PagedList;
+import com.microsoft.azure.management.network.PublicIpAddress;
+import com.microsoft.azure.management.network.PublicIpAddresses;
+import com.microsoft.azure.management.network.implementation.api.PublicIPAddressInner;
+import com.microsoft.azure.management.network.implementation.api.PublicIPAddressesInner;
+import com.microsoft.azure.management.resources.ResourceGroups;
+import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils;
+import com.microsoft.azure.management.resources.fluentcore.utils.PagedListConverter;
+import com.microsoft.azure.management.resources.implementation.api.PageImpl;
+import com.microsoft.rest.RestException;
+import com.microsoft.rest.ServiceResponse;
+
+import java.io.IOException;
+import java.util.List;
+
+public class PublicIpAddressesImpl
+ implements PublicIpAddresses {
+ private final PublicIPAddressesInner client;
+ private final ResourceGroups resourceGroups;
+ private final PagedListConverter converter;
+
+ public PublicIpAddressesImpl(final PublicIPAddressesInner client, final ResourceGroups resourceGroups) {
+ this.client = client;
+ this.resourceGroups = resourceGroups;
+ this.converter = new PagedListConverter() {
+ @Override
+ public PublicIpAddress typeConvert(PublicIPAddressInner publicIpAddressInner) {
+ return createFluentModel(publicIpAddressInner);
+ }
+ };
+ }
+
+ @Override
+ public PagedList list() throws CloudException, IOException {
+ ServiceResponse> response = client.listAll();
+ return converter.convert(toPagedList(response.getBody()));
+ }
+
+ @Override
+ public PagedList list(String groupName) throws CloudException, IOException {
+ ServiceResponse> response = client.list(groupName);
+ return converter.convert(toPagedList(response.getBody()));
+ }
+
+ @Override
+ public PublicIpAddress get(String id) throws CloudException, IOException {
+ PublicIPAddressInner inner = client.get(
+ ResourceUtils.groupFromResourceId(id),
+ ResourceUtils.nameFromResourceId(id)).getBody();
+ return createFluentModel(inner);
+ }
+
+ @Override
+ public PublicIpAddress get(String groupName, String name) throws CloudException, IOException {
+ ServiceResponse serviceResponse = this.client.get(groupName, name);
+ return createFluentModel(serviceResponse.getBody());
+ }
+
+ @Override
+ public void delete(String id) throws Exception {
+ this.delete(ResourceUtils.groupFromResourceId(id), ResourceUtils.nameFromResourceId(id));
+ }
+
+ @Override
+ public void delete(String groupName, String name) throws Exception {
+ this.client.delete(groupName, name);
+ }
+
+ @Override
+ public PublicIpAddress.DefinitionBlank define(String name) throws Exception {
+ return createFluentModel(name);
+ }
+
+ private PagedList toPagedList(List list) {
+ PageImpl page = new PageImpl<>();
+ page.setItems(list);
+ page.setNextPageLink(null);
+ return new PagedList(page) {
+ @Override
+ public Page nextPage(String nextPageLink) throws RestException, IOException {
+ return null;
+ }
+ };
+ }
+
+ /** Fluent model create helpers **/
+
+ private PublicIpAddressImpl createFluentModel(String name) {
+ PublicIPAddressInner inner = new PublicIPAddressInner();
+ return new PublicIpAddressImpl(name, inner, this.client, this.resourceGroups);
+ }
+
+ private PublicIpAddressImpl createFluentModel(PublicIPAddressInner inner) {
+ return new PublicIpAddressImpl(inner.name(), inner, this.client, this.resourceGroups);
+ }
+}
diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/ResourceUtils.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/ResourceUtils.java
index 9b1af80bd671..96c60b70dff3 100644
--- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/ResourceUtils.java
+++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/ResourceUtils.java
@@ -5,7 +5,7 @@
public class ResourceUtils {
public static String groupFromResourceId(String id) {
- return extractFromResourceId(id, "resourcegroups");
+ return extractFromResourceId(id, "resourceGroups");
}
public static String extractFromResourceId(String id, String identifier) {
@@ -22,6 +22,6 @@ public static String extractFromResourceId(String id, String identifier) {
}
public static String nameFromResourceId(String id) {
- return null;
+ return id.split("/")[8];
}
}
diff --git a/azure/src/main/java/com/microsoft/azure/implementation/Azure.java b/azure/src/main/java/com/microsoft/azure/implementation/Azure.java
index f0650d884cd1..b77233dad927 100644
--- a/azure/src/main/java/com/microsoft/azure/implementation/Azure.java
+++ b/azure/src/main/java/com/microsoft/azure/implementation/Azure.java
@@ -14,6 +14,8 @@
import com.microsoft.azure.management.compute.AvailabilitySets;
import com.microsoft.azure.management.compute.VirtualMachines;
import com.microsoft.azure.management.compute.implementation.ComputeManager;
+import com.microsoft.azure.management.network.PublicIpAddresses;
+import com.microsoft.azure.management.network.implementation.NetworkManager;
import com.microsoft.azure.management.resources.Deployments;
import com.microsoft.azure.management.resources.GenericResources;
import com.microsoft.azure.management.resources.Subscriptions;
@@ -35,6 +37,7 @@ public final class Azure {
private final ResourceManager resourceManager;
private final StorageManager storageManager;
private final ComputeManager computeManager;
+ private final NetworkManager networkManager;
public static Authenticated authenticate(ServiceClientCredentials credentials) {
return new AuthenticatedImpl(new RestClient
@@ -60,12 +63,14 @@ public static Authenticated authenticate(ServiceClientCredentials credentials) {
*/
public static Authenticated authenticate(File credentialsFile) throws IOException {
ApplicationTokenCredentials credentials = ApplicationTokenCredentials.fromFile(credentialsFile);
- return new AuthenticatedImpl(new RestClient
- .Builder(AzureEnvironment.AZURE.getBaseUrl())
- .withMapperAdapter(new AzureJacksonMapperAdapter())
+
+ return new AuthenticatedImpl(
+ new RestClient.Builder(AzureEnvironment.AZURE.getBaseUrl())
+ .withMapperAdapter(new AzureJacksonMapperAdapter())
.withCredentials(credentials)
.withBaseUrl(credentials.getEnvironment().getBaseUrl())
- .build());
+ .build())
+ .withDefaultSubscription(credentials.defaultSubscriptionId());
}
public static Authenticated authenticate(RestClient restClient) {
@@ -77,31 +82,66 @@ public static Configurable configure() {
}
public interface Configurable extends AzureConfigurable {
+ /**
+ * Authenticates API access based on the provided credentials
+ * @param credentials The credentials to authenticate API access with
+ * @return
+ */
Authenticated authenticate(ServiceClientCredentials credentials);
+
+ /**
+ * Authenticates API access using a properties file containing the required credentials
+ * @param credentialsFile The file containing the credentials in the standard Java properties file format,
+ * with the following keys:
+ * subscription=
+ * tenant=
+ * client=
+ * key=
+ * managementURI=
+ * baseURL=
+ * authURL=
+ * @return Authenticated Azure client
+ * @throws IOException
+ */
+ Authenticated authenticate(File credentialsFile) throws IOException;
}
+
private static final class ConfigurableImpl extends AzureConfigurableImpl implements Configurable {
@Override
public Authenticated authenticate(ServiceClientCredentials credentials) {
return Azure.authenticate(buildRestClient(credentials));
}
+
+ @Override
+ public Authenticated authenticate(File credentialsFile) throws IOException {
+ return Azure.authenticate(credentialsFile);
+ }
}
+
public interface Authenticated {
Subscriptions subscriptions();
Tenants tenants();
Azure withSubscription(String subscriptionId);
+ Azure withDefaultSubscription();
}
private static final class AuthenticatedImpl implements Authenticated {
final private RestClient restClient;
final private ResourceManager.Authenticated resourceManagerAuthenticated;
-
+ private String defaultSubscription;
+
private AuthenticatedImpl(RestClient restClient) {
this.resourceManagerAuthenticated = ResourceManager.authenticate(restClient);
this.restClient = restClient;
}
+ private AuthenticatedImpl withDefaultSubscription(String subscriptionId) {
+ this.defaultSubscription = subscriptionId;
+ return this;
+ }
+
@Override
public Subscriptions subscriptions() {
return resourceManagerAuthenticated.subscriptions();
@@ -116,6 +156,11 @@ public Tenants tenants() {
public Azure withSubscription(String subscriptionId) {
return new Azure(restClient, subscriptionId);
}
+
+ @Override
+ public Azure withDefaultSubscription() {
+ return withSubscription(this.defaultSubscription);
+ }
}
public interface ResourceGroups extends SupportsListing,
@@ -140,6 +185,7 @@ private Azure(RestClient restClient, String subscriptionId) {
this.resourceManager = ResourceManager.authenticate(restClient).withSubscription(subscriptionId);
this.storageManager = StorageManager.authenticate(restClient, subscriptionId);
this.computeManager = ComputeManager.authenticate(restClient, subscriptionId);
+ this.networkManager = NetworkManager.authenticate(restClient, subscriptionId);
}
public ResourceGroups resourceGroups() {
@@ -165,4 +211,8 @@ public AvailabilitySets availabilitySets() {
public VirtualMachines virtualMachines() {
return computeManager.virtualMachines();
}
+
+ public PublicIpAddresses publicIpAddresses() {
+ return this.networkManager.publicIpAddresses();
+ }
}
diff --git a/azure/src/test/java/com/microsoft/azure/AzureTests.java b/azure/src/test/java/com/microsoft/azure/AzureTests.java
index dfb596898271..ae678fcb1a79 100644
--- a/azure/src/test/java/com/microsoft/azure/AzureTests.java
+++ b/azure/src/test/java/com/microsoft/azure/AzureTests.java
@@ -3,12 +3,18 @@
import com.microsoft.azure.credentials.ApplicationTokenCredentials;
import com.microsoft.azure.credentials.AzureEnvironment;
import com.microsoft.azure.implementation.Azure;
+import com.microsoft.azure.management.network.PublicIpAddress;
import com.microsoft.azure.management.resources.Subscriptions;
import com.microsoft.azure.management.resources.fluentcore.arm.Region;
import com.microsoft.azure.management.storage.StorageAccount;
import com.microsoft.azure.management.storage.implementation.api.AccountType;
import com.microsoft.rest.credentials.ServiceClientCredentials;
import okhttp3.logging.HttpLoggingInterceptor;
+import okhttp3.logging.HttpLoggingInterceptor.Level;
+
+import java.io.File;
+import java.io.IOException;
+
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -21,19 +27,61 @@ public class AzureTests {
AzureEnvironment.AZURE);
private static final String subscriptionId = System.getenv("resourceClient-id");
private Subscriptions subscriptions;
- private Azure azure;
+ private Azure azure, azure2;
+ public static void main(String[] args) throws IOException, CloudException {
+ Azure azure = Azure.authenticate(new File("my.auth"))
+ .withDefaultSubscription();
+ System.out.println(String.valueOf(azure.resourceGroups().list().size()));
+
+ Azure.configure().withLogLevel(Level.BASIC).authenticate(new File("my.auth"));
+ System.out.println(String.valueOf(azure.resourceGroups().list().size()));
+ }
+
@Before
public void setup() throws Exception {
- Azure.Authenticated azureAuthed = Azure.configure()
+ // Authenticate based on credentials instance
+ Azure.Authenticated azureAuthed = Azure.configure()
.withLogLevel(HttpLoggingInterceptor.Level.BASIC)
.withUserAgent("AzureTests")
.authenticate(credentials);
subscriptions = azureAuthed.subscriptions();
azure = azureAuthed.withSubscription(subscriptionId);
+
+ // Authenticate based on file
+ this.azure2 = Azure.authenticate(new File("my.auth"))
+ .withDefaultSubscription();
}
+ @Test public void testPublicIpAddresses() throws Exception {
+ // Verify creation of a new public IP address
+ String suffix = String.valueOf(System.currentTimeMillis());
+ String newPipName = "pip" + suffix;
+ PublicIpAddress pip = azure2.publicIpAddresses().define(newPipName)
+ .withRegion(Region.US_WEST)
+ .withNewGroup()
+ .withDynamicIp()
+ .withLeafDomainLabel(newPipName)
+ .provision();
+
+ // Verify list
+ int publicIpAddressCount = azure2.publicIpAddresses().list().size();
+ System.out.println(publicIpAddressCount);
+ Assert.assertTrue(0 < publicIpAddressCount);
+ String resourceGroupName = pip.group();
+ pip = azure2.publicIpAddresses().get(resourceGroupName, newPipName);
+ Assert.assertTrue(pip.name().equalsIgnoreCase(newPipName));
+ System.out.println(new StringBuilder().append("Public IP Address: ").append(pip.id())
+ .append("\n\tIP Address: ").append(pip.ipAddress())
+ .append("\n\tLeaf domain label: ").append(pip.leafDomainLabel())
+ .toString());
+
+ // Verify delete
+ azure2.publicIpAddresses().delete(pip.id());
+ azure2.resourceGroups().delete(resourceGroupName);
+ }
+
@Test
public void listSubscriptions() throws Exception {
Assert.assertTrue(0 < subscriptions.list().size());
@@ -48,7 +96,7 @@ public void listResourceGroups() throws Exception {
public void listStorageAccounts() throws Exception {
Assert.assertTrue(0 < azure.storageAccounts().list().size());
}
-
+
@Test
public void createStorageAccount() throws Exception {
StorageAccount storageAccount = azure.storageAccounts().define("my-stg1")
diff --git a/runtimes/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/ApplicationTokenCredentials.java b/runtimes/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/ApplicationTokenCredentials.java
index 1305f2c2c12d..c9eb75f58209 100644
--- a/runtimes/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/ApplicationTokenCredentials.java
+++ b/runtimes/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/ApplicationTokenCredentials.java
@@ -33,7 +33,9 @@ public class ApplicationTokenCredentials extends TokenCredentials {
private AzureEnvironment environment;
/** The current authentication result. */
private AuthenticationResult authenticationResult;
-
+ /** The default subscription to use, if any */
+ private String defaultSubscription;
+
/**
* Initializes a new instance of the UserTokenCredentials.
*
@@ -80,7 +82,18 @@ public String toString() {
}
}
-
+ /**
+ * @return The default subscription ID, if any
+ */
+ public String defaultSubscriptionId() {
+ return defaultSubscription;
+ }
+
+ ApplicationTokenCredentials withDefaultSubscriptionId(String subscriptionId) {
+ this.defaultSubscription = subscriptionId;
+ return this;
+ }
+
/**
* Initializes the credentials based on the provided credentials file
* @param credentialsFile A file with credentials, using the standard Java properties format
@@ -113,7 +126,8 @@ public static ApplicationTokenCredentials fromFile(File credentialsFile) throws
final String mgmtUri = authSettings.getProperty(CredentialSettings.MANAGEMENT_URI.toString());
final String authUrl = authSettings.getProperty(CredentialSettings.AUTH_URL.toString());
final String baseUrl = authSettings.getProperty(CredentialSettings.BASE_URL.toString());
-
+ final String defaultSubscriptionId = authSettings.getProperty(CredentialSettings.SUBSCRIPTION_ID.toString());
+
return new ApplicationTokenCredentials(
clientId,
tenantId,
@@ -123,7 +137,7 @@ public static ApplicationTokenCredentials fromFile(File credentialsFile) throws
mgmtUri,
true,
baseUrl)
- );
+ ).withDefaultSubscriptionId(defaultSubscriptionId);
}
@@ -153,7 +167,7 @@ public String getDomain() {
public String getSecret() {
return secret;
}
-
+
/**
* Gets the Azure environment to authenticate with.
*