Skip to content

Commit 95ea3ec

Browse files
author
Anil Kumar Yelam
committed
Changed Get-Extension response to get values from SQL config, not public settings in response. Fixed tests.
1 parent 167dca3 commit 95ea3ec

File tree

10 files changed

+249
-23
lines changed

10 files changed

+249
-23
lines changed

src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/SqlIaaSExtensionTests.ps1

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ function Test-SetAzureRmVMSqlServerAKVExtension
8989

9090
# 3) Verifies settings are correct given input
9191

92-
Assert-AreEqual $extension.KeyVaultCredentialSettings.CredentialName "CredentialTesting";
92+
Assert-AreEqual $extension.KeyVaultCredentialSettings.Credentials.Count 1;
93+
Assert-AreEqual $extension.KeyVaultCredentialSettings.Credentials[0].CredentialName "CredentialTesting"
9394

9495
# 4) Update extension values
9596

@@ -98,8 +99,9 @@ function Test-SetAzureRmVMSqlServerAKVExtension
9899

99100
# 5) Verify changes
100101
$extension = Get-AzureRmVMSqlServerExtension -ResourceGroupName $rgname -VmName $vmName -Name $extensionName;
101-
102-
Assert-AreEqual $extension.KeyVaultCredentialSettings.CredentialName "CredentialTest"
102+
103+
Assert-AreEqual $extension.KeyVaultCredentialSettings.Credentials.Count 2;
104+
Assert-AreEqual $extension.KeyVaultCredentialSettings.Credentials[1].CredentialName "CredentialTest"
103105

104106
# 6) Test with correct Name and Version
105107

src/ResourceManager/Compute/Commands.Compute.Test/SessionRecords/Microsoft.Azure.Commands.Compute.Test.ScenarioTests.SqlIaaSExtensionTests/TestSqlIaaSExtensionWith2016Image.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/ResourceManager/Compute/Commands.Compute/Commands.Compute.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,14 +271,16 @@
271271
<Compile Include="Extension\SqlServer\AzureVMSqlServerAutoBackupSettings.cs" />
272272
<Compile Include="Extension\SqlServer\AzureVMSqlServerAutoPatchingSettings.cs" />
273273
<Compile Include="Extension\SqlServer\AzureVMSqlServerAutoTelemetrySettings.cs" />
274+
<Compile Include="Extension\SqlServer\AzureVMSqlServerConfiguration.cs" />
275+
<Compile Include="Extension\SqlServer\AzureVMSqlServerKeyVaultCredential.cs" />
274276
<Compile Include="Extension\SqlServer\NewAzureRmVMSqlServerAutoBackupConfig.cs" />
275277
<Compile Include="Extension\SqlServer\NewAzureRmVMSqlServerAutoPatchingConfig.cs" />
276278
<Compile Include="Extension\SqlServer\NewAzureRmVMSqlServerKeyVaultCredentialConfig.cs" />
277279
<Compile Include="Extension\SqlServer\PrivateKeyVaultCredentialSettings.cs" />
278280
<Compile Include="Extension\SqlServer\AzureVMSqlServerPrivateSettings.cs" />
279281
<Compile Include="Extension\SqlServer\AzureVMSqlServerPublicSettings.cs" />
280282
<Compile Include="Extension\SqlServer\GetAzureVMSqlServerExtensionCommand.cs" />
281-
<Compile Include="Extension\SqlServer\KeyVaultCredentialSettings.cs" />
283+
<Compile Include="Extension\SqlServer\AzureVMSqlServerKeyVaultCredentialSettings.cs" />
282284
<Compile Include="Extension\SqlServer\NewAzureVMSqlServerAutoBackupConfig.cs" />
283285
<Compile Include="Extension\SqlServer\NewAzureVMSqlServerAutoPatchingConfig.cs" />
284286
<Compile Include="Extension\SqlServer\NewAzureVMSqlServerKeyVaultCredentialConfig.cs" />
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
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.Collections.Generic;
16+
17+
namespace Microsoft.Azure.Commands.Compute
18+
{
19+
/// <summary>
20+
/// SQL Server Configuration object that is returned by extension as a substatus.
21+
/// </summary>
22+
public class AzureVMSqlServerConfiguration
23+
{
24+
/// <summary>
25+
/// Auto Patching report object
26+
/// </summary>
27+
public class AutoPatchingReport
28+
{
29+
public string Name { get; set; }
30+
public int Status { get; set; }
31+
public bool Enable { get; set; }
32+
public string DayOfWeek { get; set; }
33+
public int MaintenanceWindowStartingHour { get; set; }
34+
public int MaintenanceWindowDuration { get; set; }
35+
public string PatchCategory { get; set; }
36+
}
37+
38+
/// <summary>
39+
/// Auto Backup report object
40+
/// </summary>
41+
public class AutoBackupReport
42+
{
43+
public string Name { get; set; }
44+
public int Status { get; set; }
45+
public bool Enable { get; set; }
46+
public bool EnableEncryption { get; set; }
47+
public string StorageAccountUrl { get; set; }
48+
public int RetentionPeriod { get; set; }
49+
public string BackupScheduleType { get; set; }
50+
public bool? BackupSystemDbs { get; set; }
51+
public string FullBackupFrequency { get; set; }
52+
public int? FullBackupStartTime { get; set; }
53+
public int? FullBackupWindowHours { get; set; }
54+
public int? LogBackupFrequency { get; set; }
55+
}
56+
57+
/// <summary>
58+
/// Azure Key Vault report object
59+
/// </summary>
60+
public class AzureKeyVaultReport
61+
{
62+
public string Name { get; set; }
63+
public int Status { get; set; }
64+
public bool Enable { get; set; }
65+
public bool EnableEncryption { get; set; }
66+
public List<AzureVMSqlServerKeyVaultCredential> CredentialsList { get; set; }
67+
}
68+
69+
/// <summary>
70+
/// Auto telemetry report object
71+
/// </summary>
72+
public class AutoTelemetrySettingsReport
73+
{
74+
public string Name { get; set; }
75+
public int Status { get; set; }
76+
public string Location { get; set; }
77+
public string PerformanceCollectorStatus { get; set; }
78+
}
79+
80+
/// <summary>
81+
/// Auto patching settings
82+
/// </summary>
83+
public AutoPatchingReport AutoPatching { get; set; }
84+
85+
/// <summary>
86+
/// Auto-backup settings
87+
/// </summary>
88+
public AutoBackupReport AutoBackup { get; set; }
89+
90+
/// <summary>
91+
/// AkV settings
92+
/// </summary>
93+
public AzureKeyVaultReport AzureKeyVault { get; set; }
94+
95+
/// <summary>
96+
/// Auto-telemetry settings
97+
/// </summary>
98+
public AutoTelemetrySettingsReport AutoTelemetryReport { get; set; }
99+
}
100+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
namespace Microsoft.Azure.Commands.Compute
16+
{
17+
/// <summary>
18+
/// AKV Credential
19+
/// </summary>
20+
public class AzureVMSqlServerKeyVaultCredential
21+
{
22+
/// <summary>
23+
/// Name of the credential
24+
/// </summary>
25+
public string CredentialName { get; set; }
26+
27+
/// <summary>
28+
/// Key vault that this credential provides access to.
29+
/// </summary>
30+
public string KeyVaultName { get; set; }
31+
}
32+
}

src/ResourceManager/Compute/Commands.Compute/Extension/SqlServer/KeyVaultCredentialSettings.cs renamed to src/ResourceManager/Compute/Commands.Compute/Extension/SqlServer/AzureVMSqlServerKeyVaultCredentialSettings.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using System.Security;
1615
using Newtonsoft.Json;
16+
using System.Collections.Generic;
1717

1818
namespace Microsoft.Azure.Commands.Compute
1919
{
@@ -43,7 +43,7 @@ public class KeyVaultCredentialSettings
4343
/// <value>
4444
/// The azure key vault URL for Credential Management.
4545
/// </value>
46-
[JsonIgnoreAttribute()]
46+
[JsonIgnore]
4747
public string AzureKeyVaultUrl { get; set; }
4848

4949
/// <summary>
@@ -52,7 +52,7 @@ public class KeyVaultCredentialSettings
5252
/// <value>
5353
/// The name of the service principal to access the Azure Key Vault.
5454
/// </value>
55-
[JsonIgnoreAttribute()]
55+
[JsonIgnore]
5656
public string ServicePrincipalName { get; set; }
5757

5858
/// <summary>
@@ -61,7 +61,16 @@ public class KeyVaultCredentialSettings
6161
/// <value>
6262
/// The service principal secret to access the Azure Key Vault.
6363
/// </value>
64-
[JsonIgnoreAttribute()]
64+
[JsonIgnore]
6565
public string ServicePrincipalSecret { get; set; }
66+
67+
/// <summary>
68+
/// Gets the credentials
69+
/// </summary>
70+
/// <value>
71+
/// The list of existing credentials for AKV.
72+
/// </value>
73+
[JsonIgnore]
74+
public List<AzureVMSqlServerKeyVaultCredential> Credentials { get; set; }
6675
}
6776
}

src/ResourceManager/Compute/Commands.Compute/Extension/SqlServer/GetAzureVMSqlServerExtensionCommand.cs

Lines changed: 69 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using Microsoft.Azure.Management.Compute.Models;
1919
using Newtonsoft.Json;
2020
using System;
21+
using System.Collections.Generic;
2122
using System.Globalization;
2223
using System.Linq;
2324
using System.Management.Automation;
@@ -33,6 +34,22 @@ namespace Microsoft.Azure.Commands.Compute
3334
public class GetAzureVMSqlServerExtensionCommand : VirtualMachineExtensionBaseCmdlet
3435
{
3536
protected const string GetSqlServerExtensionParamSetName = "GetSqlServerExtension";
37+
protected const string SqlConfigurationSubStatusCode = "ComponentStatus/SQL Configuration/succeeded";
38+
39+
// These maps are needed due to mismatch in the values while we set/get these parameters.
40+
protected static readonly Dictionary<string, string> AutoBackupScheduleTypeMap =
41+
new Dictionary<string, string>()
42+
{
43+
{ "NOTSET" , null },
44+
{ "SYSTEM" , "Automated" },
45+
{ "CUSTOM" , "Manual" }
46+
};
47+
protected static readonly Dictionary<string, string> AutoPatchingCategoryMap =
48+
new Dictionary<string, string>()
49+
{
50+
{ "WindowsMandatoryUpdates" , "Important" },
51+
};
52+
3653

3754
[Parameter(
3855
Mandatory = true,
@@ -102,11 +119,29 @@ private VirtualMachineSqlServerExtensionContext GetSqlServerExtensionContext(PSV
102119
{
103120
SqlServerPublicSettings extensionPublicSettings = null;
104121
VirtualMachineSqlServerExtensionContext context = null;
122+
123+
// Extract sql configuration information from one of the sub statuses
124+
if (extension.SubStatuses == null
125+
|| extension.SubStatuses.FirstOrDefault(s =>
126+
s.Code.Equals(SqlConfigurationSubStatusCode, StringComparison.InvariantCultureIgnoreCase)) == null)
127+
{
128+
ThrowTerminatingError(
129+
new ErrorRecord(
130+
new Exception(
131+
String.Format(
132+
CultureInfo.CurrentUICulture,
133+
Properties.Resources.AzureVMSqlServerSqlConfigurationNotFound,
134+
extension.SubStatuses)),
135+
string.Empty,
136+
ErrorCategory.ParserError,
137+
null));
138+
}
105139

140+
string sqlConfiguration = extension.SubStatuses.First(s => s.Code.Equals(SqlConfigurationSubStatusCode, StringComparison.InvariantCultureIgnoreCase)).Message;
141+
106142
try
107143
{
108-
extensionPublicSettings = string.IsNullOrEmpty(extension.PublicSettings) ? null
109-
: JsonConvert.DeserializeObject<SqlServerPublicSettings>(extension.PublicSettings);
144+
AzureVMSqlServerConfiguration settings = JsonConvert.DeserializeObject<AzureVMSqlServerConfiguration>(sqlConfiguration);
110145

111146
// #$ISSUE- extension.Statuses is always null, follow up with Azure team
112147
context = new VirtualMachineSqlServerExtensionContext
@@ -122,12 +157,38 @@ private VirtualMachineSqlServerExtensionContext GetSqlServerExtensionContext(PSV
122157
PublicSettings = JsonConvert.SerializeObject(extensionPublicSettings),
123158
ProtectedSettings = extension.ProtectedSettings,
124159
ProvisioningState = extension.ProvisioningState,
125-
AutoBackupSettings = extensionPublicSettings.AutoBackupSettings,
126-
AutoPatchingSettings = extensionPublicSettings.AutoPatchingSettings,
127-
KeyVaultCredentialSettings = extensionPublicSettings.KeyVaultCredentialSettings,
160+
AutoBackupSettings = settings.AutoBackup == null ? null : new AutoBackupSettings()
161+
{
162+
Enable = settings.AutoBackup.Enable,
163+
EnableEncryption = settings.AutoBackup.EnableEncryption,
164+
RetentionPeriod = settings.AutoBackup.RetentionPeriod,
165+
StorageUrl = settings.AutoBackup.StorageAccountUrl,
166+
BackupSystemDbs = settings.AutoBackup.BackupSystemDbs,
167+
BackupScheduleType = string.IsNullOrEmpty(settings.AutoBackup.BackupScheduleType) ? null : AutoBackupScheduleTypeMap[settings.AutoBackup.BackupScheduleType],
168+
FullBackupFrequency = settings.AutoBackup.FullBackupFrequency,
169+
FullBackupStartTime = settings.AutoBackup.FullBackupStartTime,
170+
FullBackupWindowHours = settings.AutoBackup.FullBackupWindowHours,
171+
LogBackupFrequency = settings.AutoBackup.LogBackupFrequency
172+
},
173+
AutoPatchingSettings = settings.AutoPatching == null ? null : new AutoPatchingSettings()
174+
{
175+
Enable = settings.AutoPatching.Enable,
176+
DayOfWeek = settings.AutoPatching.DayOfWeek,
177+
MaintenanceWindowDuration = settings.AutoPatching.MaintenanceWindowDuration,
178+
MaintenanceWindowStartingHour = settings.AutoPatching.MaintenanceWindowStartingHour,
179+
PatchCategory = string.IsNullOrEmpty(settings.AutoPatching.PatchCategory) ? null : AutoPatchingCategoryMap[settings.AutoPatching.PatchCategory]
180+
},
181+
KeyVaultCredentialSettings = settings.AzureKeyVault == null ? null : new KeyVaultCredentialSettings()
182+
{
183+
Enable = settings.AzureKeyVault.Enable,
184+
Credentials = settings.AzureKeyVault.CredentialsList
185+
},
186+
AutoTelemetrySettings = settings.AutoTelemetryReport == null ? null : new AutoTelemetrySettings()
187+
{
188+
Region = settings.AutoTelemetryReport.Location,
189+
},
128190
Statuses = extension.Statuses
129191
};
130-
131192
}
132193
catch (JsonException e)
133194
{
@@ -136,8 +197,8 @@ private VirtualMachineSqlServerExtensionContext GetSqlServerExtensionContext(PSV
136197
new JsonException(
137198
String.Format(
138199
CultureInfo.CurrentUICulture,
139-
Properties.Resources.AzureVMSqlServerWrongSettingsFormat,
140-
extension.PublicSettings),
200+
Properties.Resources.AzureVMSqlServerWrongConfigFormat,
201+
sqlConfiguration),
141202
e),
142203
string.Empty,
143204
ErrorCategory.ParserError,

src/ResourceManager/Compute/Commands.Compute/Extension/SqlServer/VirtualMachineSqlServerExtensionContext.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,10 @@ public class VirtualMachineSqlServerExtensionContext : PSVirtualMachineExtension
5555
/// Key Vault Credential settings
5656
/// </summary>
5757
public KeyVaultCredentialSettings KeyVaultCredentialSettings;
58+
59+
/// <summary>
60+
/// Auto Telemetry settings
61+
/// </summary>
62+
public AutoTelemetrySettings AutoTelemetrySettings;
5863
}
5964
}

src/ResourceManager/Compute/Commands.Compute/Properties/Resources.Designer.cs

Lines changed: 13 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)