diff --git a/src/ResourceManager/Sql/Commands.Sql.Test/Commands.Sql.Test.csproj b/src/ResourceManager/Sql/Commands.Sql.Test/Commands.Sql.Test.csproj index 96f800352f71..0a8705eeb102 100644 --- a/src/ResourceManager/Sql/Commands.Sql.Test/Commands.Sql.Test.csproj +++ b/src/ResourceManager/Sql/Commands.Sql.Test/Commands.Sql.Test.csproj @@ -48,7 +48,7 @@ False - ..\..\..\packages\Microsoft.Azure.Management.Sql.0.14.0-prerelease\lib\net40\Microsoft.Azure.Management.Sql.dll + ..\..\..\packages\Microsoft.Azure.Management.Sql.0.14.3-prerelease\lib\net40\Microsoft.Azure.Management.Sql.dll False @@ -58,7 +58,7 @@ False ..\..\..\packages\Microsoft.Azure.Management.Resources.2.7.1-preview\lib\net40\Microsoft.Azure.ResourceManager.dll - + False ..\..\..\packages\Hydra.HttpRecorder.1.0.5417.13285-prerelease\lib\net45\Microsoft.Azure.Utilities.HttpRecorder.dll @@ -85,17 +85,17 @@ ..\..\..\packages\Microsoft.WindowsAzure.Common.1.4.0\lib\net45\Microsoft.WindowsAzure.Common.dll - + ..\..\..\packages\Microsoft.WindowsAzure.Common.1.4.0\lib\net45\Microsoft.WindowsAzure.Common.NetFramework.dll False ..\..\..\packages\Microsoft.WindowsAzure.Management.Storage.3.1.0\lib\net40\Microsoft.WindowsAzure.Management.Storage.dll - + False ..\..\..\packages\Hydra.SpecTestSupport.1.0.5417.13285-prerelease\lib\net45\Microsoft.WindowsAzure.Testing.dll - + False ..\..\..\packages\Moq.4.2.1402.2112\lib\net40\Moq.dll diff --git a/src/ResourceManager/Sql/Commands.Sql.Test/packages.config b/src/ResourceManager/Sql/Commands.Sql.Test/packages.config index 5c5fc03033b0..af0160fc9427 100644 --- a/src/ResourceManager/Sql/Commands.Sql.Test/packages.config +++ b/src/ResourceManager/Sql/Commands.Sql.Test/packages.config @@ -4,7 +4,7 @@ - + diff --git a/src/ResourceManager/Sql/Commands.Sql/Commands.Sql.csproj b/src/ResourceManager/Sql/Commands.Sql/Commands.Sql.csproj index 4e6abf259975..a95b34a794f3 100644 --- a/src/ResourceManager/Sql/Commands.Sql/Commands.Sql.csproj +++ b/src/ResourceManager/Sql/Commands.Sql/Commands.Sql.csproj @@ -89,7 +89,7 @@ False - ..\..\..\packages\Microsoft.Azure.Management.Sql.0.14.0-prerelease\lib\net40\Microsoft.Azure.Management.Sql.dll + ..\..\..\packages\Microsoft.Azure.Management.Sql.0.14.3-prerelease\lib\net40\Microsoft.Azure.Management.Sql.dll False diff --git a/src/ResourceManager/Sql/Commands.Sql/Properties/Resources.Designer.cs b/src/ResourceManager/Sql/Commands.Sql/Properties/Resources.Designer.cs index 757628091ed5..2b22cf7cd63b 100644 --- a/src/ResourceManager/Sql/Commands.Sql/Properties/Resources.Designer.cs +++ b/src/ResourceManager/Sql/Commands.Sql/Properties/Resources.Designer.cs @@ -60,6 +60,24 @@ internal Resources() { } } + /// + /// Looks up a localized string similar to {your_password_here}. + /// + internal static string EnterPassword { + get { + return ResourceManager.GetString("EnterPassword", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to {your_user_id_here}. + /// + internal static string EnterUserId { + get { + return ResourceManager.GetString("EnterUserId", resourceCulture); + } + } + /// /// Looks up a localized string similar to Cannot use the '{0}' option with other event types.. /// @@ -78,6 +96,33 @@ internal static string NoStorageAccountWhenConfiguringAuditingPolicy { } } + /// + /// Looks up a localized string similar to PHP Data Objects(PDO) Sample Code:. + /// + internal static string PdoTitle { + get { + return ResourceManager.GetString("PdoTitle", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Error connecting to SQL Server. + /// + internal static string PhpConnectionError { + get { + return ResourceManager.GetString("PhpConnectionError", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to SQL Server Extension Sample Code:. + /// + internal static string sqlSampleTitle { + get { + return ResourceManager.GetString("sqlSampleTitle", resourceCulture); + } + } + /// /// Looks up a localized string similar to Cannot find a storage account with the name '{0}'. It either does not exist, associated with a different subscription or you do not have the appropriate credentials to access it.. /// diff --git a/src/ResourceManager/Sql/Commands.Sql/Properties/Resources.resx b/src/ResourceManager/Sql/Commands.Sql/Properties/Resources.resx index 0bb1355309aa..1c3014ac090d 100644 --- a/src/ResourceManager/Sql/Commands.Sql/Properties/Resources.resx +++ b/src/ResourceManager/Sql/Commands.Sql/Properties/Resources.resx @@ -117,12 +117,27 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + {your_password_here} + + + {your_user_id_here} + Cannot use the '{0}' option with other event types. Cannot set auditing policy without a storage account name. + + PHP Data Objects(PDO) Sample Code: + + + Error connecting to SQL Server + + + SQL Server Extension Sample Code: + Cannot find a storage account with the name '{0}'. It either does not exist, associated with a different subscription or you do not have the appropriate credentials to access it. diff --git a/src/ResourceManager/Sql/Commands.Sql/Security/Services/SqlClient.cs b/src/ResourceManager/Sql/Commands.Sql/Security/Services/SqlClient.cs index 4bfada279e82..19e4ef8e7732 100644 --- a/src/ResourceManager/Sql/Commands.Sql/Security/Services/SqlClient.cs +++ b/src/ResourceManager/Sql/Commands.Sql/Security/Services/SqlClient.cs @@ -18,6 +18,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text; namespace Microsoft.Azure.Commands.Sql.Security.Services { @@ -65,6 +66,7 @@ public AuditingPolicy GetDatabaseAuditingPolicy(string resourceGroup, string ser wrapper.ResourceGroupName = resourceGroup; wrapper.ServerName = serverName; wrapper.DatabaseName = databaseName; + AddConnectionStringsToWrapperFromPolicy(wrapper, policy.Properties); return wrapper; } @@ -86,7 +88,6 @@ private AuditingPolicy WrapPolicy(DatabaseSecurityPolicy policy) wrapper.DirectAccessEnabled = !properties.IsBlockDirectAccessEnabled; addStorageInfoToWrapperFromPolicy(wrapper, properties); AddEventTypesToWrapperFromPolicy(wrapper, properties); - AddConnectionStringsToWrapperFromPolicy(wrapper, properties); this.FetchedProperties = properties; return wrapper; } @@ -102,10 +103,69 @@ private void addStorageInfoToWrapperFromPolicy(AuditingPolicy wrapper, DatabaseS private void AddConnectionStringsToWrapperFromPolicy(AuditingPolicy wrapper, DatabaseSecurityPolicyProperties properties) { - wrapper.ConnectionStrings.AdoNetConnectionString = properties.AdoNetConnectionString; - wrapper.ConnectionStrings.OdbcConnectionString = properties.OdbcConnectionString; - wrapper.ConnectionStrings.JdbcConnectionString = properties.JdbcConnectionString; - wrapper.ConnectionStrings.PhpConnectionString = properties.PhpConnectionString; + wrapper.ConnectionStrings.AdoNetConnectionString = ConstructAdoNetConnectionString(wrapper, properties); + wrapper.ConnectionStrings.OdbcConnectionString = ConstructOdbcConnectionString(wrapper, properties); + wrapper.ConnectionStrings.JdbcConnectionString = ConstructJdbcConnectionString(wrapper, properties); + wrapper.ConnectionStrings.PhpConnectionString = ConstructPhpConnectionString(wrapper, properties); + } + + private string ConstructPhpConnectionString(AuditingPolicy wrapper, DatabaseSecurityPolicyProperties properties) + { + string enterUser = Microsoft.Azure.Commands.Sql.Properties.Resources.EnterUserId; + string enterPassword = Microsoft.Azure.Commands.Sql.Properties.Resources.EnterPassword; + string pdoTitle = Microsoft.Azure.Commands.Sql.Properties.Resources.PdoTitle; + string sqlServerSampleTitle = Microsoft.Azure.Commands.Sql.Properties.Resources.sqlSampleTitle; + string connectionError = Microsoft.Azure.Commands.Sql.Properties.Resources.PhpConnectionError; + StringBuilder sb = new StringBuilder(); + sb.Append(string.Format("Server: {0}, {1}", properties.ProxyDnsName, properties.ProxyPort)).Append(Environment.NewLine); + sb.Append(string.Format("SQL Database: {0}", wrapper.DatabaseName)).Append(Environment.NewLine); + sb.Append(string.Format("User Name: {0}", enterUser)).Append(Environment.NewLine).Append(Environment.NewLine); + sb.Append(pdoTitle).Append(Environment.NewLine); + sb.Append("try{").Append(Environment.NewLine); + sb.Append(string.Format("$conn = new PDO ( \"sqlsrv:server = tcp:{0},{1}; Database = \"{2}\", \"{3}\", \"{4}\");", + properties.ProxyDnsName, properties.ProxyPort, wrapper.DatabaseName, enterUser, enterPassword)).Append(Environment.NewLine); + sb.Append("$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );").Append(Environment.NewLine); + sb.Append("}").Append(Environment.NewLine); + sb.Append("catch ( PDOException $e ) {").Append(Environment.NewLine); + sb.Append(string.Format("print( \"{0}\" );", connectionError)).Append(Environment.NewLine); + sb.Append("die(print_r($e));").Append(Environment.NewLine); + sb.Append("}").Append(Environment.NewLine); + sb.Append(sqlServerSampleTitle).Append(Environment.NewLine).Append(Environment.NewLine); + sb.Append(string.Format("connectionInfo = array(\"UID\" => \"{0}@{1}\", \"pwd\" => \"{2}\", \"Database\" => \"{3}\", \"LoginTimeout\" => 30, \"Encrypt\" => 1);", + enterUser, wrapper.ServerName, enterPassword, wrapper.DatabaseName)).Append(Environment.NewLine); + sb.Append(string.Format("$serverName = \"tcp:{0},{1}\";", properties.ProxyDnsName, properties.ProxyPort)).Append(Environment.NewLine); + sb.Append("$conn = sqlsrv_connect($serverName, $connectionInfo);"); + return sb.ToString(); + } + + private string ConstructOdbcConnectionString(AuditingPolicy wrapper, DatabaseSecurityPolicyProperties properties) + { + string enterUser = Microsoft.Azure.Commands.Sql.Properties.Resources.EnterUserId; + string enterPassword = Microsoft.Azure.Commands.Sql.Properties.Resources.EnterPassword; + StringBuilder sb = new StringBuilder(); + sb.Append("Driver={SQL Server Native Client 11.0};"); + sb.Append(string.Format("Server=tcp:{0},{1};", properties.ProxyDnsName, properties.ProxyPort)); + sb.Append(string.Format("Database={0};", wrapper.DatabaseName)); + sb.Append(string.Format("Uid={0}@{1};", enterUser, wrapper.ServerName)); + sb.Append(string.Format("Pwd={0};", enterPassword)); + sb.Append("Encrypt=yes;Connection Timeout=30;"); + return sb.ToString(); + } + + private string ConstructJdbcConnectionString(AuditingPolicy wrapper, DatabaseSecurityPolicyProperties properties) + { + string enterUser = Microsoft.Azure.Commands.Sql.Properties.Resources.EnterUserId; + string enterPassword = Microsoft.Azure.Commands.Sql.Properties.Resources.EnterPassword; + return string.Format("jdbc:sqlserver://{0}:{1};database={2};user={3}@{4};password={5};encrypt=true;hostNameInCertificate=*.database.secure.windows.net;loginTimeout=30;", + properties.ProxyDnsName, properties.ProxyPort, wrapper.DatabaseName, enterUser, wrapper.ServerName, enterPassword); + } + + private string ConstructAdoNetConnectionString(AuditingPolicy wrapper,DatabaseSecurityPolicyProperties properties) + { + string enterUser = Microsoft.Azure.Commands.Sql.Properties.Resources.EnterUserId; + string enterPassword = Microsoft.Azure.Commands.Sql.Properties.Resources.EnterPassword; + return string.Format("Server=tcp:{0},{1};Database={2};User ID={3}@{4};Password={5};Trusted_Connection=False;Encrypt=True;Connection Timeout=30", + properties.ProxyDnsName, properties.ProxyPort, wrapper.DatabaseName, enterUser, wrapper.ServerName, enterPassword); } private void AddEventTypesToWrapperFromPolicy(AuditingPolicy wrapper, DatabaseSecurityPolicyProperties properties) diff --git a/src/ResourceManager/Sql/Commands.Sql/packages.config b/src/ResourceManager/Sql/Commands.Sql/packages.config index f72e111e16ce..73e7a482e05a 100644 --- a/src/ResourceManager/Sql/Commands.Sql/packages.config +++ b/src/ResourceManager/Sql/Commands.Sql/packages.config @@ -1,7 +1,7 @@  - +