Skip to content

Commit d7c1f88

Browse files
msJinLeiHarveyLink
andauthored
[DBForMySql] Generate MySql (#11519)
* Generate Az.MySql for Azure PowerShell 4.0 * Remove profile * Address cmdlet review comments * Address PR review comments * Add test for MySql - Add test for MySql - Record files for playback mode included * Add template file for VNet deploy Add template file for VNet deploy * Update verify count * Update examles for MySql Update examles for MySql * Compile examples into docs * skip part of test cases Co-authored-by: Harvey Chen <[email protected]>
1 parent 18db5c7 commit d7c1f88

File tree

91 files changed

+17016
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+17016
-0
lines changed
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# ----------------------------------------------------------------------------------
2+
#
3+
# Copyright Microsoft Corporation
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
# ----------------------------------------------------------------------------------
14+
15+
function Get-AzMySqlConnectionString {
16+
[OutputType([System.String])]
17+
[CmdletBinding(DefaultParameterSetName='Get', PositionalBinding=$false)]
18+
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Description('Get the connection string according to client connection provider.')]
19+
param(
20+
[Parameter(ParameterSetName='Get', Mandatory, HelpMessage = 'The name of the server.')]
21+
[Alias('ServerName')]
22+
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Path')]
23+
[System.String]
24+
${Name},
25+
26+
[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.')]
27+
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Path')]
28+
[System.String]
29+
${ResourceGroupName},
30+
31+
[Parameter(ParameterSetName='GetViaIdentity', Mandatory, ValueFromPipeline, HelpMessage = 'The source server object to create replica from.')]
32+
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Body')]
33+
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Models.Api20171201.IServer]
34+
${InputObject},
35+
36+
[Parameter(Mandatory, HelpMessage = 'Client connection provider.')]
37+
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Path')]
38+
[Validateset('ADO.NET', 'JDBC', 'Node.js', 'PHP', 'Python', 'Ruby', 'WebApp')]
39+
[System.String]
40+
${Client},
41+
42+
[Parameter(HelpMessage = 'The credentials, account, tenant, and subscription used for communication with Azure.')]
43+
[Alias('AzureRMContext', 'AzureCredential')]
44+
[ValidateNotNull()]
45+
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Azure')]
46+
[System.Management.Automation.PSObject]
47+
${DefaultProfile},
48+
49+
[Parameter(DontShow, HelpMessage = 'Wait for .NET debugger to attach.')]
50+
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Runtime')]
51+
[System.Management.Automation.SwitchParameter]
52+
${Break},
53+
54+
[Parameter(DontShow)]
55+
[ValidateNotNull()]
56+
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Runtime')]
57+
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Runtime.SendAsyncStep[]]
58+
# SendAsync Pipeline Steps to be appended to the front of the pipeline.
59+
${HttpPipelineAppend},
60+
61+
[Parameter(DontShow)]
62+
[ValidateNotNull()]
63+
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Runtime')]
64+
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Runtime.SendAsyncStep[]]
65+
# SendAsync Pipeline Steps to be prepended to the front of the pipeline.
66+
${HttpPipelinePrepend},
67+
68+
[Parameter(DontShow)]
69+
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Runtime')]
70+
[System.Uri]
71+
# The URI for the proxy server to use.
72+
${Proxy},
73+
74+
[Parameter(DontShow)]
75+
[ValidateNotNull()]
76+
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Runtime')]
77+
[System.Management.Automation.PSCredential]
78+
# Credentials for a proxy server to use for the remote call.
79+
${ProxyCredential},
80+
81+
[Parameter(DontShow)]
82+
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Runtime')]
83+
[System.Management.Automation.SwitchParameter]
84+
# Use the default credentials for the proxy.
85+
${ProxyUseDefaultCredentials}
86+
)
87+
88+
process {
89+
function GetConnectionStringSslPart {
90+
param(
91+
[Parameter()]
92+
[string]
93+
${Client},
94+
[Parameter()]
95+
[string]
96+
${SslEnforcement}
97+
)
98+
$SslEnforcementTemplateMap = @{
99+
'ADO.NET' = 'SslMode=Preferred;'
100+
'JDBC' = '?useSSL=true'
101+
'Node.js' = ', ssl:{ca:fs.readFileSync({ca-cert filename})}'
102+
'PHP' = 'mysqli_ssl_set($con, NULL, NULL, {ca-cert filename}, NULL, NULL);'
103+
'Python' = ', ssl_ca={ca-cert filename}, ssl_verify_cert=true'
104+
'Ruby' = ', sslca:{ca-cert filename}, sslverify:false, sslcipher:"AES256-SHA"'
105+
'WebApp' = ''
106+
}
107+
if ($SslEnforcement -eq 'Enabled') {
108+
return $SslEnforcementTemplateMap[$Client]
109+
}
110+
return ''
111+
}
112+
113+
$clientConnection = $PSBoundParameters['Client']
114+
$null = $PSBoundParameters.Remove('Client')
115+
$mySqlServer = Az.MySql\Get-AzMySqlServer @PSBoundParameters
116+
$DBHost = $mySqlServer.FullyQualifiedDomainName
117+
$DBPort = 3306
118+
$adminName = $mySqlServer.AdministratorLogin
119+
$serverName = $mySqlServer.Name
120+
$SslConnectionString = GetConnectionStringSslPart -Client $clientConnection -SslEnforcement $mySqlServer.SslEnforcement
121+
$ConnectionStringMap = @{
122+
'ADO.NET' = "Server=${DBHost}; Port=${DBPort}; Database={your_database}; Uid=${adminName}@${serverName}; Pwd={your_password}; $SslConnectionString"
123+
'JDBC' = "String url =`"jdbc:mysql://${DBHost}:${DBPort}/{your_database}$SslConnectionString`"; myDbConn = DriverManager.getConnection(url, `"${adminName}@${serverName}`", {your_password});"
124+
'Node.js' = "var conn = mysql.createConnection({host: `"${DBHost}`", user: `"${adminName}@${serverName}`", password: {your_password}, database: {your_database}, port: ${DBPort}$SslConnectionString});"
125+
'PHP' = "`$con=mysqli_init();$SslConnectionString mysqli_real_connect(`$con, `"${DBHost}`", `"${adminName}@${serverName}`", {your_password}, {your_database}, ${DBPort});"
126+
'Python' = "cnx = mysql.connector.connect(user=`"${adminName}@${serverName}`", password={your_password}, host=`"${DBHost}`", port=${DBPort}, database={your_database}$SslConnectionString)"
127+
'Ruby' = "client = Mysql2::Client.new(username: `"${adminName}@${serverName}`", password: {your_password}, database: {your_database}, host: `"${DBHost}`", port: ${DBPort}$SslConnectionString)"
128+
'WebApp' = "Database={your_database}; Data Source=${DBHost}; User Id=${adminName}@${serverName}; Password={your_password}"
129+
}
130+
return $ConnectionStringMap[$Client]
131+
}
132+
}
133+
Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
2+
# ----------------------------------------------------------------------------------
3+
#
4+
# Copyright Microsoft Corporation
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
# ----------------------------------------------------------------------------------
15+
16+
function New-AzMySqlServer {
17+
[OutputType([Microsoft.Azure.PowerShell.Cmdlets.MySql.Models.Api20171201.IServer])]
18+
[CmdletBinding(DefaultParameterSetName='CreateExpanded', PositionalBinding=$false, SupportsShouldProcess, ConfirmImpact='Medium')]
19+
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Description('Creates a new server.')]
20+
param(
21+
[Parameter(Mandatory, HelpMessage = 'The name of the server.')]
22+
[Alias('ServerName')]
23+
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Path')]
24+
[System.String]
25+
${Name},
26+
27+
[Parameter(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.')]
28+
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Path')]
29+
[System.String]
30+
${ResourceGroupName},
31+
32+
[Parameter(HelpMessage='The subscription ID that identifies an Azure subscription.')]
33+
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Path')]
34+
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Runtime.DefaultInfo(Script='(Get-AzContext).Subscription.Id')]
35+
[System.String]
36+
${SubscriptionId},
37+
38+
[Parameter(Mandatory, HelpMessage = 'The location the resource resides in.')]
39+
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Body')]
40+
[System.String]
41+
${Location},
42+
43+
[Parameter(Mandatory, HelpMessage = 'The location the resource resides in.')]
44+
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Body')]
45+
[System.String]
46+
${AdministratorUserName},
47+
48+
[Parameter(Mandatory, HelpMessage = 'The location the resource resides in.')]
49+
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Body')]
50+
[System.Security.SecureString]
51+
[ValidateNotNullOrEmpty()]
52+
${AdministratorLoginPassword},
53+
54+
[Parameter(Mandatory, HelpMessage = 'The name of the sku, typically, tier + family + cores, e.g. B_Gen4_1, GP_Gen5_8.')]
55+
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Body')]
56+
[System.String]
57+
${Sku},
58+
59+
[Parameter(HelpMessage = 'Enable ssl enforcement or not when connect to server.')]
60+
[ArgumentCompleter([Microsoft.Azure.PowerShell.Cmdlets.MySql.Support.SslEnforcementEnum])]
61+
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Body')]
62+
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Support.SslEnforcementEnum]
63+
${SslEnforcement},
64+
65+
[Parameter(HelpMessage = "Backup retention days for the server. Day count is between 7 and 35.")]
66+
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Body')]
67+
[System.Int32]
68+
${BackupRetentionDay},
69+
70+
[Parameter(HelpMessage = 'Enable Geo-redundant or not for server backup.')]
71+
[ArgumentCompleter([Microsoft.Azure.PowerShell.Cmdlets.MySql.Support.GeoRedundantBackup])]
72+
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Body')]
73+
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Support.GeoRedundantBackup]
74+
${GeoRedundantBackup},
75+
76+
[Parameter(HelpMessage = 'Enable Storage Auto Grow.')]
77+
[ArgumentCompleter([Microsoft.Azure.PowerShell.Cmdlets.MySql.Support.StorageAutogrow])]
78+
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Body')]
79+
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Support.StorageAutogrow]
80+
${StorageAutogrow},
81+
82+
[Parameter(HelpMessage = 'Max storage allowed for a server.')]
83+
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Body')]
84+
[System.Int32]
85+
${StorageInMb},
86+
87+
[Parameter(HelpMessage = 'Application-specific metadata in the form of key-value pairs.')]
88+
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Body')]
89+
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Runtime.Info(PossibleTypes=([Microsoft.Azure.PowerShell.Cmdlets.MySql.Models.Api20171201.IServerForCreateTags]))]
90+
[System.Collections.Hashtable]
91+
${Tag},
92+
93+
[Parameter(HelpMessage = 'Server version.')]
94+
[ArgumentCompleter([Microsoft.Azure.PowerShell.Cmdlets.MySql.Support.ServerVersion])]
95+
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Body')]
96+
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Support.ServerVersion]
97+
${Version},
98+
99+
[Parameter(HelpMessage = 'The credentials, account, tenant, and subscription used for communication with Azure.')]
100+
[Alias('AzureRMContext', 'AzureCredential')]
101+
[ValidateNotNull()]
102+
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Azure')]
103+
[System.Management.Automation.PSObject]
104+
${DefaultProfile},
105+
106+
[Parameter(HelpMessage = 'Run the command as a job.')]
107+
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Runtime')]
108+
[System.Management.Automation.SwitchParameter]
109+
${AsJob},
110+
111+
[Parameter(DontShow, HelpMessage = 'Wait for .NET debugger to attach.')]
112+
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Runtime')]
113+
[System.Management.Automation.SwitchParameter]
114+
${Break},
115+
116+
[Parameter(DontShow)]
117+
[ValidateNotNull()]
118+
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Runtime')]
119+
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Runtime.SendAsyncStep[]]
120+
# SendAsync Pipeline Steps to be appended to the front of the pipeline.
121+
${HttpPipelineAppend},
122+
123+
[Parameter(DontShow)]
124+
[ValidateNotNull()]
125+
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Runtime')]
126+
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Runtime.SendAsyncStep[]]
127+
# SendAsync Pipeline Steps to be prepended to the front of the pipeline.
128+
${HttpPipelinePrepend},
129+
130+
[Parameter(HelpMessage = 'Run the command asynchronously.')]
131+
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Runtime')]
132+
[System.Management.Automation.SwitchParameter]
133+
${NoWait},
134+
135+
[Parameter(DontShow)]
136+
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Runtime')]
137+
[System.Uri]
138+
# The URI for the proxy server to use.
139+
${Proxy},
140+
141+
[Parameter(DontShow)]
142+
[ValidateNotNull()]
143+
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Runtime')]
144+
[System.Management.Automation.PSCredential]
145+
# Credentials for a proxy server to use for the remote call.
146+
${ProxyCredential},
147+
148+
[Parameter(DontShow)]
149+
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Runtime')]
150+
[System.Management.Automation.SwitchParameter]
151+
# Use the default credentials for the proxy.
152+
${ProxyUseDefaultCredentials}
153+
)
154+
155+
process {
156+
try {
157+
$Parameter = [Microsoft.Azure.PowerShell.Cmdlets.MySql.Models.Api20171201.ServerForCreate]::new()
158+
$Parameter.Property = [Microsoft.Azure.PowerShell.Cmdlets.MySql.Models.Api20171201.ServerPropertiesForDefaultCreate]::new()
159+
160+
if ($PSBoundParameters.ContainsKey('Location')) {
161+
$Parameter.Location = $PSBoundParameters['Location']
162+
$null = $PSBoundParameters.Remove('Location')
163+
}
164+
165+
if ($PSBoundParameters.ContainsKey('Sku')) {
166+
$Parameter.SkuName = $PSBoundParameters['Sku']
167+
$null = $PSBoundParameters.Remove('Sku')
168+
}
169+
170+
if ($PSBoundParameters.ContainsKey('SslEnforcement')) {
171+
$Parameter.SslEnforcement = $PSBoundParameters['SslEnforcement']
172+
$null = $PSBoundParameters.Remove('SslEnforcement')
173+
}
174+
else
175+
{
176+
$Parameter.SslEnforcement = [Microsoft.Azure.PowerShell.Cmdlets.MySql.Support.SslEnforcementEnum]::Enable
177+
}
178+
179+
if ($PSBoundParameters.ContainsKey('BackupRetentionDay')) {
180+
$Parameter.StorageProfileBackupRetentionDay = $PSBoundParameters['BackupRetentionDay']
181+
$null = $PSBoundParameters.Remove('BackupRetentionDay')
182+
}
183+
184+
if ($PSBoundParameters.ContainsKey('GeoRedundantBackup')) {
185+
$Parameter.StorageProfileGeoRedundantBackup = $PSBoundParameters['GeoRedundantBackup']
186+
$null = $PSBoundParameters.Remove('GeoRedundantBackup')
187+
}
188+
189+
if ($PSBoundParameters.ContainsKey('StorageAutogrow')) {
190+
$Parameter.StorageProfileStorageAutogrow = $PSBoundParameters['StorageAutogrow']
191+
$null = $PSBoundParameters.Remove('StorageAutogrow')
192+
}
193+
194+
if ($PSBoundParameters.ContainsKey('StorageInMb')) {
195+
$Parameter.StorageProfileStorageMb = $PSBoundParameters['StorageInMb']
196+
$null = $PSBoundParameters.Remove('StorageInMb')
197+
}
198+
199+
if ($PSBoundParameters.ContainsKey('Tag')) {
200+
$Parameter.Tag = $PSBoundParameters['Tag']
201+
$null = $PSBoundParameters.Remove('Tag')
202+
}
203+
204+
if ($PSBoundParameters.ContainsKey('Version')) {
205+
$Parameter.Version = $PSBoundParameters['Version']
206+
$null = $PSBoundParameters.Remove('Version')
207+
}
208+
209+
$Parameter.CreateMode = [Microsoft.Azure.PowerShell.Cmdlets.MySql.Support.CreateMode]::Default
210+
211+
$Parameter.Property.AdministratorLogin = $PSBoundParameters['AdministratorUserName']
212+
$null = $PSBoundParameters.Remove('AdministratorUserName')
213+
214+
$Parameter.Property.AdministratorLoginPassword = [System.Runtime.InteropServices.marshal]::PtrToStringAuto([System.Runtime.InteropServices.marshal]::SecureStringToBSTR($PSBoundParameters['AdministratorLoginPassword']))
215+
$null = $PSBoundParameters.Remove('AdministratorLoginPassword')
216+
217+
$PSBoundParameters.Add('Parameter', $Parameter)
218+
Az.MySql.internal\New-AzMySqlServer @PSBoundParameters
219+
} catch {
220+
throw
221+
}
222+
}
223+
}
224+
225+

0 commit comments

Comments
 (0)