Skip to content

Commit 78f76a9

Browse files
Init for DBForMariaDb (#11508)
Co-authored-by: wyunchi-ms <[email protected]>
1 parent d7c1f88 commit 78f76a9

File tree

94 files changed

+15302
-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.

94 files changed

+15302
-0
lines changed

src/MariaDB/.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
bin
2+
obj
3+
.vs
4+
generated
5+
internal
6+
exports
7+
custom/*.psm1
8+
test/*-TestResults.xml
9+
/*.ps1
10+
/*.ps1xml
11+
/*.psm1
12+
/*.snk
13+
/*.csproj
14+
/*.nuspec
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
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+
function Get-AzMariaDbConnectionString {
16+
[OutputType([System.String])]
17+
[CmdletBinding(DefaultParameterSetName='ServerName', PositionalBinding=$false)]
18+
param(
19+
[Parameter(ParameterSetName='ServerName', Mandatory, HelpMessage='The name of the server.')]
20+
[Alias('ServerName')]
21+
[Microsoft.Azure.PowerShell.Cmdlets.MariaDb.Category('Path')]
22+
[System.String]
23+
# The name of the server.
24+
${Name},
25+
26+
[Parameter(ParameterSetName='ServerName', Mandatory, HelpMessage='The name of the resource group that contains the resource.')]
27+
[Microsoft.Azure.PowerShell.Cmdlets.MariaDb.Category('Path')]
28+
[System.String]
29+
# The name of the resource group that contains the resource.
30+
# You can obtain this value from the Azure Resource Manager API or the portal.
31+
${ResourceGroupName},
32+
33+
[Parameter(ParameterSetName='ServerName', HelpMessage='The subscription ID is part of the URI for every service call')]
34+
[Microsoft.Azure.PowerShell.Cmdlets.MariaDb.Category('Path')]
35+
[Microsoft.Azure.PowerShell.Cmdlets.MariaDb.Runtime.DefaultInfo(Script='(Get-AzContext).Subscription.Id')]
36+
[System.String]
37+
# Gets the subscription Id which uniquely identifies the Microsoft Azure subscription.
38+
# The subscription ID is part of the URI for every service call.
39+
${SubscriptionId},
40+
41+
[Parameter(ParameterSetName='ServerObject', ValueFromPipeline, Mandatory, HelpMessage='Identity Parameter')]
42+
[Microsoft.Azure.PowerShell.Cmdlets.MariaDb.Category('Path')]
43+
[Microsoft.Azure.PowerShell.Cmdlets.MariaDb.Models.Api20180601Preview.IServer]
44+
# Identity Parameter
45+
# To construct, see NOTES section for INPUTOBJECT properties and create a hash table.
46+
${InputObject},
47+
48+
[Parameter(Mandatory, HelpMessage='Connect client type')]
49+
[Microsoft.Azure.PowerShell.Cmdlets.MariaDb.Category('Path')]
50+
[Validateset('ADO.NET', 'JDBC', 'Node.js', 'PHP', 'Python', 'Ruby', 'WebApp')]
51+
[string]
52+
${Client},
53+
54+
#region DefaultParameters
55+
[Parameter()]
56+
[Alias('AzureRMContext', 'AzureCredential')]
57+
[ValidateNotNull()]
58+
[Microsoft.Azure.PowerShell.Cmdlets.MariaDb.Category('Azure')]
59+
[System.Management.Automation.PSObject]
60+
# The credentials, account, tenant, and subscription used for communication with Azure.
61+
${DefaultProfile},
62+
63+
[Parameter(DontShow)]
64+
[Microsoft.Azure.PowerShell.Cmdlets.MariaDb.Category('Runtime')]
65+
[System.Management.Automation.SwitchParameter]
66+
# Wait for .NET debugger to attach
67+
${Break},
68+
69+
[Parameter(DontShow)]
70+
[ValidateNotNull()]
71+
[Microsoft.Azure.PowerShell.Cmdlets.MariaDb.Category('Runtime')]
72+
[Microsoft.Azure.PowerShell.Cmdlets.MariaDb.Runtime.SendAsyncStep[]]
73+
# SendAsync Pipeline Steps to be appended to the front of the pipeline
74+
${HttpPipelineAppend},
75+
76+
[Parameter(DontShow)]
77+
[ValidateNotNull()]
78+
[Microsoft.Azure.PowerShell.Cmdlets.MariaDb.Category('Runtime')]
79+
[Microsoft.Azure.PowerShell.Cmdlets.MariaDb.Runtime.SendAsyncStep[]]
80+
# SendAsync Pipeline Steps to be prepended to the front of the pipeline
81+
${HttpPipelinePrepend},
82+
83+
[Parameter(DontShow)]
84+
[Microsoft.Azure.PowerShell.Cmdlets.MariaDb.Category('Runtime')]
85+
[System.Uri]
86+
# The URI for the proxy server to use
87+
${Proxy},
88+
89+
[Parameter(DontShow)]
90+
[ValidateNotNull()]
91+
[Microsoft.Azure.PowerShell.Cmdlets.MariaDb.Category('Runtime')]
92+
[System.Management.Automation.PSCredential]
93+
# Credentials for a proxy server to use for the remote call
94+
${ProxyCredential},
95+
96+
[Parameter(DontShow)]
97+
[Microsoft.Azure.PowerShell.Cmdlets.MariaDb.Category('Runtime')]
98+
[System.Management.Automation.SwitchParameter]
99+
# Use the default credentials for the proxy
100+
${ProxyUseDefaultCredentials}
101+
#endregion DefaultParameters
102+
)
103+
104+
process {
105+
$null = $PSBoundParameters.Remove('Client')
106+
$MariaDB = Get-AzMariaDbServer @PSBoundParameters
107+
$DBHost = $MariaDB.FullyQualifiedDomainName
108+
$DBPort = 3306
109+
$AdminName = $MariaDB.AdministratorLogin
110+
$MariaDBName = $MariaDB.Name
111+
112+
$SslEnforcementTemplateMap = @{
113+
'ADO.NET' = 'SslMode=Preferred;'
114+
'JDBC' = '?useSSL=true'
115+
'Node.js' = ', ssl:{ca:fs.readFileSync({ca-cert filename})}'
116+
'PHP' = 'mysqli_ssl_set($con, NULL, NULL, {ca-cert filename}, NULL, NULL);'
117+
'Python' = ', ssl_ca={ca-cert filename}, ssl_verify_cert=true'
118+
'Ruby' = ', sslca:{ca-cert filename}, sslverify:false, sslcipher:"AES256-SHA"'
119+
'WebApp' = ''
120+
}
121+
if ($MariaDB.SslEnforcement -eq 'Enabled') {
122+
$SslConnectionString = $SslEnforcementTemplateMap[$Client]
123+
} else {
124+
$SslConnectionString = ''
125+
}
126+
127+
$ConnectionStringMap = @{
128+
'ADO.NET' = "Server=${DBHost}; Port=${DBPort}; Database={your_database}; Uid=${AdminName}@${MariaDBName}; Pwd={your_password}; $SslConnectionString"
129+
'JDBC' = "String url =`"jdbc:mariadb://${DBHost}:${DBPort}/{your_database}$SslConnectionString`"; myDbConn = DriverManager.getConnection(url, `"${AdminName}@${MariaDBName}`", {your_password});"
130+
'Node.js' = "var conn = mysql.createConnection({host: `"${DBHost}`", user: `"${AdminName}@${MariaDBName}`", password: {your_password}, database: {your_database}, port: ${DBPort}$SslConnectionString});"
131+
'PHP' = "`$con=mysqli_init();$SslConnectionString mysqli_real_connect(`$con, `"${DBHost}`", `"${AdminName}@${MariaDBName}`", {your_password}, {your_database}, ${DBPort});"
132+
'Python' = "cnx = mysql.connector.connect(user=`"${AdminName}@${MariaDBName}`", password={your_password}, host=`"${DBHost}`", port=${DBPort}, database={your_database}$SslConnectionString)"
133+
'Ruby' = "client = Mysql2::Client.new(username: `"${AdminName}@${MariaDBName}`", password: {your_password}, database: {your_database}, host: `"${DBHost}`", port: ${DBPort}$SslConnectionString)"
134+
'WebApp' = "Database={your_database}; Data Source=${DBHost}; User Id=${AdminName}@${MariaDBName}; Password={your_password}"
135+
}
136+
return $ConnectionStringMap[$Client]
137+
}
138+
}

0 commit comments

Comments
 (0)