diff --git a/src/MySql/Az.MySql.psd1 b/src/MySql/Az.MySql.psd1 index 4ea1d4e7208f..de57db5417a2 100644 --- a/src/MySql/Az.MySql.psd1 +++ b/src/MySql/Az.MySql.psd1 @@ -3,7 +3,7 @@ # # Generated by: Microsoft Corporation # -# Generated on: 1/14/2021 +# Generated on: 2/2/2021 # @{ @@ -45,7 +45,7 @@ PowerShellVersion = '5.1' DotNetFrameworkVersion = '4.7.2' # Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only. -# CLRVersion = '' +# ClrVersion = '' # Processor architecture (None, X86, Amd64) required by this module # ProcessorArchitecture = '' @@ -89,8 +89,9 @@ FunctionsToExport = 'Get-AzMySqlConfiguration', 'Get-AzMySqlConnectionString', 'Remove-AzMySqlVirtualNetworkRule', 'Restart-AzMySqlFlexibleServer', 'Restart-AzMySqlServer', 'Restore-AzMySqlFlexibleServer', 'Restore-AzMySqlServer', 'Start-AzMySqlFlexibleServer', - 'Stop-AzMySqlFlexibleServer', 'Update-AzMySqlConfiguration', - 'Update-AzMySqlFirewallRule', 'Update-AzMySqlFlexibleServer', + 'Stop-AzMySqlFlexibleServer', 'Test-AzMySqlFlexibleServerConnect', + 'Update-AzMySqlConfiguration', 'Update-AzMySqlFirewallRule', + 'Update-AzMySqlFlexibleServer', 'Update-AzMySqlFlexibleServerConfiguration', 'Update-AzMySqlFlexibleServerDatabase', 'Update-AzMySqlFlexibleServerFirewallRule', 'Update-AzMySqlServer', @@ -132,9 +133,7 @@ PrivateData = @{ # IconUri = '' # ReleaseNotes of this module - ReleaseNotes = '* Updated New-AzMySqlFlexibleServer cmdlet to provide easy resource group and network management within RDBMS flexible server management -* Added new cmdlets Get-AzMySqlFlexibleServerLocationBasedCapability and Get-AzMySqlConnectionString -* Added parameter MinimalTlsVersion' + # ReleaseNotes = '' # Prerelease string of this module # Prerelease = '' diff --git a/src/MySql/ChangeLog.md b/src/MySql/ChangeLog.md index 9462f82722a4..589ee069588c 100644 --- a/src/MySql/ChangeLog.md +++ b/src/MySql/ChangeLog.md @@ -18,6 +18,7 @@ - Additional information about change #1 --> ## Upcoming Release +* Added cmdlet `Test-AzMySqlFlexibleServerConnect` ## Version 0.4.0 * Updated New-AzMySqlFlexibleServer cmdlet to provide easy resource group and network management within RDBMS flexible server management diff --git a/src/MySql/custom/New-AzMySqlFlexibleServer.ps1 b/src/MySql/custom/New-AzMySqlFlexibleServer.ps1 index 5fc2d5dd7242..fc0c9ce91608 100644 --- a/src/MySql/custom/New-AzMySqlFlexibleServer.ps1 +++ b/src/MySql/custom/New-AzMySqlFlexibleServer.ps1 @@ -191,7 +191,6 @@ process { $Password = Get-GeneratePassword $PSBoundParameters.AdministratorLoginPassword = $Password | ConvertTo-SecureString -AsPlainText -Force } - $PSBoundParameters.AdministratorLoginPassword = . "$PSScriptRoot/../utils/Unprotect-SecureString.ps1" $PSBoundParameters['AdministratorLoginPassword'] Import-Module -Name Az.Resources if(!$PSBoundParameters.ContainsKey('ResourceGroupName')) { @@ -308,7 +307,7 @@ process { $Server.FirewallRuleName = $FirewallRuleName } $Server.DatabaseName = $DEFAULT_DB_NAME - $Server.SecuredPassword = $PSBoundParameters.AdministratorLoginPassword | ConvertTo-SecureString -AsPlainText -Force + $Server.SecuredPassword = $PSBoundParameters.AdministratorLoginPassword return $Server @@ -526,7 +525,7 @@ function CreateFirewallRule($Parameters) { } return $FirewallRule.Name } - elseif ($Parameters.ContainsKey('PublicAccess') -And $Parameters.PublicAccess.ToLower() -ne 'none') { + elseif ($Parameters.ContainsKey('PublicAccess') -And $Parameters.PublicAccess.ToLower() -eq 'none') { Write-Host "No firewall rule was set" } } diff --git a/src/MySql/custom/New-AzMySqlServer.ps1 b/src/MySql/custom/New-AzMySqlServer.ps1 index df2b26c07015..a2dffc3a3582 100644 --- a/src/MySql/custom/New-AzMySqlServer.ps1 +++ b/src/MySql/custom/New-AzMySqlServer.ps1 @@ -224,7 +224,7 @@ function New-AzMySqlServer { $Parameter.Property.AdministratorLogin = $PSBoundParameters['AdministratorUserName'] $null = $PSBoundParameters.Remove('AdministratorUserName') - $Parameter.Property.AdministratorLoginPassword = . "$PSScriptRoot/../utils/Unprotect-SecureString.ps1" $PSBoundParameters['AdministratorLoginPassword'] + $Parameter.Property.AdministratorLoginPassword = $PSBoundParameters['AdministratorLoginPassword'] $null = $PSBoundParameters.Remove('AdministratorLoginPassword') $PSBoundParameters.Add('Parameter', $Parameter) diff --git a/src/MySql/custom/Test-AzMySqlFlexibleServerConnect.ps1 b/src/MySql/custom/Test-AzMySqlFlexibleServerConnect.ps1 new file mode 100644 index 000000000000..df4b049ab945 --- /dev/null +++ b/src/MySql/custom/Test-AzMySqlFlexibleServerConnect.ps1 @@ -0,0 +1,164 @@ +# ---------------------------------------------------------------------------------- +# +# Copyright Microsoft Corporation +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ---------------------------------------------------------------------------------- + +function Test-AzMySqlFlexibleServerConnect { + [OutputType([System.String])] + [CmdletBinding(DefaultParameterSetName='Test', PositionalBinding=$false)] + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Description('Test out the connection to the database server')] + param( + [Parameter(ParameterSetName='Test', Mandatory, HelpMessage = 'The name of the server to connect.')] + [Parameter(ParameterSetName='TestAndQuery', Mandatory, HelpMessage = 'The name of the server to connect.')] + [Alias('ServerName')] + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Path')] + [System.String] + ${Name}, + + [Parameter(ParameterSetName='Test', Mandatory, HelpMessage = 'The name of the resource group that contains the resource, You can obtain this value from the Azure Resource Manager API or the portal.')] + [Parameter(ParameterSetName='TestAndQuery', Mandatory, HelpMessage = 'The name of the resource group that contains the resource, You can obtain this value from the Azure Resource Manager API or the portal.')] + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Path')] + [System.String] + ${ResourceGroupName}, + + [Parameter(HelpMessage = 'The database name to connect.')] + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Path')] + [System.String] + ${DatabaseName}, + + [Parameter(ParameterSetName='TestViaIdentityAndQuery', Mandatory, HelpMessage = 'The query for the database to test')] + [Parameter(ParameterSetName='TestAndQuery', Mandatory, HelpMessage = 'The query for the database to test')] + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Path')] + [System.String] + ${QueryText}, + + [Parameter(ParameterSetName='TestViaIdentity', Mandatory, ValueFromPipeline, HelpMessage = 'The server to connect.')] + [Parameter(ParameterSetName='TestViaIdentityAndQuery', Mandatory, ValueFromPipeline, HelpMessage = 'The server to connect.')] + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Body')] + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Models.IMySqlIdentity] + ${InputObject}, + + [Parameter(HelpMessage = 'Administrator username for the server. Once set, it cannot be changed.')] + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Body')] + [System.String] + ${AdministratorUserName}, + + [Parameter(Mandatory, HelpMessage = 'The password of the administrator. Minimum 8 characters and maximum 128 characters. Password must contain characters from three of the following categories: English uppercase letters, English lowercase letters, numbers, and non-alphanumeric characters.')] + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Body')] + [System.Security.SecureString] + [ValidateNotNullOrEmpty()] + ${AdministratorLoginPassword}, + + [Parameter(HelpMessage = 'The credentials, account, tenant, and subscription used for communication with Azure.')] + [Alias('AzureRMContext', 'AzureCredential')] + [ValidateNotNull()] + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Azure')] + [System.Management.Automation.PSObject] + ${DefaultProfile}, + + [Parameter(DontShow, HelpMessage = 'Wait for .NET debugger to attach.')] + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Runtime')] + [System.Management.Automation.SwitchParameter] + ${Break}, + + [Parameter(DontShow)] + [ValidateNotNull()] + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Runtime')] + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Runtime.SendAsyncStep[]] + # SendAsync Pipeline Steps to be appended to the front of the pipeline. + ${HttpPipelineAppend}, + + [Parameter(DontShow)] + [ValidateNotNull()] + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Runtime')] + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Runtime.SendAsyncStep[]] + # SendAsync Pipeline Steps to be prepended to the front of the pipeline. + ${HttpPipelinePrepend}, + + [Parameter(DontShow)] + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Runtime')] + [System.Uri] + # The URI for the proxy server to use. + ${Proxy}, + + [Parameter(DontShow)] + [ValidateNotNull()] + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Runtime')] + [System.Management.Automation.PSCredential] + # Credentials for a proxy server to use for the remote call. + ${ProxyCredential}, + + [Parameter(DontShow)] + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Runtime')] + [System.Management.Automation.SwitchParameter] + # Use the default credentials for the proxy. + ${ProxyUseDefaultCredentials} + ) + + process { + if (!(Get-Module -ListAvailable -Name SimplySQL)){ + Write-Error "This cmdlet requires SimplySQL module. Please install the module first by running Install-Module -Name SimplySQL." + exit + } + Import-Module SimplySQL + + $Query = [string]::Empty + if ($PSBoundParameters.ContainsKey('QueryText')) { + $Query = $PSBoundParameters.QueryText + $null = $PSBoundParameters.Remove('QueryText') + } + + $DatabaseName = [string]::Empty + if ($PSBoundParameters.ContainsKey('DatabaseName')) { + $DatabaseName = $PSBoundParameters.DatabaseName + $null = $PSBoundParameters.Remove('DatabaseName') + } + + $Password = $PSBoundParameters['AdministratorLoginPassword'] + $null = $PSBoundParameters.Remove('AdministratorLoginPassword') + + $AdministratorUserName = [string]::Empty + if ($PSBoundParameters.ContainsKey('AdministratorUserName')) { + $AdministratorUserName = $PSBoundParameters.AdministratorUserName + $null = $PSBoundParameters.Remove('AdministratorUserName') + } + + $Server = Az.MySql\Get-AzMySqlFlexibleServer @PSBoundParameters + $HostAddr = $Server.FullyQualifiedDomainName + + if ([string]::IsNullOrEmpty($AdministratorUserName)) { + $AdministratorUserName = $Server.AdministratorLogin + } + + try { + if ([string]::IsNullOrEmpty($DatabaseName)){ + Open-MySqlConnection -Database $DatabaseName -Server $HostAddr -UserName $AdministratorUserName -Password $Password -SSLMode Required -WarningAction 'silentlycontinue' + } + else { + Open-MySqlConnection -Server $HostAddr -UserName $AdministratorUserName -Password $Password -SSLMode Required -WarningAction 'silentlycontinue' + } + } catch { + Write-Host $_.Exception.GetType().FullName + Write-Host $_.Exception.Message + exit + } + + if (![string]::IsNullOrEmpty($Query)) { + Invoke-SqlQuery -Query $Query -WarningAction 'silentlycontinue' + } + else { + $Msg = "The connection testing to {0} was successful!" -f $HostAddr + Write-Host $Msg + } + } +} + diff --git a/src/MySql/custom/Update-AzMySqlFlexibleServer.ps1 b/src/MySql/custom/Update-AzMySqlFlexibleServer.ps1 index c59a4264336a..ee1d9961c2ad 100644 --- a/src/MySql/custom/Update-AzMySqlFlexibleServer.ps1 +++ b/src/MySql/custom/Update-AzMySqlFlexibleServer.ps1 @@ -161,10 +161,6 @@ function Update-AzMySqlFlexibleServer { process { try { - if ($PSBoundParameters.ContainsKey('AdministratorLoginPassword')) { - $PSBoundParameters.AdministratorLoginPassword = . "$PSScriptRoot/../utils/Unprotect-SecureString.ps1" $PSBoundParameters['AdministratorLoginPassword'] - } - if ($PSBoundParameters.ContainsKey('StorageInMb')) { $PSBoundParameters.StorageProfileStorageMb = $PSBoundParameters['StorageInMb'] $null = $PSBoundParameters.Remove('StorageInMb') diff --git a/src/MySql/custom/Update-AzMySqlServer.ps1 b/src/MySql/custom/Update-AzMySqlServer.ps1 index 8eead1d8f584..a743cac3bf3d 100644 --- a/src/MySql/custom/Update-AzMySqlServer.ps1 +++ b/src/MySql/custom/Update-AzMySqlServer.ps1 @@ -165,12 +165,6 @@ function Update-AzMySqlServer { process { try { - if ($PSBoundParameters.ContainsKey('AdministratorLoginPassword')) { - $password = . "$PSScriptRoot/../utils/Unprotect-SecureString.ps1" $PSBoundParameters['AdministratorLoginPassword'] - $PSBoundParameters.Add('AdministratorLoginPassword', $password) - $null = $PSBoundParameters.Remove('AdministratorLoginPassword') - } - if ($PSBoundParameters.ContainsKey('StorageInMb')) { $PSBoundParameters.Add('StorageProfileStorageMb', $PSBoundParameters['StorageInMb']) $null = $PSBoundParameters.Remove('StorageInMb') diff --git a/src/MySql/examples/Test-AzMySqlFlexibleServerConnect.md b/src/MySql/examples/Test-AzMySqlFlexibleServerConnect.md new file mode 100644 index 000000000000..c292735fc27d --- /dev/null +++ b/src/MySql/examples/Test-AzMySqlFlexibleServerConnect.md @@ -0,0 +1,44 @@ +### Example 1: Test connection by name +```powershell +PS C:\> Get-AzMySqlFlexibleServerConnect -ResourceGroupName PowershellMySqlTest -Name mysql-test -AdministratorLoginPassword $password + +The connection testing to mysql-test.database.azure.com was successful! +``` + +Test connection by the resource group and the server name + +### Example 2: Test connection by identity +```powershell +PS C:\> Get-AzMySqlFlexibleServer -ResourceGroupName PowershellMySqlTest -ServerName mysql-test | Get-AzMySqlFlexibleServerConnect -AdministratorLoginPassword $password + +The connection testing to mysql-test.database.azure.com was successful! +``` + +Test connection by the identity + +### Example 3: Test query by name +```powershell +PS C:\> Get-AzMySqlFlexibleServerConnect -ResourceGroupName PowershellMySqlTest -Name mysql-test -AdministratorLoginPassword $password -Query "SELECT * FROM test" + +col +----- +1 +2 +3 +``` + +Test a query by the resource group and the server name + +### Example 4: Test connection by identity +```powershell +PS C:\> Get-AzMySqlFlexibleServer -ResourceGroupName PowershellMySqlTest -ServerName mysql-test | Get-AzMySqlFlexibleServerConnect -Query "SELECT * FROM test" -AdministratorLoginPassword $password + +col +----- +1 +2 +3 +``` + +Test a query by the identity + diff --git a/src/MySql/exports/ProxyCmdletDefinitions.ps1 b/src/MySql/exports/ProxyCmdletDefinitions.ps1 index 1ebe87407ab0..2d5a862b92a8 100644 --- a/src/MySql/exports/ProxyCmdletDefinitions.ps1 +++ b/src/MySql/exports/ProxyCmdletDefinitions.ps1 @@ -6921,6 +6921,211 @@ end { # limitations under the License. # ---------------------------------------------------------------------------------- +<# +.Synopsis +Test out the connection to the database server +.Description +Test out the connection to the database server +.Example +PS C:\> Get-AzMySqlFlexibleServerConnect -ResourceGroupName PowershellMySqlTest -Name mysql-test -AdministratorLoginPassword $password + +The connection testing to mysql-test.database.azure.com was successful! +.Example +PS C:\> Get-AzMySqlFlexibleServer -ResourceGroupName PowershellMySqlTest -ServerName mysql-test | Get-AzMySqlFlexibleServerConnect -AdministratorLoginPassword $password + +The connection testing to mysql-test.database.azure.com was successful! +.Example +PS C:\> Get-AzMySqlFlexibleServerConnect -ResourceGroupName PowershellMySqlTest -Name mysql-test -AdministratorLoginPassword $password -Query "SELECT * FROM test" + +col +----- +1 +2 +3 +.Example +PS C:\> Get-AzMySqlFlexibleServer -ResourceGroupName PowershellMySqlTest -ServerName mysql-test | Get-AzMySqlFlexibleServerConnect -Query "SELECT * FROM test" -AdministratorLoginPassword $password + +col +----- +1 +2 +3 + +.Inputs +Microsoft.Azure.PowerShell.Cmdlets.MySql.Models.IMySqlIdentity +.Outputs +System.String +.Notes +COMPLEX PARAMETER PROPERTIES + +To create the parameters described below, construct a hash table containing the appropriate properties. For information on hash tables, run Get-Help about_Hash_Tables. + +INPUTOBJECT : The server to connect. + [ConfigurationName ]: The name of the server configuration. + [DatabaseName ]: The name of the database. + [FirewallRuleName ]: The name of the server firewall rule. + [Id ]: Resource identity path + [KeyName ]: The name of the server key. + [LocationName ]: The name of the location. + [ResourceGroupName ]: The name of the resource group. The name is case insensitive. + [SecurityAlertPolicyName ]: The name of the security alert policy. + [ServerName ]: The name of the server. + [SubscriptionId ]: The ID of the target subscription. + [VirtualNetworkRuleName ]: The name of the virtual network rule. +.Link +https://docs.microsoft.com/en-us/powershell/module/az.mysql/test-azmysqlflexibleserverconnect +#> +function Test-AzMySqlFlexibleServerConnect { +[OutputType([System.String])] +[CmdletBinding(DefaultParameterSetName='Test', PositionalBinding=$false)] +param( + [Parameter(ParameterSetName='Test', Mandatory)] + [Parameter(ParameterSetName='TestAndQuery', Mandatory)] + [Alias('ServerName')] + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Path')] + [System.String] + # The name of the server to connect. + ${Name}, + + [Parameter(ParameterSetName='Test', Mandatory)] + [Parameter(ParameterSetName='TestAndQuery', Mandatory)] + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Path')] + [System.String] + # The name of the resource group that contains the resource, You can obtain this value from the Azure Resource Manager API or the portal. + ${ResourceGroupName}, + + [Parameter()] + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Path')] + [System.String] + # The database name to connect. + ${DatabaseName}, + + [Parameter(ParameterSetName='TestAndQuery', Mandatory)] + [Parameter(ParameterSetName='TestViaIdentityAndQuery', Mandatory)] + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Path')] + [System.String] + # The query for the database to test + ${QueryText}, + + [Parameter(Mandatory)] + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Body')] + [System.Security.SecureString] + # The password of the administrator. + # Minimum 8 characters and maximum 128 characters. + # Password must contain characters from three of the following categories: English uppercase letters, English lowercase letters, numbers, and non-alphanumeric characters. + ${AdministratorLoginPassword}, + + [Parameter()] + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Body')] + [System.String] + # Administrator username for the server. + # Once set, it cannot be changed. + ${AdministratorUserName}, + + [Parameter(ParameterSetName='TestViaIdentityAndQuery', Mandatory, ValueFromPipeline)] + [Parameter(ParameterSetName='TestViaIdentity', Mandatory, ValueFromPipeline)] + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Body')] + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Models.IMySqlIdentity] + # The server to connect. + # To construct, see NOTES section for INPUTOBJECT properties and create a hash table. + ${InputObject}, + + [Parameter()] + [Alias('AzureRMContext', 'AzureCredential')] + [ValidateNotNull()] + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Azure')] + [System.Management.Automation.PSObject] + # The credentials, account, tenant, and subscription used for communication with Azure. + ${DefaultProfile}, + + [Parameter(DontShow)] + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Runtime')] + [System.Management.Automation.SwitchParameter] + # Wait for .NET debugger to attach. + ${Break}, + + [Parameter(DontShow)] + [ValidateNotNull()] + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Runtime')] + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Runtime.SendAsyncStep[]] + ${HttpPipelineAppend}, + + [Parameter(DontShow)] + [ValidateNotNull()] + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Runtime')] + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Runtime.SendAsyncStep[]] + ${HttpPipelinePrepend}, + + [Parameter(DontShow)] + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Runtime')] + [System.Uri] + ${Proxy}, + + [Parameter(DontShow)] + [ValidateNotNull()] + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Runtime')] + [System.Management.Automation.PSCredential] + ${ProxyCredential}, + + [Parameter(DontShow)] + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Runtime')] + [System.Management.Automation.SwitchParameter] + ${ProxyUseDefaultCredentials} +) + +begin { + try { + $outBuffer = $null + if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) { + $PSBoundParameters['OutBuffer'] = 1 + } + $parameterSet = $PSCmdlet.ParameterSetName + $mapping = @{ + Test = 'Az.MySql.custom\Test-AzMySqlFlexibleServerConnect'; + TestAndQuery = 'Az.MySql.custom\Test-AzMySqlFlexibleServerConnect'; + TestViaIdentityAndQuery = 'Az.MySql.custom\Test-AzMySqlFlexibleServerConnect'; + TestViaIdentity = 'Az.MySql.custom\Test-AzMySqlFlexibleServerConnect'; + } + $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand(($mapping[$parameterSet]), [System.Management.Automation.CommandTypes]::Cmdlet) + $scriptCmd = {& $wrappedCmd @PSBoundParameters} + $steppablePipeline = $scriptCmd.GetSteppablePipeline($MyInvocation.CommandOrigin) + $steppablePipeline.Begin($PSCmdlet) + } catch { + throw + } +} + +process { + try { + $steppablePipeline.Process($_) + } catch { + throw + } +} + +end { + try { + $steppablePipeline.End() + } catch { + throw + } +} +} + +# ---------------------------------------------------------------------------------- +# +# Copyright Microsoft Corporation +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ---------------------------------------------------------------------------------- + <# .Synopsis Updates a configuration of a server. diff --git a/src/MySql/exports/Test-AzMySqlFlexibleServerConnect.ps1 b/src/MySql/exports/Test-AzMySqlFlexibleServerConnect.ps1 new file mode 100644 index 000000000000..4d878d12ca50 --- /dev/null +++ b/src/MySql/exports/Test-AzMySqlFlexibleServerConnect.ps1 @@ -0,0 +1,205 @@ + +# ---------------------------------------------------------------------------------- +# +# Copyright Microsoft Corporation +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ---------------------------------------------------------------------------------- + +<# +.Synopsis +Test out the connection to the database server +.Description +Test out the connection to the database server +.Example +PS C:\> Get-AzMySqlFlexibleServerConnect -ResourceGroupName PowershellMySqlTest -Name mysql-test -AdministratorLoginPassword $password + +The connection testing to mysql-test.database.azure.com was successful! +.Example +PS C:\> Get-AzMySqlFlexibleServer -ResourceGroupName PowershellMySqlTest -ServerName mysql-test | Get-AzMySqlFlexibleServerConnect -AdministratorLoginPassword $password + +The connection testing to mysql-test.database.azure.com was successful! +.Example +PS C:\> Get-AzMySqlFlexibleServerConnect -ResourceGroupName PowershellMySqlTest -Name mysql-test -AdministratorLoginPassword $password -Query "SELECT * FROM test" + +col +----- +1 +2 +3 +.Example +PS C:\> Get-AzMySqlFlexibleServer -ResourceGroupName PowershellMySqlTest -ServerName mysql-test | Get-AzMySqlFlexibleServerConnect -Query "SELECT * FROM test" -AdministratorLoginPassword $password + +col +----- +1 +2 +3 + +.Inputs +Microsoft.Azure.PowerShell.Cmdlets.MySql.Models.IMySqlIdentity +.Outputs +System.String +.Notes +COMPLEX PARAMETER PROPERTIES + +To create the parameters described below, construct a hash table containing the appropriate properties. For information on hash tables, run Get-Help about_Hash_Tables. + +INPUTOBJECT : The server to connect. + [ConfigurationName ]: The name of the server configuration. + [DatabaseName ]: The name of the database. + [FirewallRuleName ]: The name of the server firewall rule. + [Id ]: Resource identity path + [KeyName ]: The name of the server key. + [LocationName ]: The name of the location. + [ResourceGroupName ]: The name of the resource group. The name is case insensitive. + [SecurityAlertPolicyName ]: The name of the security alert policy. + [ServerName ]: The name of the server. + [SubscriptionId ]: The ID of the target subscription. + [VirtualNetworkRuleName ]: The name of the virtual network rule. +.Link +https://docs.microsoft.com/en-us/powershell/module/az.mysql/test-azmysqlflexibleserverconnect +#> +function Test-AzMySqlFlexibleServerConnect { +[OutputType([System.String])] +[CmdletBinding(DefaultParameterSetName='Test', PositionalBinding=$false)] +param( + [Parameter(ParameterSetName='Test', Mandatory)] + [Parameter(ParameterSetName='TestAndQuery', Mandatory)] + [Alias('ServerName')] + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Path')] + [System.String] + # The name of the server to connect. + ${Name}, + + [Parameter(ParameterSetName='Test', Mandatory)] + [Parameter(ParameterSetName='TestAndQuery', Mandatory)] + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Path')] + [System.String] + # The name of the resource group that contains the resource, You can obtain this value from the Azure Resource Manager API or the portal. + ${ResourceGroupName}, + + [Parameter()] + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Path')] + [System.String] + # The database name to connect. + ${DatabaseName}, + + [Parameter(ParameterSetName='TestAndQuery', Mandatory)] + [Parameter(ParameterSetName='TestViaIdentityAndQuery', Mandatory)] + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Path')] + [System.String] + # The query for the database to test + ${QueryText}, + + [Parameter(Mandatory)] + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Body')] + [System.Security.SecureString] + # The password of the administrator. + # Minimum 8 characters and maximum 128 characters. + # Password must contain characters from three of the following categories: English uppercase letters, English lowercase letters, numbers, and non-alphanumeric characters. + ${AdministratorLoginPassword}, + + [Parameter()] + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Body')] + [System.String] + # Administrator username for the server. + # Once set, it cannot be changed. + ${AdministratorUserName}, + + [Parameter(ParameterSetName='TestViaIdentityAndQuery', Mandatory, ValueFromPipeline)] + [Parameter(ParameterSetName='TestViaIdentity', Mandatory, ValueFromPipeline)] + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Body')] + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Models.IMySqlIdentity] + # The server to connect. + # To construct, see NOTES section for INPUTOBJECT properties and create a hash table. + ${InputObject}, + + [Parameter()] + [Alias('AzureRMContext', 'AzureCredential')] + [ValidateNotNull()] + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Azure')] + [System.Management.Automation.PSObject] + # The credentials, account, tenant, and subscription used for communication with Azure. + ${DefaultProfile}, + + [Parameter(DontShow)] + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Runtime')] + [System.Management.Automation.SwitchParameter] + # Wait for .NET debugger to attach. + ${Break}, + + [Parameter(DontShow)] + [ValidateNotNull()] + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Runtime')] + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Runtime.SendAsyncStep[]] + ${HttpPipelineAppend}, + + [Parameter(DontShow)] + [ValidateNotNull()] + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Runtime')] + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Runtime.SendAsyncStep[]] + ${HttpPipelinePrepend}, + + [Parameter(DontShow)] + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Runtime')] + [System.Uri] + ${Proxy}, + + [Parameter(DontShow)] + [ValidateNotNull()] + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Runtime')] + [System.Management.Automation.PSCredential] + ${ProxyCredential}, + + [Parameter(DontShow)] + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Runtime')] + [System.Management.Automation.SwitchParameter] + ${ProxyUseDefaultCredentials} +) + +begin { + try { + $outBuffer = $null + if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) { + $PSBoundParameters['OutBuffer'] = 1 + } + $parameterSet = $PSCmdlet.ParameterSetName + $mapping = @{ + Test = 'Az.MySql.custom\Test-AzMySqlFlexibleServerConnect'; + TestAndQuery = 'Az.MySql.custom\Test-AzMySqlFlexibleServerConnect'; + TestViaIdentityAndQuery = 'Az.MySql.custom\Test-AzMySqlFlexibleServerConnect'; + TestViaIdentity = 'Az.MySql.custom\Test-AzMySqlFlexibleServerConnect'; + } + $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand(($mapping[$parameterSet]), [System.Management.Automation.CommandTypes]::Cmdlet) + $scriptCmd = {& $wrappedCmd @PSBoundParameters} + $steppablePipeline = $scriptCmd.GetSteppablePipeline($MyInvocation.CommandOrigin) + $steppablePipeline.Begin($PSCmdlet) + } catch { + throw + } +} + +process { + try { + $steppablePipeline.Process($_) + } catch { + throw + } +} + +end { + try { + $steppablePipeline.End() + } catch { + throw + } +} +} diff --git a/src/MySql/generate-info.json b/src/MySql/generate-info.json index 4d55e4931d14..7c0af3ac395b 100644 --- a/src/MySql/generate-info.json +++ b/src/MySql/generate-info.json @@ -1,12 +1,8 @@ { - "autorest_remodeler": "2.1.27", - "swagger_commit": "96ba256c1f61d4dc2a7928d7658e024b9b1615a6", - "autorest_core": "3.0.6320", - "microsoft.azure_autorest.csharp": "2.3.82", - "autorest_modelerfour": "4.15.414", + "autorest_powershell": "3.0.414", + "swagger_commit": "c95619ec11a9e817c49fdfe23de4224b990c5a61", "node": "v10.16.0", - "microsoft.azure_autorest.modeler": "2.3.55", - "microsoft.azure_autorest-core": "2.0.4417", - "autorest": "3.0.6187", - "autorest_powershell": "3.0.403" + "autorest_core": "3.0.6365", + "autorest_modelerfour": "4.15.414", + "autorest": "3.0.6187" } diff --git a/src/MySql/help/Az.MySql.md b/src/MySql/help/Az.MySql.md index db26f57c70e7..ddfd39577cf3 100644 --- a/src/MySql/help/Az.MySql.md +++ b/src/MySql/help/Az.MySql.md @@ -110,6 +110,9 @@ Starts a server. ### [Stop-AzMySqlFlexibleServer](Stop-AzMySqlFlexibleServer.md) Stops a server. +### [Test-AzMySqlFlexibleServerConnect](Test-AzMySqlFlexibleServerConnect.md) +Test out the connection to the database server + ### [Update-AzMySqlConfiguration](Update-AzMySqlConfiguration.md) Updates a configuration of a server. Use Update-AzMySqlServer instead if you want update AdministratorLoginPassword, sku, etc. diff --git a/src/MySql/help/Test-AzMySqlFlexibleServerConnect.md b/src/MySql/help/Test-AzMySqlFlexibleServerConnect.md new file mode 100644 index 000000000000..533088ddaf39 --- /dev/null +++ b/src/MySql/help/Test-AzMySqlFlexibleServerConnect.md @@ -0,0 +1,251 @@ +--- +external help file: +Module Name: Az.MySql +online version: https://docs.microsoft.com/en-us/powershell/module/az.mysql/test-azmysqlflexibleserverconnect +schema: 2.0.0 +--- + +# Test-AzMySqlFlexibleServerConnect + +## SYNOPSIS +Test out the connection to the database server + +## SYNTAX + +### Test (Default) +``` +Test-AzMySqlFlexibleServerConnect -Name -ResourceGroupName + -AdministratorLoginPassword [-DatabaseName ] [-AdministratorUserName ] + [-DefaultProfile ] [] +``` + +### TestAndQuery +``` +Test-AzMySqlFlexibleServerConnect -Name -QueryText -ResourceGroupName + -AdministratorLoginPassword [-DatabaseName ] [-AdministratorUserName ] + [-DefaultProfile ] [] +``` + +### TestViaIdentity +``` +Test-AzMySqlFlexibleServerConnect -AdministratorLoginPassword -InputObject + [-DatabaseName ] [-AdministratorUserName ] [-DefaultProfile ] [] +``` + +### TestViaIdentityAndQuery +``` +Test-AzMySqlFlexibleServerConnect -QueryText -AdministratorLoginPassword + -InputObject [-DatabaseName ] [-AdministratorUserName ] + [-DefaultProfile ] [] +``` + +## DESCRIPTION +Test out the connection to the database server + +## EXAMPLES + +### Example 1: Test connection by name +```powershell +PS C:\> Get-AzMySqlFlexibleServerConnect -ResourceGroupName PowershellMySqlTest -Name mysql-test -AdministratorLoginPassword $password + +The connection testing to mysql-test.database.azure.com was successful! +``` + +Test connection by the resource group and the server name + +### Example 2: Test connection by identity +```powershell +PS C:\> Get-AzMySqlFlexibleServer -ResourceGroupName PowershellMySqlTest -ServerName mysql-test | Get-AzMySqlFlexibleServerConnect -AdministratorLoginPassword $password + +The connection testing to mysql-test.database.azure.com was successful! +``` + +Test connection by the identity + +### Example 3: Test query by name +```powershell +PS C:\> Get-AzMySqlFlexibleServerConnect -ResourceGroupName PowershellMySqlTest -Name mysql-test -AdministratorLoginPassword $password -Query "SELECT * FROM test" + +col +----- +1 +2 +3 +``` + +Test a query by the resource group and the server name + +### Example 4: Test connection by identity +```powershell +PS C:\> Get-AzMySqlFlexibleServer -ResourceGroupName PowershellMySqlTest -ServerName mysql-test | Get-AzMySqlFlexibleServerConnect -Query "SELECT * FROM test" -AdministratorLoginPassword $password + +col +----- +1 +2 +3 +``` + +Test a query by the identity + +## PARAMETERS + +### -AdministratorLoginPassword +The password of the administrator. +Minimum 8 characters and maximum 128 characters. +Password must contain characters from three of the following categories: English uppercase letters, English lowercase letters, numbers, and non-alphanumeric characters. + +```yaml +Type: System.Security.SecureString +Parameter Sets: (All) +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -AdministratorUserName +Administrator username for the server. +Once set, it cannot be changed. + +```yaml +Type: System.String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -DatabaseName +The database name to connect. + +```yaml +Type: System.String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -DefaultProfile +The credentials, account, tenant, and subscription used for communication with Azure. + +```yaml +Type: System.Management.Automation.PSObject +Parameter Sets: (All) +Aliases: AzureRMContext, AzureCredential + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -InputObject +The server to connect. +To construct, see NOTES section for INPUTOBJECT properties and create a hash table. + +```yaml +Type: Microsoft.Azure.PowerShell.Cmdlets.MySql.Models.IMySqlIdentity +Parameter Sets: TestViaIdentity, TestViaIdentityAndQuery +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### -Name +The name of the server to connect. + +```yaml +Type: System.String +Parameter Sets: Test, TestAndQuery +Aliases: ServerName + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -QueryText +The query for the database to test + +```yaml +Type: System.String +Parameter Sets: TestAndQuery, TestViaIdentityAndQuery +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ResourceGroupName +The name of the resource group that contains the resource, You can obtain this value from the Azure Resource Manager API or the portal. + +```yaml +Type: System.String +Parameter Sets: Test, TestAndQuery +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### Microsoft.Azure.PowerShell.Cmdlets.MySql.Models.IMySqlIdentity + +## OUTPUTS + +### System.String + +## NOTES + +ALIASES + +COMPLEX PARAMETER PROPERTIES + +To create the parameters described below, construct a hash table containing the appropriate properties. For information on hash tables, run Get-Help about_Hash_Tables. + + +INPUTOBJECT : The server to connect. + - `[ConfigurationName ]`: The name of the server configuration. + - `[DatabaseName ]`: The name of the database. + - `[FirewallRuleName ]`: The name of the server firewall rule. + - `[Id ]`: Resource identity path + - `[KeyName ]`: The name of the server key. + - `[LocationName ]`: The name of the location. + - `[ResourceGroupName ]`: The name of the resource group. The name is case insensitive. + - `[SecurityAlertPolicyName ]`: The name of the security alert policy. + - `[ServerName ]`: The name of the server. + - `[SubscriptionId ]`: The ID of the target subscription. + - `[VirtualNetworkRuleName ]`: The name of the virtual network rule. + +## RELATED LINKS + diff --git a/src/MySql/test/Test-AzMySqlFlexibleServerConnect.Recording.json b/src/MySql/test/Test-AzMySqlFlexibleServerConnect.Recording.json new file mode 100644 index 000000000000..f759906c98ac --- /dev/null +++ b/src/MySql/test/Test-AzMySqlFlexibleServerConnect.Recording.json @@ -0,0 +1,158 @@ +{ + "Get-AzMySqlFlexibleServerConnect+[NoContext]+Get+$GET+https://management.azure.com/subscriptions/7fec3109-5b78-4a24-b834-5d47d63e2596/resourceGroups/MySqlTestGroup/providers/Microsoft.DBForMySql/flexibleServers/mysql-flexible-test-100?api-version=2020-07-01-preview+1": { + "Request": { + "Method": "GET", + "RequestUri": "https://management.azure.com/subscriptions/7fec3109-5b78-4a24-b834-5d47d63e2596/resourceGroups/MySqlTestGroup/providers/Microsoft.DBForMySql/flexibleServers/mysql-flexible-test-100?api-version=2020-07-01-preview", + "Content": null, + "Headers": { + "x-ms-unique-id": [ "1" ], + "x-ms-client-request-id": [ "3986950e-423a-4e89-b933-6e59cb85e464" ], + "CommandName": [ "Az.MySql\\Get-AzMySqlFlexibleServer" ], + "FullCommandName": [ "Get-AzMySqlFlexibleServer_Get" ], + "ParameterSetName": [ "__AllParameterSets" ], + "User-Agent": [ "AzurePowershell/Az4.0.0-preview" ], + "Authorization": [ "[Filtered]" ] + }, + "ContentHeaders": { + } + }, + "Response": { + "StatusCode": 200, + "Headers": { + "Cache-Control": [ "no-cache" ], + "Pragma": [ "no-cache" ], + "X-Content-Type-Options": [ "nosniff" ], + "x-ms-request-id": [ "bc17bc1d-9bfd-40a7-a3d3-d908b0ec8782" ], + "Server": [ "Microsoft-HTTPAPI/2.0" ], + "x-ms-ratelimit-remaining-subscription-reads": [ "11999" ], + "x-ms-correlation-request-id": [ "bfee1d6f-adab-4457-86e0-945a1787b9c9" ], + "x-ms-routing-request-id": [ "WESTUS:20210113T222728Z:bfee1d6f-adab-4457-86e0-945a1787b9c9" ], + "Strict-Transport-Security": [ "max-age=31536000; includeSubDomains" ], + "Date": [ "Wed, 13 Jan 2021 22:27:27 GMT" ] + }, + "ContentHeaders": { + "Content-Length": [ "976" ], + "Content-Type": [ "application/json; charset=utf-8" ], + "Expires": [ "-1" ] + }, + "Content": "{\"sku\":{\"name\":\"Standard_B1ms\",\"tier\":\"Burstable\",\"capacity\":0},\"properties\":{\"administratorLogin\":\"mysqltest\",\"storageProfile\":{\"storageMB\":10240,\"storageIops\":0,\"backupRetentionDays\":7,\"storageAutogrow\":\"Disabled\",\"fileStorageSkuName\":\"Premium_LRS\"},\"version\":\"5.7\",\"state\":\"Ready\",\"haState\":\"NotEnabled\",\"fullyQualifiedDomainName\":\"mysql-flexible-test-100.mysql.database.azure.com\",\"sourceServerId\":\"\",\"publicNetworkAccess\":\"Enabled\",\"sslEnforcement\":\"Disabled\",\"haEnabled\":\"Disabled\",\"earliestRestoreDate\":\"2021-01-13T01:02:10.9821685+00:00\",\"maintenanceWindow\":{\"customWindow\":\"Disabled\",\"dayOfWeek\":0,\"startHour\":0,\"startMinute\":0},\"replicationRole\":\"None\",\"replicaCapacity\":10,\"byokEnforcement\":\"Disabled\"},\"location\":\"East US 2 EUAP\",\"id\":\"/subscriptions/7fec3109-5b78-4a24-b834-5d47d63e2596/resourceGroups/MySqlTestGroup/providers/Microsoft.DBforMySQL/flexibleServers/mysql-flexible-test-100\",\"name\":\"mysql-flexible-test-100\",\"type\":\"Microsoft.DBforMySQL/flexibleServers\"}" + } + }, + "Get-AzMySqlFlexibleServerConnect+[NoContext]+GetViaIdentity+$GET+https://management.azure.com/subscriptions/7fec3109-5b78-4a24-b834-5d47d63e2596/resourceGroups/MySqlTestGroup/providers/Microsoft.DBForMySql/flexibleServers/mysql-flexible-test-100?api-version=2020-07-01-preview+1": { + "Request": { + "Method": "GET", + "RequestUri": "https://management.azure.com/subscriptions/7fec3109-5b78-4a24-b834-5d47d63e2596/resourceGroups/MySqlTestGroup/providers/Microsoft.DBForMySql/flexibleServers/mysql-flexible-test-100?api-version=2020-07-01-preview", + "Content": null, + "Headers": { + "x-ms-unique-id": [ "2" ], + "x-ms-client-request-id": [ "6e337f77-83c0-4791-afe6-59ddaea9cae2" ], + "CommandName": [ "Az.MySql\\Get-AzMySqlFlexibleServer" ], + "FullCommandName": [ "Get-AzMySqlFlexibleServer_GetViaIdentity" ], + "ParameterSetName": [ "__AllParameterSets" ], + "User-Agent": [ "AzurePowershell/Az4.0.0-preview" ], + "Authorization": [ "[Filtered]" ] + }, + "ContentHeaders": { + } + }, + "Response": { + "StatusCode": 200, + "Headers": { + "Cache-Control": [ "no-cache" ], + "Pragma": [ "no-cache" ], + "X-Content-Type-Options": [ "nosniff" ], + "x-ms-request-id": [ "192ed36e-2e58-4f84-b157-8f74a61864fe" ], + "Server": [ "Microsoft-HTTPAPI/2.0" ], + "x-ms-ratelimit-remaining-subscription-reads": [ "11998" ], + "x-ms-correlation-request-id": [ "ee735a9f-5d22-4686-962d-41e207287df4" ], + "x-ms-routing-request-id": [ "WESTUS:20210113T222730Z:ee735a9f-5d22-4686-962d-41e207287df4" ], + "Strict-Transport-Security": [ "max-age=31536000; includeSubDomains" ], + "Date": [ "Wed, 13 Jan 2021 22:27:29 GMT" ] + }, + "ContentHeaders": { + "Content-Length": [ "976" ], + "Content-Type": [ "application/json; charset=utf-8" ], + "Expires": [ "-1" ] + }, + "Content": "{\"sku\":{\"name\":\"Standard_B1ms\",\"tier\":\"Burstable\",\"capacity\":0},\"properties\":{\"administratorLogin\":\"mysqltest\",\"storageProfile\":{\"storageMB\":10240,\"storageIops\":0,\"backupRetentionDays\":7,\"storageAutogrow\":\"Disabled\",\"fileStorageSkuName\":\"Premium_LRS\"},\"version\":\"5.7\",\"state\":\"Ready\",\"haState\":\"NotEnabled\",\"fullyQualifiedDomainName\":\"mysql-flexible-test-100.mysql.database.azure.com\",\"sourceServerId\":\"\",\"publicNetworkAccess\":\"Enabled\",\"sslEnforcement\":\"Disabled\",\"haEnabled\":\"Disabled\",\"earliestRestoreDate\":\"2021-01-13T01:02:10.9821685+00:00\",\"maintenanceWindow\":{\"customWindow\":\"Disabled\",\"dayOfWeek\":0,\"startHour\":0,\"startMinute\":0},\"replicationRole\":\"None\",\"replicaCapacity\":10,\"byokEnforcement\":\"Disabled\"},\"location\":\"East US 2 EUAP\",\"id\":\"/subscriptions/7fec3109-5b78-4a24-b834-5d47d63e2596/resourceGroups/MySqlTestGroup/providers/Microsoft.DBforMySQL/flexibleServers/mysql-flexible-test-100\",\"name\":\"mysql-flexible-test-100\",\"type\":\"Microsoft.DBforMySQL/flexibleServers\"}" + } + }, + "Get-AzMySqlFlexibleServerConnect+[NoContext]+GetAndQuery+$GET+https://management.azure.com/subscriptions/7fec3109-5b78-4a24-b834-5d47d63e2596/resourceGroups/MySqlTestGroup/providers/Microsoft.DBForMySql/flexibleServers/mysql-flexible-test-100?api-version=2020-07-01-preview+1": { + "Request": { + "Method": "GET", + "RequestUri": "https://management.azure.com/subscriptions/7fec3109-5b78-4a24-b834-5d47d63e2596/resourceGroups/MySqlTestGroup/providers/Microsoft.DBForMySql/flexibleServers/mysql-flexible-test-100?api-version=2020-07-01-preview", + "Content": null, + "Headers": { + "x-ms-unique-id": [ "3" ], + "x-ms-client-request-id": [ "5db4119f-ce37-4288-9934-b57b93066d71" ], + "CommandName": [ "Az.MySql\\Get-AzMySqlFlexibleServer" ], + "FullCommandName": [ "Get-AzMySqlFlexibleServer_Get" ], + "ParameterSetName": [ "__AllParameterSets" ], + "User-Agent": [ "AzurePowershell/Az4.0.0-preview" ], + "Authorization": [ "[Filtered]" ] + }, + "ContentHeaders": { + } + }, + "Response": { + "StatusCode": 200, + "Headers": { + "Cache-Control": [ "no-cache" ], + "Pragma": [ "no-cache" ], + "X-Content-Type-Options": [ "nosniff" ], + "x-ms-request-id": [ "2fd2e130-a2fb-4ecc-a4ab-43bd0134c96b" ], + "Server": [ "Microsoft-HTTPAPI/2.0" ], + "x-ms-ratelimit-remaining-subscription-reads": [ "11997" ], + "x-ms-correlation-request-id": [ "db11bc36-5218-43f5-9202-101d361d2fe0" ], + "x-ms-routing-request-id": [ "WESTUS:20210113T222731Z:db11bc36-5218-43f5-9202-101d361d2fe0" ], + "Strict-Transport-Security": [ "max-age=31536000; includeSubDomains" ], + "Date": [ "Wed, 13 Jan 2021 22:27:31 GMT" ] + }, + "ContentHeaders": { + "Content-Length": [ "976" ], + "Content-Type": [ "application/json; charset=utf-8" ], + "Expires": [ "-1" ] + }, + "Content": "{\"sku\":{\"name\":\"Standard_B1ms\",\"tier\":\"Burstable\",\"capacity\":0},\"properties\":{\"administratorLogin\":\"mysqltest\",\"storageProfile\":{\"storageMB\":10240,\"storageIops\":0,\"backupRetentionDays\":7,\"storageAutogrow\":\"Disabled\",\"fileStorageSkuName\":\"Premium_LRS\"},\"version\":\"5.7\",\"state\":\"Ready\",\"haState\":\"NotEnabled\",\"fullyQualifiedDomainName\":\"mysql-flexible-test-100.mysql.database.azure.com\",\"sourceServerId\":\"\",\"publicNetworkAccess\":\"Enabled\",\"sslEnforcement\":\"Disabled\",\"haEnabled\":\"Disabled\",\"earliestRestoreDate\":\"2021-01-13T01:02:10.9821685+00:00\",\"maintenanceWindow\":{\"customWindow\":\"Disabled\",\"dayOfWeek\":0,\"startHour\":0,\"startMinute\":0},\"replicationRole\":\"None\",\"replicaCapacity\":10,\"byokEnforcement\":\"Disabled\"},\"location\":\"East US 2 EUAP\",\"id\":\"/subscriptions/7fec3109-5b78-4a24-b834-5d47d63e2596/resourceGroups/MySqlTestGroup/providers/Microsoft.DBforMySQL/flexibleServers/mysql-flexible-test-100\",\"name\":\"mysql-flexible-test-100\",\"type\":\"Microsoft.DBforMySQL/flexibleServers\"}" + } + }, + "Get-AzMySqlFlexibleServerConnect+[NoContext]+GetViaIdentityAndQuery+$GET+https://management.azure.com/subscriptions/7fec3109-5b78-4a24-b834-5d47d63e2596/resourceGroups/MySqlTestGroup/providers/Microsoft.DBForMySql/flexibleServers/mysql-flexible-test-100?api-version=2020-07-01-preview+1": { + "Request": { + "Method": "GET", + "RequestUri": "https://management.azure.com/subscriptions/7fec3109-5b78-4a24-b834-5d47d63e2596/resourceGroups/MySqlTestGroup/providers/Microsoft.DBForMySql/flexibleServers/mysql-flexible-test-100?api-version=2020-07-01-preview", + "Content": null, + "Headers": { + "x-ms-unique-id": [ "4" ], + "x-ms-client-request-id": [ "dbaae391-ca36-42ab-9e42-5f69df65b55b" ], + "CommandName": [ "Az.MySql\\Get-AzMySqlFlexibleServer" ], + "FullCommandName": [ "Get-AzMySqlFlexibleServer_GetViaIdentity" ], + "ParameterSetName": [ "__AllParameterSets" ], + "User-Agent": [ "AzurePowershell/Az4.0.0-preview" ], + "Authorization": [ "[Filtered]" ] + }, + "ContentHeaders": { + } + }, + "Response": { + "StatusCode": 200, + "Headers": { + "Cache-Control": [ "no-cache" ], + "Pragma": [ "no-cache" ], + "X-Content-Type-Options": [ "nosniff" ], + "x-ms-request-id": [ "1babeabc-6141-4f70-b46f-b2be9a154ecc" ], + "Server": [ "Microsoft-HTTPAPI/2.0" ], + "x-ms-ratelimit-remaining-subscription-reads": [ "11996" ], + "x-ms-correlation-request-id": [ "8316be7c-f2e7-4018-86e7-a6165b0c34d9" ], + "x-ms-routing-request-id": [ "WESTUS:20210113T222733Z:8316be7c-f2e7-4018-86e7-a6165b0c34d9" ], + "Strict-Transport-Security": [ "max-age=31536000; includeSubDomains" ], + "Date": [ "Wed, 13 Jan 2021 22:27:32 GMT" ] + }, + "ContentHeaders": { + "Content-Length": [ "976" ], + "Content-Type": [ "application/json; charset=utf-8" ], + "Expires": [ "-1" ] + }, + "Content": "{\"sku\":{\"name\":\"Standard_B1ms\",\"tier\":\"Burstable\",\"capacity\":0},\"properties\":{\"administratorLogin\":\"mysqltest\",\"storageProfile\":{\"storageMB\":10240,\"storageIops\":0,\"backupRetentionDays\":7,\"storageAutogrow\":\"Disabled\",\"fileStorageSkuName\":\"Premium_LRS\"},\"version\":\"5.7\",\"state\":\"Ready\",\"haState\":\"NotEnabled\",\"fullyQualifiedDomainName\":\"mysql-flexible-test-100.mysql.database.azure.com\",\"sourceServerId\":\"\",\"publicNetworkAccess\":\"Enabled\",\"sslEnforcement\":\"Disabled\",\"haEnabled\":\"Disabled\",\"earliestRestoreDate\":\"2021-01-13T01:02:10.9821685+00:00\",\"maintenanceWindow\":{\"customWindow\":\"Disabled\",\"dayOfWeek\":0,\"startHour\":0,\"startMinute\":0},\"replicationRole\":\"None\",\"replicaCapacity\":10,\"byokEnforcement\":\"Disabled\"},\"location\":\"East US 2 EUAP\",\"id\":\"/subscriptions/7fec3109-5b78-4a24-b834-5d47d63e2596/resourceGroups/MySqlTestGroup/providers/Microsoft.DBforMySQL/flexibleServers/mysql-flexible-test-100\",\"name\":\"mysql-flexible-test-100\",\"type\":\"Microsoft.DBforMySQL/flexibleServers\"}" + } + } +} \ No newline at end of file diff --git a/src/MySql/test/Test-AzMySqlFlexibleServerConnect.Tests.ps1 b/src/MySql/test/Test-AzMySqlFlexibleServerConnect.Tests.ps1 new file mode 100644 index 000000000000..a8429fd2c430 --- /dev/null +++ b/src/MySql/test/Test-AzMySqlFlexibleServerConnect.Tests.ps1 @@ -0,0 +1,46 @@ +$loadEnvPath = Join-Path $PSScriptRoot 'loadEnv.ps1' +if (-Not (Test-Path -Path $loadEnvPath)) { + $loadEnvPath = Join-Path $PSScriptRoot '..\loadEnv.ps1' +} +. ($loadEnvPath) +$TestRecordingFile = Join-Path $PSScriptRoot 'Test-AzMySqlFlexibleServerConnect.Recording.json' +$currentPath = $PSScriptRoot +while(-not $mockingPath) { + $mockingPath = Get-ChildItem -Path $currentPath -Recurse -Include 'HttpPipelineMocking.ps1' -File + $currentPath = Split-Path -Path $currentPath -Parent +} +. ($mockingPath | Select-Object -First 1).FullName + +Describe 'Test-AzMySqlFlexibleServerConnect' { + #[SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine")] + $password = 'Pasword01!!2020' | ConvertTo-SecureString -AsPlainText -Force + + if ($TestMode -eq 'live' -or $TestMode -eq 'record') { + Install-Module -Name SimplySQL -Scope CurrentUser -Force + It 'Test' { + { + Get-AzMySqlFlexibleServerConnect -ResourceGroupName $env.resourceGroup -ServerName $env.flexibleServerName -AdministratorLoginPassword $password + } | Should -Not -Throw + } + + It 'TestViaIdentity' { + { + $ID = "/subscriptions/$($env.SubscriptionId)/resourceGroups/$($env.resourceGroup)/providers/Microsoft.DBForMySql/flexibleServers/$($env.flexibleServerName)" + Get-AzMySqlFlexibleServerConnect -InputObject $ID -AdministratorLoginPassword $password + } | Should -Not -Throw + } + + It 'TestAndQuery' { + { + Get-AzMySqlFlexibleServerConnect -ResourceGroupName $env.resourceGroup -ServerName $env.flexibleServerName -AdministratorLoginPassword $password -Query "CREATE TABLE dbtest (col1 INT)" + } | Should -Not -Throw + } + + It 'TestViaIdentityAndQuery' { + { + $ID = "/subscriptions/$($env.SubscriptionId)/resourceGroups/$($env.resourceGroup)/providers/Microsoft.DBForMySql/flexibleServers/$($env.flexibleServerName)" + Get-AzMySqlFlexibleServerConnect -InputObject $ID -AdministratorLoginPassword $password -Query "CREATE TABLE dbtest2 (col1 INT)" + } | Should -Not -Throw + } + } +}