Skip to content

Commit

Permalink
MySql flexibler server enhancement
Browse files Browse the repository at this point in the history
  • Loading branch information
msJinLei committed Dec 22, 2020
1 parent 4cbc080 commit baff4e7
Show file tree
Hide file tree
Showing 71 changed files with 20,121 additions and 1,648 deletions.
12 changes: 7 additions & 5 deletions src/MySql/Az.MySql.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# Generated by: Microsoft Corporation
#
# Generated on: 12/3/2020
# Generated on: 12/22/2020
#

@{
Expand All @@ -12,7 +12,7 @@
RootModule = './Az.MySql.psm1'

# Version number of this module.
ModuleVersion = '0.3.1'
ModuleVersion = '0.1.0'

# Supported PSEditions
CompatiblePSEditions = 'Core', 'Desktop'
Expand Down Expand Up @@ -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 = ''
Expand All @@ -63,7 +63,7 @@ RequiredAssemblies = './bin/Az.MySql.private.dll'
# TypesToProcess = @()

# Format files (.ps1xml) to be loaded when importing this module
FormatsToProcess = 'Az.MySql.format.ps1xml'
FormatsToProcess = './Az.MySql.format.ps1xml'

# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
# NestedModules = @()
Expand All @@ -72,8 +72,10 @@ FormatsToProcess = 'Az.MySql.format.ps1xml'
FunctionsToExport = 'Get-AzMySqlConfiguration', 'Get-AzMySqlConnectionString',
'Get-AzMySqlFirewallRule', 'Get-AzMySqlFlexibleServer',
'Get-AzMySqlFlexibleServerConfiguration',
'Get-AzMySqlFlexibleServerConnectionString',
'Get-AzMySqlFlexibleServerDatabase',
'Get-AzMySqlFlexibleServerFirewallRule',
'Get-AzMySqlFlexibleServerLocationBasedCapability',
'Get-AzMySqlFlexibleServerReplica', 'Get-AzMySqlReplica',
'Get-AzMySqlServer', 'Get-AzMySqlVirtualNetworkRule',
'New-AzMySqlFirewallRule', 'New-AzMySqlFlexibleServer',
Expand Down Expand Up @@ -130,7 +132,7 @@ PrivateData = @{
# IconUri = ''

# ReleaseNotes of this module
ReleaseNotes = '* Fixed secure string issue'
# ReleaseNotes = ''

# Prerelease string of this module
# Prerelease = ''
Expand Down
2 changes: 1 addition & 1 deletion src/MySql/build-module.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ $null = New-Item -ItemType Directory -Force -Path $examplesFolder

if($NoDocs) {
Write-Host -ForegroundColor Green 'Creating exports...'
Export-ProxyCmdlet -ModuleName $moduleName -ModulePath $modulePaths -ExportsFolder $exportsFolder -InternalFolder $internalFolder -ExcludeDocs
Export-ProxyCmdlet -ModuleName $moduleName -ModulePath $modulePaths -ExportsFolder $exportsFolder -InternalFolder $internalFolder -ExcludeDocs -ExamplesFolder $examplesFolder
} else {
Write-Host -ForegroundColor Green 'Creating exports and docs...'
$moduleDescription = 'Microsoft Azure PowerShell: MySql cmdlets'
Expand Down
2 changes: 1 addition & 1 deletion src/MySql/custom/Get-AzMySqlConnectionString.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function Get-AzMySqlConnectionString {
[System.String]
${SubscriptionId},

[Parameter(ParameterSetName='GetViaIdentity', Mandatory, ValueFromPipeline, HelpMessage = 'The source server object to create replica from.')]
[Parameter(ParameterSetName='GetViaIdentity', Mandatory, ValueFromPipeline, HelpMessage = 'Name of the server')]
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Body')]
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Models.Api20171201.IServer]
${InputObject},
Expand Down
144 changes: 144 additions & 0 deletions src/MySql/custom/Get-AzMySqlFlexibleServerConnectionString.ps1
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 src/MySql/custom/Get-AzMySqlFlexibleServerLocationBasedCapability.ps1
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
}
}
}
Loading

0 comments on commit baff4e7

Please sign in to comment.