Skip to content

Commit 50312c1

Browse files
author
Jianghao Lu
committed
Merge pull request #847 from OJDUDE/release-0.9.8
SQL VM AKV Integration in Azure SDK Release 0.9.8
2 parents ab992a1 + 8e8ab7a commit 50312c1

14 files changed

+1245
-513
lines changed

src/ServiceManagement/Compute/Commands.ServiceManagement/Commands.ServiceManagement.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,11 @@
171171
<Reference Include="System.Xml" />
172172
</ItemGroup>
173173
<ItemGroup>
174+
<Compile Include="IaaS\Extensions\SqlServer\AzureVMSqlServerPublicAutoBackupSettings.cs" />
175+
<Compile Include="IaaS\Extensions\SqlServer\AzureVMSqlServerPublicKeyVaultCredentialSettings.cs" />
176+
<Compile Include="IaaS\Extensions\SqlServer\AzureVMSqlServerPrivateKeyVaultCredentialSettings.cs" />
177+
<Compile Include="IaaS\Extensions\SqlServer\AzureVMSqlServerKeyVaultCredentialSettings.cs" />
178+
<Compile Include="IaaS\Extensions\SqlServer\NewAzureVMSqlServerKeyVaultCredentialConfig.cs" />
174179
<Compile Include="IaaS\Extensions\DSC\DscExtensionCmdletConstants.cs" />
175180
<Compile Include="IaaS\Extensions\DSC\DscExtensionPrivateSettings.cs" />
176181
<Compile Include="IaaS\Extensions\DSC\DscExtensionPublicSettings.cs" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
using System.Security;
16+
17+
namespace Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.Extensions
18+
{
19+
/// <summary>
20+
/// Autobackup settings to configure managed backup on SQL VM
21+
/// </summary>
22+
public class KeyVaultCredentialSettings
23+
{
24+
/// <summary>
25+
/// Defines if the Key Vault Credentails feature is enabled or disabled
26+
/// </summary>
27+
public bool Enable { get; set; }
28+
29+
/// <summary>
30+
/// Key Vault credentails name
31+
/// </summary>
32+
public string CredentialName { get; set; }
33+
34+
/// <summary>
35+
/// Gets the azure key vault URL.
36+
/// </summary>
37+
/// <value>
38+
/// The azure key vault URL for Credential Management.
39+
/// </value>
40+
public string AzureKeyVaultUrl { get; set; }
41+
42+
/// <summary>
43+
/// Gets the name of the principal.
44+
/// </summary>
45+
/// <value>
46+
/// The name of the service principal to access the Azure Key Vault.
47+
/// </value>
48+
public string ServicePrincipalName { get; set; }
49+
50+
/// <summary>
51+
/// Gets the principal secret.
52+
/// </summary>
53+
/// <value>
54+
/// The service principal secret to access the Azure Key Vault.
55+
/// </value>
56+
public string ServicePrincipalSecret { get; set; }
57+
}
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
using System.Security;
16+
17+
namespace Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.Extensions
18+
{
19+
/// <summary>
20+
/// Autobackup settings to configure managed backup on SQL VM
21+
/// </summary>
22+
public class PrivateKeyVaultCredentialSettings
23+
{
24+
/// <summary>
25+
/// Gets the azure key vault URL.
26+
/// </summary>
27+
/// <value>
28+
/// The azure key vault URL for Credential Management.
29+
/// </value>
30+
public string AzureKeyVaultUrl { get; set; }
31+
32+
/// <summary>
33+
/// Gets the name of the principal.
34+
/// </summary>
35+
/// <value>
36+
/// The name of the service principal to access the Azure Key Vault.
37+
/// </value>
38+
public string ServicePrincipalName { get; set; }
39+
40+
/// <summary>
41+
/// Gets the principal secret.
42+
/// </summary>
43+
/// <value>
44+
/// The service principal secret to access the Azure Key Vault.
45+
/// </value>
46+
public string ServicePrincipalSecret { get; set; }
47+
}
48+
}

src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Extensions/SqlServer/AzureVMSqlServerPrivateSettings.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,11 @@ public class SqlServerPrivateSettings
3434
/// Password required for certification when encryption is enabled
3535
/// </summary>
3636
public string Password;
37+
38+
/// <summary>
39+
/// Azure Key Vault Credential settings
40+
/// </summary>
41+
public PrivateKeyVaultCredentialSettings PrivateKeyVaultCredentialSettings;
42+
3743
}
3844
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
using System.Security;
16+
17+
namespace Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.Extensions
18+
{
19+
/// <summary>
20+
/// Autobackup public settings to configure managed backup on SQL VM
21+
/// </summary>
22+
public class PublicAutoBackupSettings
23+
{
24+
/// <summary>
25+
/// Defines if the Auto-backup feature is enabled or disabled
26+
/// </summary>
27+
public bool Enable { get; set; }
28+
29+
/// <summary>
30+
/// Defines if backups will be encrypted or not
31+
/// </summary>
32+
public bool EnableEncryption { get; set; }
33+
34+
/// <summary>
35+
/// Defines the number of days to keep the backups
36+
/// </summary>
37+
public int RetentionPeriod { get; set; }
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
using System.Security;
16+
17+
namespace Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.Extensions
18+
{
19+
/// <summary>
20+
/// Key Vault public settings to manage SQL VM credentials on configure Azure Key Vault
21+
/// </summary>
22+
public class PublicKeyVaultCredentialSettings
23+
{
24+
/// <summary>
25+
/// Defines if the Key Vault Credentails feature is enabled or disabled
26+
/// </summary>
27+
public bool Enable { get; set; }
28+
29+
/// <summary>
30+
/// Key Vault credentails name
31+
/// </summary>
32+
public string CredentialName { get; set; }
33+
}
34+
}

src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Extensions/SqlServer/AzureVMSqlServerPublicSettings.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,16 @@ public class SqlServerPublicSettings
2727
/// <summary>
2828
/// Auto-backup settings
2929
/// </summary>
30-
public AutoBackupSettings AutoBackupSettings { get; set; }
30+
public PublicAutoBackupSettings AutoBackupSettings { get; set; }
3131

3232
/// <summary>
3333
/// Auto-telemetry settings
3434
/// </summary>
3535
public AutoTelemetrySettings AutoTelemetrySettings { get; set; }
36+
37+
/// <summary>
38+
/// Azure Key Vault SQL Credentials settings
39+
/// </summary>
40+
public PublicKeyVaultCredentialSettings KeyVaultCredentialSettings { get; set; }
3641
}
3742
}

src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Extensions/SqlServer/GetAzureVMSqlServerExtension.cs

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public class GetAzureVMSqlServerExtensionCommand : VirtualMachineSqlServerExtens
4242
protected const string GetSqlServerExtensionParamSetName = "GetSqlServerExtension";
4343
protected const string AutoPatchingStatusMessageName = "Automated Patching";
4444
protected const string AutoBackupStatusMessageName = "Automated Backup";
45+
protected const string KeyVaultCredentialStatusMessageName = "Key Vault Credential";
4546

4647
internal void ExecuteCommand()
4748
{
@@ -59,7 +60,7 @@ internal void ExecuteCommand()
5960
protected override void ProcessRecord()
6061
{
6162
base.ProcessRecord();
62-
ExecuteCommand();
63+
this.ExecuteCommand();
6364
}
6465

6566
/// <summary>
@@ -68,7 +69,7 @@ protected override void ProcessRecord()
6869
/// <returns></returns>
6970
private VirtualMachineSqlServerExtensionContext GetExtensionContext(ResourceExtensionReference r)
7071
{
71-
string extensionName= VirtualMachineSqlServerExtensionCmdletBase.ExtensionPublishedNamespace + "."
72+
string extensionName = VirtualMachineSqlServerExtensionCmdletBase.ExtensionPublishedNamespace + "."
7273
+ VirtualMachineSqlServerExtensionCmdletBase.ExtensionPublishedName;
7374

7475
VirtualMachineSqlServerExtensionContext context = new VirtualMachineSqlServerExtensionContext
@@ -116,11 +117,14 @@ private VirtualMachineSqlServerExtensionContext GetExtensionContext(ResourceExte
116117
{
117118
context.AutoPatchingSettings = DeSerializeAutoPatchingSettings(status.Name, formattedMessage);
118119
}
119-
120-
if (status.Name.Equals(AutoBackupStatusMessageName, System.StringComparison.InvariantCulture))
120+
else if (status.Name.Equals(AutoBackupStatusMessageName, System.StringComparison.InvariantCulture))
121121
{
122122
context.AutoBackupSettings = DeSerializeAutoBackupSettings(status.Name, formattedMessage);
123123
}
124+
else if (status.Name.Equals(KeyVaultCredentialStatusMessageName, System.StringComparison.InvariantCulture))
125+
{
126+
context.KeyVaultCredentialSettings = DeSerializeKeyVaultCredentialSettings(status.Name, formattedMessage);
127+
}
124128

125129
statusMessageList.Add(formattedMessage);
126130
}
@@ -158,7 +162,7 @@ private VirtualMachineSqlServerExtensionContext GetExtensionContext(ResourceExte
158162
NSM.DeploymentSlot.Production);
159163
}
160164
catch (CloudException e)
161-
{
165+
{
162166
if (e.Response.StatusCode != HttpStatusCode.NotFound)
163167
{
164168
throw;
@@ -212,13 +216,62 @@ private AutoPatchingSettings DeSerializeAutoPatchingSettings(string category, st
212216

213217
private AutoBackupSettings DeSerializeAutoBackupSettings(string category, string input)
214218
{
215-
AutoBackupSettings abs = new AutoBackupSettings();
219+
AutoBackupSettings autoBackupSettings = new AutoBackupSettings();
216220

217221
if (!string.IsNullOrEmpty(input))
218222
{
219223
try
220224
{
221-
abs = JsonConvert.DeserializeObject<AutoBackupSettings>(input);
225+
PublicAutoBackupSettings publicAutoBackupSettings = JsonConvert.DeserializeObject<PublicAutoBackupSettings>(input);
226+
227+
if(publicAutoBackupSettings != null)
228+
{
229+
autoBackupSettings.Enable = publicAutoBackupSettings.Enable;
230+
autoBackupSettings.EnableEncryption = publicAutoBackupSettings.EnableEncryption;
231+
autoBackupSettings.RetentionPeriod = publicAutoBackupSettings.RetentionPeriod;
232+
autoBackupSettings.StorageAccessKey = "***";
233+
autoBackupSettings.StorageUrl = "***";
234+
235+
if (autoBackupSettings.EnableEncryption)
236+
{
237+
autoBackupSettings.Password = "***";
238+
}
239+
}
240+
}
241+
catch (JsonReaderException jre)
242+
{
243+
WriteVerboseWithTimestamp("Category:" + category);
244+
WriteVerboseWithTimestamp("Message:" + input);
245+
WriteVerboseWithTimestamp(jre.ToString());
246+
}
247+
}
248+
249+
return autoBackupSettings;
250+
}
251+
252+
private KeyVaultCredentialSettings DeSerializeKeyVaultCredentialSettings(string category, string input)
253+
{
254+
KeyVaultCredentialSettings kvtSettings = new KeyVaultCredentialSettings();
255+
256+
if (!string.IsNullOrEmpty(input))
257+
{
258+
try
259+
{
260+
// we only print the public settings
261+
PublicKeyVaultCredentialSettings publicSettings = JsonConvert.DeserializeObject<PublicKeyVaultCredentialSettings>(input);
262+
263+
if (publicSettings != null)
264+
{
265+
kvtSettings.CredentialName = publicSettings.CredentialName;
266+
kvtSettings.Enable = publicSettings.Enable;
267+
268+
if (kvtSettings.Enable)
269+
{
270+
kvtSettings.ServicePrincipalName = "***";
271+
kvtSettings.ServicePrincipalSecret = "***";
272+
kvtSettings.AzureKeyVaultUrl = "***";
273+
}
274+
}
222275
}
223276
catch (JsonReaderException jre)
224277
{
@@ -228,7 +281,7 @@ private AutoBackupSettings DeSerializeAutoBackupSettings(string category, string
228281
}
229282
}
230283

231-
return abs;
284+
return kvtSettings;
232285
}
233286

234287
/// <summary>

0 commit comments

Comments
 (0)