Java Code Examples for com.microsoft.azure.management.sql.SqlFirewallRule

The following examples show how to use com.microsoft.azure.management.sql.SqlFirewallRule. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: pacbot   Source File: SQLDatabaseInventoryCollector.java    License: Apache License 2.0 5 votes vote down vote up
private void firewallRule(SqlServer sqlServer, SQLDatabaseVH sqlDatabaseVH) {
	List<Map<String, String>> firewallRuleList = new ArrayList<>();
	Map<String, String> firewallMap;
	for (SqlFirewallRule sqlFirewallRule : sqlServer.firewallRules().list()) {
		firewallMap = new HashMap<>();
		firewallMap.put("name", sqlFirewallRule.name());
		firewallMap.put("startIPAddress", sqlFirewallRule.startIPAddress());
		firewallMap.put("endIPAddress", sqlFirewallRule.endIPAddress());
		firewallRuleList.add(firewallMap);

	}
	for (SqlVirtualNetworkRule sqlVirtualNetworkRule : sqlServer.virtualNetworkRules().list()) {
		firewallMap = new HashMap<>();

		firewallMap.put("virtualNetworkRuleName",
				sqlVirtualNetworkRule.name() != null ? sqlVirtualNetworkRule.name() : "");
		firewallMap.put("virtualNetworkSubnetId",
				sqlVirtualNetworkRule.subnetId() != null ? sqlVirtualNetworkRule.subnetId() : "");
		firewallMap.put("virtualNetworkResourceGroupName",
				sqlVirtualNetworkRule.resourceGroupName() != null ? sqlVirtualNetworkRule.resourceGroupName() : "");
		firewallMap.put("virtualNetworkState",
				sqlVirtualNetworkRule.state() != null ? sqlVirtualNetworkRule.state() : "");

		firewallRuleList.add(firewallMap);
	}
	sqlDatabaseVH.setFirewallRuleDetails(firewallRuleList);
}
 
Example 2
Source Project: pacbot   Source File: SQLServerInventoryCollector.java    License: Apache License 2.0 5 votes vote down vote up
private void firewallRule(SqlServer sqlServer, SQLServerVH sqlServerVH) {
	List<Map<String, String>> firewallRuleList = new ArrayList<>();
	Map<String, String> firewallMap;
	for (SqlFirewallRule sqlFirewallRule : sqlServer.firewallRules().list()) {
		firewallMap = new HashMap<>();
		firewallMap.put("name", sqlFirewallRule.name());
		firewallMap.put("startIPAddress", sqlFirewallRule.startIPAddress());
		firewallMap.put("endIPAddress", sqlFirewallRule.endIPAddress());
		firewallRuleList.add(firewallMap);

	}
	for (SqlVirtualNetworkRule sqlVirtualNetworkRule : sqlServer.virtualNetworkRules().list()) {
		firewallMap = new HashMap<>();

		firewallMap.put("virtualNetworkRuleName",
				sqlVirtualNetworkRule.name() != null ? sqlVirtualNetworkRule.name() : "");
		firewallMap.put("virtualNetworkSubnetId",
				sqlVirtualNetworkRule.subnetId() != null ? sqlVirtualNetworkRule.subnetId() : "");
		firewallMap.put("virtualNetworkResourceGroupName",
				sqlVirtualNetworkRule.resourceGroupName() != null ? sqlVirtualNetworkRule.resourceGroupName() : "");
		firewallMap.put("virtualNetworkState",
				sqlVirtualNetworkRule.state() != null ? sqlVirtualNetworkRule.state() : "");

		firewallRuleList.add(firewallMap);
	}
	sqlServerVH.setFirewallRuleDetails(firewallRuleList);
}
 
Example 3
@Override
public SqlFirewallRule get(String name) {
    if (this.sqlServer == null) {
        return null;
    }
    return this.getBySqlServer(this.sqlServer, name);
}
 
Example 4
@Override
public Observable<SqlFirewallRule> getAsync(String name) {
    if (this.sqlServer == null) {
        return null;
    }
    return this.getBySqlServerAsync(this.sqlServer, name);
}
 
Example 5
@Override
public SqlFirewallRule getById(String id) {
    Objects.requireNonNull(id);
    return this.getBySqlServer(ResourceUtils.groupFromResourceId(id),
        ResourceUtils.nameFromResourceId(ResourceUtils.parentRelativePathFromResourceId(id)),
        ResourceUtils.nameFromResourceId(id));
}
 
Example 6
@Override
public Observable<SqlFirewallRule> getByIdAsync(String id) {
    Objects.requireNonNull(id);
    return this.getBySqlServerAsync(ResourceUtils.groupFromResourceId(id),
        ResourceUtils.nameFromResourceId(ResourceUtils.parentRelativePathFromResourceId(id)),
        ResourceUtils.nameFromResourceId(id));
}
 
Example 7
@Override
public List<SqlFirewallRule> listBySqlServer(SqlServer sqlServer) {
    Objects.requireNonNull(sqlServer);
    List<SqlFirewallRule> firewallRuleSet = new ArrayList<>();
    for (FirewallRuleInner inner : sqlServer.manager().inner().firewallRules().listByServer(sqlServer.resourceGroupName(), sqlServer.name())) {
        firewallRuleSet.add(new SqlFirewallRuleImpl(inner.name(), (SqlServerImpl) sqlServer, inner, sqlServer.manager()));
    }
    return Collections.unmodifiableList(firewallRuleSet);
}
 
Example 8
@Override
public List<SqlFirewallRule> list() {
    if (this.sqlServer == null) {
        return null;
    }
    return this.listBySqlServer(this.sqlServer);
}
 
Example 9
@Override
public Observable<SqlFirewallRule> listAsync() {
    if (sqlServer == null) {
        return null;
    }
    return this.listBySqlServerAsync(this.sqlServer.resourceGroupName(), this.sqlServer.name());
}
 
Example 10
Source Project: azure-libraries-for-java   Source File: SqlServerImpl.java    License: MIT License 5 votes vote down vote up
@Override
public SqlFirewallRule enableAccessFromAzureServices() {
    SqlFirewallRule firewallRule = this.manager().sqlServers().firewallRules()
            .getBySqlServer(this.resourceGroupName(), this.name(), "AllowAllWindowsAzureIps");
    if (firewallRule == null) {
        firewallRule = this.manager().sqlServers().firewallRules()
            .define("AllowAllWindowsAzureIps")
            .withExistingSqlServer(this.resourceGroupName(), this.name())
            .withIPAddress("0.0.0.0")
            .create();
    }

    return firewallRule;
}
 
Example 11
Source Project: azure-libraries-for-java   Source File: SqlServerImpl.java    License: MIT License 5 votes vote down vote up
@Override
public void removeAccessFromAzureServices() {
    SqlFirewallRule firewallRule = this.manager().sqlServers().firewallRules()
        .getBySqlServer(this.resourceGroupName(), this.name(), "AllowAllWindowsAzureIps");
    if (firewallRule != null) {
        this.manager().sqlServers().firewallRules()
            .deleteBySqlServer(this.resourceGroupName(), this.name(), "AllowAllWindowsAzureIps");
    }
}
 
Example 12
Source Project: azure-libraries-for-java   Source File: Utils.java    License: MIT License 5 votes vote down vote up
/**
 * Prints information for the passed firewall rule.
 * @param firewallRule firewall rule to be printed.
 */
public static void print(SqlFirewallRule firewallRule) {
    StringBuilder builder = new StringBuilder().append("Sql firewall rule: ").append(firewallRule.id())
            .append("Name: ").append(firewallRule.name())
            .append("\n\tResource group: ").append(firewallRule.resourceGroupName())
            .append("\n\tRegion: ").append(firewallRule.region())
            .append("\n\tSqlServer Name: ").append(firewallRule.sqlServerName())
            .append("\n\tStart IP Address of the firewall rule: ").append(firewallRule.startIPAddress())
            .append("\n\tEnd IP Address of the firewall rule: ").append(firewallRule.endIPAddress());

    System.out.println(builder.toString());
}
 
Example 13
Source Project: clouditor   Source File: AzureSQLServerScanner.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected Asset transform(SqlServer server) throws ScanException {
  var asset = super.transform(server);

  enrich(
      asset,
      "securityAlertPolicy",
      server,
      x -> x.serverSecurityAlertPolicies().get(),
      SqlServerSecurityAlertPolicy::id,
      SqlServerSecurityAlertPolicy::name);

  enrich(
      asset,
      "encryptionProtectors",
      server,
      x -> x.encryptionProtectors().get(),
      SqlEncryptionProtector::id,
      SqlEncryptionProtector::serverKeyName);

  enrich(
      asset,
      "activeDirectoryAdmin",
      server,
      x -> server.getActiveDirectoryAdministrator(),
      SqlActiveDirectoryAdministrator::id,
      SqlActiveDirectoryAdministrator::signInName);

  enrichList(
      asset,
      "firewallRules",
      server,
      x -> x.firewallRules().list(),
      SqlFirewallRule::id,
      SqlFirewallRule::name);

  enrich(
      asset,
      "auditingPolicy",
      server,
      x ->
          this.api
              .azure()
              .sqlServers()
              .manager()
              .inner()
              .serverBlobAuditingPolicies()
              .get(server.resourceGroupName(), server.name()),
      ServerBlobAuditingPolicyInner::id,
      ServerBlobAuditingPolicyInner::name);

  return asset;
}
 
Example 14
@Override
public SqlFirewallRule getBySqlServer(String resourceGroupName, String sqlServerName, String name) {
    FirewallRuleInner inner = this.sqlServerManager.inner().firewallRules().get(resourceGroupName, sqlServerName, name);
    return (inner != null) ? new SqlFirewallRuleImpl(resourceGroupName, sqlServerName, inner.name(), inner, sqlServerManager) : null;
}
 
Example 15
@Override
public SqlFirewallRule getBySqlServer(SqlServer sqlServer, String name) {
    Objects.requireNonNull(sqlServer);
    FirewallRuleInner inner = this.sqlServerManager.inner().firewallRules().get(sqlServer.resourceGroupName(), sqlServer.name(), name);
    return (inner != null) ? new SqlFirewallRuleImpl(inner.name(), (SqlServerImpl) sqlServer, inner, sqlServer.manager()) : null;
}