-
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
71 changed files
with
20,121 additions
and
1,648 deletions.
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
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] | ||
} | ||
} | ||
|
119 changes: 119 additions & 0 deletions
119
src/MySql/custom/Get-AzMySqlFlexibleServerLocationBasedCapability.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,119 @@ | ||
# ---------------------------------------------------------------------------------- | ||
# | ||
# 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 available SKU information for the location | ||
.Description | ||
Get the available SKU information for the location | ||
#> | ||
|
||
function Get-AzMySqlFlexibleServerLocationBasedCapability { | ||
[OutputType([Microsoft.Azure.PowerShell.Cmdlets.MySql.Models.Api20200701Preview.ICapabilityProperties])] | ||
[CmdletBinding(DefaultParameterSetName='List', PositionalBinding=$false)] | ||
param( | ||
[Parameter(Mandatory)] | ||
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Path')] | ||
[System.String] | ||
# The name of the location. | ||
${Location}, | ||
|
||
[Parameter()] | ||
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Path')] | ||
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Runtime.DefaultInfo(Script='(Get-AzContext).Subscription.Id')] | ||
[System.String[]] | ||
# The ID of the target subscription. | ||
${SubscriptionId}, | ||
|
||
[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[]] | ||
# 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 { | ||
try { | ||
$PSBoundParameters.LocationName = $PSBoundParameters['Location'] | ||
$null = $PSBoundParameters.Remove('Location') | ||
|
||
$Result = Az.MySql.internal\Get-AzMySqlFlexibleServerLocationBasedCapability @PSBoundParameters | ||
Write-Host "Please refer to https://aka.ms/mysql-pricing for pricing details" | ||
$SkusTiers = $Result[0].SupportedFlexibleServerEdition | ||
$TableResult = @() | ||
|
||
ForEach ($Skus in $SkusTiers) { | ||
$TierName = $Skus.Name | ||
Try { | ||
$Keys = $Skus.SupportedServerVersion[0].SupportedVcore | ||
|
||
ForEach ($Key in $Keys) { | ||
$NewEntry = New-Object -TypeName PSCustomObject -Property @{SKU=$Key.Name; Tier=$TierName; vCore=$Key.Vcore; Memory=$Key.SupportedMemoryPerVcoreMb} | ||
$TableResult += $NewEntry | ||
} | ||
} | ||
Catch { | ||
Throw "No SKU info for this location" | ||
} | ||
} | ||
|
||
return $TableResult | ||
|
||
|
||
} catch { | ||
throw | ||
} | ||
} | ||
} |
Oops, something went wrong.