-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add cmdlet Test-AzMySqlFlexibleServerConnect #14091
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to exit here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DaeunYim could you modify it in the generation branch?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made the change for both mysql and pg