Skip to content

Commit

Permalink
Release 1.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
anuchandy committed Feb 10, 2018
1 parent 69fd93f commit 7b461bf
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure</artifactId>
<version>1.5.0</version>
<version>1.6.0</version>
</dependency>
<dependency>
<groupId>commons-net</groupId>
Expand Down
122 changes: 121 additions & 1 deletion src/main/java/com/microsoft/azure/management/samples/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import com.microsoft.azure.management.keyvault.AccessPolicy;
import com.microsoft.azure.management.keyvault.Vault;
import com.microsoft.azure.management.locks.ManagementLock;
import com.microsoft.azure.management.msi.Identity;
import com.microsoft.azure.management.network.ApplicationGateway;
import com.microsoft.azure.management.network.ApplicationGatewayBackend;
import com.microsoft.azure.management.network.ApplicationGatewayBackendAddress;
Expand Down Expand Up @@ -105,6 +106,7 @@
import com.microsoft.azure.management.network.RouteTable;
import com.microsoft.azure.management.network.SecurityGroupNetworkInterface;
import com.microsoft.azure.management.network.SecurityGroupView;
import com.microsoft.azure.management.network.ServiceEndpointType;
import com.microsoft.azure.management.network.Subnet;
import com.microsoft.azure.management.network.Topology;
import com.microsoft.azure.management.network.TopologyAssociation;
Expand All @@ -115,6 +117,8 @@
import com.microsoft.azure.management.redis.RedisCache;
import com.microsoft.azure.management.redis.RedisCachePremium;
import com.microsoft.azure.management.redis.ScheduleEntry;
import com.microsoft.azure.management.resources.ResourceGroup;
import com.microsoft.azure.management.resources.fluentcore.arm.Region;
import com.microsoft.azure.management.resources.fluentcore.utils.SdkContext;
import com.microsoft.azure.management.search.AdminKeys;
import com.microsoft.azure.management.search.QueryKey;
Expand All @@ -135,7 +139,9 @@
import com.microsoft.azure.management.sql.SqlFirewallRule;
import com.microsoft.azure.management.sql.SqlServer;
import com.microsoft.azure.management.storage.StorageAccount;
import com.microsoft.azure.management.storage.StorageAccountEncryptionStatus;
import com.microsoft.azure.management.storage.StorageAccountKey;
import com.microsoft.azure.management.storage.StorageService;
import com.microsoft.azure.management.trafficmanager.TrafficManagerAzureEndpoint;
import com.microsoft.azure.management.trafficmanager.TrafficManagerExternalEndpoint;
import com.microsoft.azure.management.trafficmanager.TrafficManagerNestedProfileEndpoint;
Expand Down Expand Up @@ -165,6 +171,37 @@
*/

public final class Utils {
/**
* Print resource group info.
*
* @param resource a resource group
*/
public static void print(ResourceGroup resource) {
StringBuilder info = new StringBuilder();
info.append("Resource Group: ").append(resource.id())
.append("\n\tName: ").append(resource.name())
.append("\n\tRegion: ").append(resource.region())
.append("\n\tTags: ").append(resource.tags());
System.out.println(info.toString());
}

/**
* Print User Assigned MSI info.
*
* @param resource a User Assigned MSI
*/
public static void print(Identity resource) {
StringBuilder info = new StringBuilder();
info.append("Resource Group: ").append(resource.id())
.append("\n\tName: ").append(resource.name())
.append("\n\tRegion: ").append(resource.region())
.append("\n\tTags: ").append(resource.tags())
.append("\n\tService Principal Id: ").append(resource.principalId())
.append("\n\tClient Id: ").append(resource.clientId())
.append("\n\tTenant Id: ").append(resource.tenantId())
.append("\n\tClient Secret Url: ").append(resource.clientSecretUrl());
System.out.println(info.toString());
}

/**
* Print virtual machine info.
Expand Down Expand Up @@ -351,6 +388,17 @@ public static void print(Network resource) {
if (routeTable != null) {
info.append("\n\tRoute table ID: ").append(routeTable.id());
}

// Output services with access
Map<ServiceEndpointType, List<Region>> services = subnet.servicesWithAccess();
if (services.size() > 0) {
info.append("\n\tServices with access");
for (Map.Entry<ServiceEndpointType, List<Region>> service : services.entrySet()) {
info.append("\n\t\tService: ")
.append(service.getKey())
.append(" Regions: " + service.getValue() + "");
}
}
}

// Output peerings
Expand Down Expand Up @@ -470,7 +518,6 @@ public static void print(Vault vault) {
System.out.println(info.toString());
}


/**
* Print storage account.
*
Expand All @@ -479,6 +526,46 @@ public static void print(Vault vault) {
public static void print(StorageAccount storageAccount) {
System.out.println(storageAccount.name()
+ " created @ " + storageAccount.creationTime());

StringBuilder info = new StringBuilder().append("Storage Account: ").append(storageAccount.id())
.append("Name: ").append(storageAccount.name())
.append("\n\tResource group: ").append(storageAccount.resourceGroupName())
.append("\n\tRegion: ").append(storageAccount.region())
.append("\n\tSKU: ").append(storageAccount.skuType().name().toString())
.append("\n\tAccessTier: ").append(storageAccount.accessTier())
.append("\n\tKind: ").append(storageAccount.kind());

info.append("\n\tNetwork Rule Configuration: ")
.append("\n\t\tAllow reading logs from any network: ").append(storageAccount.canReadLogEntriesFromAnyNetwork())
.append("\n\t\tAllow reading metrics from any network: ").append(storageAccount.canReadMetricsFromAnyNetwork())
.append("\n\t\tAllow access from all azure services: ").append(storageAccount.canAccessFromAzureServices());

if (storageAccount.networkSubnetsWithAccess().size() > 0) {
info.append("\n\t\tNetwork subnets with access: ");
for (String subnetId : storageAccount.networkSubnetsWithAccess()) {
info.append("\n\t\t\t").append(subnetId);
}
}
if (storageAccount.ipAddressesWithAccess().size() > 0) {
info.append("\n\t\tIP addresses with access: ");
for (String ipAddress : storageAccount.ipAddressesWithAccess()) {
info.append("\n\t\t\t").append(ipAddress);
}
}
if (storageAccount.ipAddressRangesWithAccess().size() > 0) {
info.append("\n\t\tIP address-ranges with access: ");
for (String ipAddressRange : storageAccount.ipAddressRangesWithAccess()) {
info.append("\n\t\t\t").append(ipAddressRange);
}
}
info.append("\n\t\tTraffic allowed from only HTTPS: ").append(storageAccount.inner().enableHttpsTrafficOnly());

info.append("\n\tEncryption status: ");
for (Map.Entry<StorageService, StorageAccountEncryptionStatus> eStatus : storageAccount.encryptionStatuses().entrySet()) {
info.append("\n\t\t").append(eStatus.getValue().storageService()).append(": ").append(eStatus.getValue().isEnabled() ? "Enabled" : "Disabled");
}

System.out.println(info.toString());
}

/**
Expand Down Expand Up @@ -1796,6 +1883,39 @@ public static void uploadFileToFunctionApp(PublishingProfile profile, String fil
}
}

/**
* Uploads a file to an Azure web app.
* @param profile the publishing profile for the web app.
* @param fileName the name of the file on server
* @param file the local file
*/
public static void uploadFileToWebAppWwwRoot(PublishingProfile profile, String fileName, InputStream file) {
FTPClient ftpClient = new FTPClient();
String[] ftpUrlSegments = profile.ftpUrl().split("/", 2);
String server = ftpUrlSegments[0];
String path = "./site/wwwroot";
if (fileName.contains("/")) {
int lastslash = fileName.lastIndexOf('/');
path = path + "/" + fileName.substring(0, lastslash);
fileName = fileName.substring(lastslash + 1);
}
try {
ftpClient.connect(server);
ftpClient.login(profile.ftpUsername(), profile.ftpPassword());
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
for (String segment : path.split("/")) {
if (!ftpClient.changeWorkingDirectory(segment)) {
ftpClient.makeDirectory(segment);
ftpClient.changeWorkingDirectory(segment);
}
}
ftpClient.storeFile(fileName, file);
ftpClient.disconnect();
} catch (IOException e) {
e.printStackTrace();
}
}

private Utils() {

}
Expand Down

0 comments on commit 7b461bf

Please sign in to comment.