-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
180 changed files
with
19,837 additions
and
4,419 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,28 @@ | ||
namespace Microsoft.Azure.PowerShell.Cmdlets.MySql.Models.Api20200701Preview | ||
{ | ||
using static Microsoft.Azure.PowerShell.Cmdlets.MySql.Runtime.Extensions; | ||
using System.Security; | ||
|
||
/// <summary>Represents a server.</summary> | ||
public partial class ServerAutoGenerated | ||
{ | ||
private SecureString _SecuredPassword; | ||
// <summary> The user password in secure string. Convert the secure string into plain text if necessary. </summary> | ||
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Origin(Microsoft.Azure.PowerShell.Cmdlets.MySql.PropertyOrigin.Inlined)] | ||
[Microsoft.Azure.PowerShell.Cmdlets.MySql.DoNotFormat] | ||
public SecureString SecuredPassword {get => this._SecuredPassword; set => this._SecuredPassword = value;} | ||
|
||
private string _FirewallRuleName; | ||
// <summary> The name of the firewall rule of the server </summary> | ||
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Origin(Microsoft.Azure.PowerShell.Cmdlets.MySql.PropertyOrigin.Inlined)] | ||
[Microsoft.Azure.PowerShell.Cmdlets.MySql.DoNotFormat] | ||
public string FirewallRuleName {get => this._FirewallRuleName; set => this._FirewallRuleName = value;} | ||
|
||
private string _DatabaseName; | ||
// <summary> The name of the default database created for the server </summary> | ||
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Origin(Microsoft.Azure.PowerShell.Cmdlets.MySql.PropertyOrigin.Inlined)] | ||
[Microsoft.Azure.PowerShell.Cmdlets.MySql.DoNotFormat] | ||
public string DatabaseName {get => this._DatabaseName; set => this._DatabaseName = value;} | ||
|
||
} | ||
} |
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
144 changes: 144 additions & 0 deletions
144
src/MySql/custom/Get-AzMySqlFlexibleServerConnectionString.ps1
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,144 @@ | ||
# ---------------------------------------------------------------------------------- | ||
# | ||
# 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 | ||
Get the connection string according to client connection provider. | ||
.Description | ||
Get the connection string according to client connection provider. | ||
#> | ||
|
||
function Get-AzMySqlFlexibleServerConnectionString { | ||
[OutputType([System.String])] | ||
[CmdletBinding(DefaultParameterSetName='Get', PositionalBinding=$false)] | ||
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Description('Get the connection string according to client connection provider.')] | ||
param( | ||
[Parameter(ParameterSetName='Get', Mandatory, HelpMessage = 'The name of the server.')] | ||
[Alias('ServerName')] | ||
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Path')] | ||
[System.String] | ||
${Name}, | ||
|
||
[Parameter(ParameterSetName='Get', 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(ParameterSetName='Get', HelpMessage='The subscription ID that identifies an Azure subscription.')] | ||
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Path')] | ||
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Runtime.DefaultInfo(Script='(Get-AzContext).Subscription.Id')] | ||
[System.String] | ||
${SubscriptionId}, | ||
|
||
[Parameter(Mandatory, HelpMessage = 'Client connection provider.')] | ||
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Path')] | ||
[Validateset('ADO.NET', 'JDBC', 'Node.js', 'PHP', 'Python', 'Ruby', 'WebApp')] | ||
[System.String] | ||
${Client}, | ||
|
||
[Parameter(ParameterSetName='GetViaIdentity', Mandatory, ValueFromPipeline, HelpMessage = 'Name of the server')] | ||
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Body')] | ||
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Models.IMySqlIdentity] | ||
${InputObject}, | ||
|
||
[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 { | ||
function GetConnectionStringSslPart { | ||
param( | ||
[Parameter()] | ||
[string] | ||
${Client}, | ||
[Parameter()] | ||
[string] | ||
${SslEnforcement} | ||
) | ||
$SslEnforcementTemplateMap = @{ | ||
'ADO.NET' = 'SslMode=MySqlSslMode.Required;SslCa="{ca-cert filename}"' | ||
'JDBC' = '?useSSL=true' | ||
'Node.js' = ', ssl:{ca:fs.readFileSync({ca-cert filename})}' | ||
'PHP' = 'mysqli_ssl_set($con, NULL, NULL, {ca-cert filename}, NULL, NULL);' | ||
'Python' = ', ssl_ca={ca-cert filename}, ssl_verify_cert=true' | ||
'Ruby' = ', sslca:{ca-cert filename}, sslverify:false, sslcipher:"AES256-SHA"' | ||
'WebApp' = '' | ||
} | ||
if ($SslEnforcement -eq 'Enabled') { | ||
return $SslEnforcementTemplateMap[$Client] | ||
} | ||
return '' | ||
} | ||
|
||
$clientConnection = $PSBoundParameters['Client'] | ||
$null = $PSBoundParameters.Remove('Client') | ||
$mySqlServer = Az.MySql\Get-AzMySqlFlexibleServer @PSBoundParameters | ||
$DBHost = $mySqlServer.FullyQualifiedDomainName | ||
$DBPort = 3306 | ||
$adminName = $mySqlServer.AdministratorLogin | ||
$SslConnectionString = GetConnectionStringSslPart -Client $clientConnection -SslEnforcement $mySqlServer.SslEnforcement | ||
$ConnectionStringMap = @{ | ||
'ADO.NET' = "Server=${DBHost}; Port=${DBPort}; Database={your_database}; UserID=${adminName}; Password={your_password}; $SslConnectionString" | ||
'JDBC' = "String url =`"jdbc:mysql://${DBHost}:${DBPort}/{your_database}$SslConnectionString`"; myDbConn = DriverManager.getConnection(url, `"${adminName}`", {your_password});" | ||
'Node.js' = "var conn = mysql.createConnection({host: `"${DBHost}`", user: `"${adminName}`", password: {your_password}, database: {your_database}, port: ${DBPort}$SslConnectionString});" | ||
'PHP' = "`$con=mysqli_init();$SslConnectionString mysqli_real_connect(`$con, `"${DBHost}`", `"${adminName}`", {your_password}, {your_database}, ${DBPort});" | ||
'Python' = "cnx = mysql.connector.connect(user=`"${adminName}`", password={your_password}, host=`"${DBHost}`", port=${DBPort}, database={your_database}$SslConnectionString)" | ||
'Ruby' = "client = Mysql2::Client.new(username: `"${adminName}`", password: {your_password}, database: {your_database}, host: `"${DBHost}`", port: ${DBPort}$SslConnectionString)" | ||
} | ||
return $ConnectionStringMap[$Client] | ||
} | ||
} | ||
|
Oops, something went wrong.