Skip to content

Commit 339e890

Browse files
ledger changes + changes for new SDK version
1 parent 88f7be2 commit 339e890

20 files changed

+803
-27
lines changed

src/Sql/Sql/Common/ResourceIdentityHelper.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ public enum ResourceIdentityType
2121

2222
public class ResourceIdentityHelper
2323
{
24-
public static Management.Sql.Models.ResourceIdentity GetIdentityObjectFromType(bool assignIdentityIsPresent)
24+
public static Management.Sql.Models.ResourceIdentityWithUserAssignedIdentities GetIdentityObjectFromType(bool assignIdentityIsPresent)
2525
{
26-
Management.Sql.Models.ResourceIdentity identityResult = null;
26+
Management.Sql.Models.ResourceIdentityWithUserAssignedIdentities identityResult = null;
2727
if (assignIdentityIsPresent)
2828
{
29-
identityResult = new Management.Sql.Models.ResourceIdentity()
29+
identityResult = new Management.Sql.Models.ResourceIdentityWithUserAssignedIdentities()
3030
{
3131
Type = ResourceIdentityType.SystemAssigned.ToString()
3232
};

src/Sql/Sql/Database Backup/Model/AzureSqlDatabaseLongTermRetentionPolicyModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ public class AzureSqlDatabaseLongTermRetentionPolicyModel
3636
/// <summary>
3737
/// Gets or sets the long term retention policy of the database
3838
/// </summary>
39-
public BackupLongTermRetentionPolicy Policy { get; set; }
39+
public LongTermRetentionPolicy Policy { get; set; }
4040
}
4141
}

src/Sql/Sql/Database Backup/Services/AzureSqlDatabaseBackupAdapter.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ internal AzureSqlDatabaseBackupLongTermRetentionPolicyModel GetDatabaseBackupLon
263263
string serverName,
264264
string databaseName)
265265
{
266-
Management.Sql.Models.BackupLongTermRetentionPolicy response = Communicator.GetDatabaseLongTermRetentionPolicy(
266+
Management.Sql.Models.LongTermRetentionPolicy response = Communicator.GetDatabaseLongTermRetentionPolicy(
267267
resourceGroup,
268268
serverName,
269269
databaseName);
@@ -324,11 +324,11 @@ internal AzureSqlDatabaseBackupLongTermRetentionPolicyModel SetDatabaseBackupLon
324324
string databaseName,
325325
AzureSqlDatabaseBackupLongTermRetentionPolicyModel model)
326326
{
327-
Management.Sql.Models.BackupLongTermRetentionPolicy response = Communicator.SetDatabaseLongTermRetentionPolicy(
327+
Management.Sql.Models.LongTermRetentionPolicy response = Communicator.SetDatabaseLongTermRetentionPolicy(
328328
resourceGroup,
329329
serverName,
330330
databaseName,
331-
new Management.Sql.Models.BackupLongTermRetentionPolicy()
331+
new Management.Sql.Models.LongTermRetentionPolicy()
332332
{
333333
WeeklyRetention = model.WeeklyRetention,
334334
MonthlyRetention = model.MonthlyRetention,
@@ -524,7 +524,7 @@ internal AzureSqlDatabaseModel RestoreDatabase(string resourceGroup, DateTime re
524524
Capacity = model.Capacity
525525
},
526526
LicenseType = model.LicenseType,
527-
StorageAccountType = MapExternalBackupStorageRedundancyToInternal(model.BackupStorageRedundancy),
527+
RequestedBackupStorageRedundancy = MapExternalBackupStorageRedundancyToInternal(model.BackupStorageRedundancy),
528528
};
529529

530530
if (model.CreateMode == Management.Sql.Models.CreateMode.Recovery)

src/Sql/Sql/Database Backup/Services/AzureSqlDatabaseBackupCommunicator.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,12 @@ public Management.Sql.LegacySdk.Models.DatabaseBackupLongTermRetentionPolicy Set
224224
/// <param name="resourceGroup">The resource group name.</param>
225225
/// <param name="serverName">The server name.</param>
226226
/// <param name="databaseName">The database name.</param>
227-
public Management.Sql.Models.BackupLongTermRetentionPolicy GetDatabaseLongTermRetentionPolicy(
227+
public Management.Sql.Models.LongTermRetentionPolicy GetDatabaseLongTermRetentionPolicy(
228228
string resourceGroup,
229229
string serverName,
230230
string databaseName)
231231
{
232-
return GetCurrentSqlClient().BackupLongTermRetentionPolicies.Get(resourceGroup, serverName, databaseName);
232+
return GetCurrentSqlClient().LongTermRetentionPolicies.Get(resourceGroup, serverName, databaseName);
233233
}
234234

235235
/// <summary>
@@ -239,13 +239,13 @@ public Management.Sql.Models.BackupLongTermRetentionPolicy GetDatabaseLongTermRe
239239
/// <param name="serverName">The server name.</param>
240240
/// <param name="databaseName">The database name.</param>
241241
/// <param name="policy">The Long Term Retention policy to apply.</param>
242-
public Management.Sql.Models.BackupLongTermRetentionPolicy SetDatabaseLongTermRetentionPolicy(
242+
public Management.Sql.Models.LongTermRetentionPolicy SetDatabaseLongTermRetentionPolicy(
243243
string resourceGroup,
244244
string serverName,
245245
string databaseName,
246-
Management.Sql.Models.BackupLongTermRetentionPolicy policy)
246+
Management.Sql.Models.LongTermRetentionPolicy policy)
247247
{
248-
return GetCurrentSqlClient().BackupLongTermRetentionPolicies.CreateOrUpdate(resourceGroup, serverName, databaseName, policy);
248+
return GetCurrentSqlClient().LongTermRetentionPolicies.CreateOrUpdate(resourceGroup, serverName, databaseName, policy);
249249
}
250250

251251
/// <summary>

src/Sql/Sql/Database/Cmdlet/NewAzureSqlDatabase.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,13 @@ public class NewAzureSqlDatabase : AzureSqlDatabaseCmdletBase<AzureSqlDatabaseCr
231231
HelpMessage = "The Maintenance configuration id for the SQL Database.")]
232232
public string MaintenanceConfigurationId { get; set; }
233233

234+
/// <summary>
235+
/// Gets or sets the ledger option to assign to the Azure SQL Database
236+
/// </summary>
237+
[Parameter(Mandatory = false,
238+
HelpMessage = "The enable ledger option for the Azure Sql Database")]
239+
public SwitchParameter EnableLedger { get; set; }
240+
234241
/// <summary>
235242
/// Overriding to add warning message
236243
/// </summary>
@@ -315,6 +322,7 @@ protected override AzureSqlDatabaseCreateOrUpdateModel ApplyUserInputToModel(Azu
315322
BackupStorageRedundancy = BackupStorageRedundancy,
316323
SecondaryType = SecondaryType,
317324
MaintenanceConfigurationId = MaintenanceConfigurationId,
325+
EnableLedger = this.IsParameterBound(p => p.EnableLedger) ? EnableLedger.ToBool() : (bool?)null,
318326
};
319327

320328
if (ParameterSetName == DtuDatabaseParameterSet)

src/Sql/Sql/Database/Cmdlet/SetAzureSqlDatabase.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,13 @@ public class SetAzureSqlDatabase : AzureSqlDatabaseCmdletBase<IEnumerable<AzureS
257257
HelpMessage = "The Maintenance configuration id for the SQL Database.")]
258258
public string MaintenanceConfigurationId { get; set; }
259259

260+
/// <summary>
261+
/// Gets or sets the ledger option to assign to the Azure SQL Database
262+
/// </summary>
263+
[Parameter(Mandatory = false,
264+
HelpMessage = "The enable ledger option for the Azure Sql Database")]
265+
public SwitchParameter EnableLedger { get; set; }
266+
260267
/// <summary>
261268
/// Overriding to add warning message
262269
/// </summary>
@@ -311,6 +318,7 @@ protected override IEnumerable<AzureSqlDatabaseModel> ApplyUserInputToModel(IEnu
311318
BackupStorageRedundancy = BackupStorageRedundancy,
312319
SecondaryType = SecondaryType,
313320
MaintenanceConfigurationId = MaintenanceConfigurationId,
321+
EnableLedger = MyInvocation.BoundParameters.ContainsKey("EnableLedger") ? (bool?)EnableLedger.ToBool() : null,
314322
};
315323

316324
var database = ModelAdapter.GetDatabase(ResourceGroupName, ServerName, DatabaseName);

src/Sql/Sql/Database/Model/AzureSqlDatabaseModel.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,11 @@ public class AzureSqlDatabaseModel
200200
/// </summary>
201201
public string MaintenanceConfigurationId { get; set; }
202202

203+
/// <summary>
204+
/// Gets or sets the ledger property for the database
205+
/// </summary>
206+
public bool? EnableLedger { get; set; }
207+
203208
/// <summary>
204209
/// Construct AzureSqlDatabaseModel
205210
/// </summary>
@@ -257,6 +262,7 @@ public AzureSqlDatabaseModel(string resourceGroup, string serverName, Management
257262
BackupStorageRedundancy = null;
258263
SecondaryType = null;
259264
MaintenanceConfigurationId = null;
265+
EnableLedger = false;
260266
}
261267

262268
/// <summary>
@@ -308,9 +314,10 @@ public AzureSqlDatabaseModel(string resourceGroup, string serverName, Management
308314
AutoPauseDelayInMinutes = database.AutoPauseDelay;
309315
MinimumCapacity = database.MinCapacity;
310316
HighAvailabilityReplicaCount = database.HighAvailabilityReplicaCount;
311-
BackupStorageRedundancy = MapInternalBackupStorageRedundancyToExternal(database.StorageAccountType);
317+
BackupStorageRedundancy = MapInternalBackupStorageRedundancyToExternal(database.CurrentBackupStorageRedundancy);
312318
SecondaryType = database.SecondaryType;
313319
MaintenanceConfigurationId = database.MaintenanceConfigurationId;
320+
EnableLedger = database.IsLedgerOn;
314321
}
315322

316323
/// <summary>

src/Sql/Sql/Database/Services/AzureSqlDatabaseAdapter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,10 @@ internal AzureSqlDatabaseModel UpsertDatabaseWithNewSdk(string resourceGroup, st
161161
AutoPauseDelay = model.Database.AutoPauseDelayInMinutes,
162162
MinCapacity = model.Database.MinimumCapacity,
163163
HighAvailabilityReplicaCount = model.Database.HighAvailabilityReplicaCount,
164-
StorageAccountType = MapExternalBackupStorageRedundancyToInternal(model.Database.BackupStorageRedundancy),
164+
RequestedBackupStorageRedundancy = MapExternalBackupStorageRedundancyToInternal(model.Database.BackupStorageRedundancy),
165165
SecondaryType = model.Database.SecondaryType,
166166
MaintenanceConfigurationId = MaintenanceConfigurationHelper.ConvertMaintenanceConfigurationIdArgument(model.Database.MaintenanceConfigurationId, _subscription.Id),
167+
IsLedgerOn = model.Database.EnableLedger,
167168
});
168169

169170
return CreateDatabaseModelFromResponse(resourceGroup, serverName, resp);
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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 Microsoft.Azure.Commands.Common.Authentication.Abstractions;
16+
using Microsoft.Azure.Commands.Common.Authentication.Models;
17+
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
18+
using Microsoft.Azure.Commands.Sql.Common;
19+
using Microsoft.Azure.Commands.Sql.Database.Model;
20+
using Microsoft.Azure.Commands.Sql.LedgerDigestUploads.Services;
21+
using Microsoft.Azure.Commands.Sql.LedgerDigestUploads.Model;
22+
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
23+
using System;
24+
using System.Collections.Generic;
25+
using System.Management.Automation;
26+
27+
namespace Microsoft.Azure.Commands.Sql.LedgerDigestUploads.Cmdlet
28+
{
29+
public abstract class AzureSqlDatabaseLedgerDigestUploadBase : AzureSqlCmdletBase<IEnumerable<AzureSqlDatabaseLedgerDigestUploadModel>, AzureSqlDatabaseLedgerDigestUploadAdapter>
30+
{
31+
/// <summary>
32+
/// Gets or sets the name of the Azure Sql server to use
33+
/// </summary>
34+
[Parameter(Mandatory = true,
35+
ValueFromPipelineByPropertyName = true,
36+
Position = 1,
37+
HelpMessage = "The Azure Sql Server name.")]
38+
[ResourceNameCompleter("Microsoft.Sql/servers", "ResourceGroupName")]
39+
[ValidateNotNullOrEmpty]
40+
public string ServerName { get; set; }
41+
42+
/// <summary>
43+
/// Gets or sets the name of the database to use.
44+
/// </summary>
45+
[Parameter(Mandatory = true,
46+
ValueFromPipelineByPropertyName = true,
47+
Position = 2,
48+
HelpMessage = "The name of the Azure SQL Database.")]
49+
[ResourceNameCompleter("Microsoft.Sql/servers/databases", "ResourceGroupName", "ServerName")]
50+
[ValidateNotNullOrEmpty]
51+
public string DatabaseName { get; set; }
52+
53+
/// <summary>
54+
/// Gets or sets the Database object to get the ledger digest upload configuration for
55+
/// </summary>
56+
[Parameter(
57+
ParameterSetName = "DatabaseObjectParameterSet",
58+
Mandatory = true,
59+
ValueFromPipeline = true,
60+
HelpMessage = "The database object to manage its ledger digest upload configuration.")]
61+
[ValidateNotNullOrEmpty]
62+
[Alias("AzureSqlDatabase")]
63+
public AzureSqlDatabaseModel AzureSqlDatabaseObject { get; set; }
64+
65+
/// <summary>
66+
/// Gets or sets the Database Resource ID to get backups for
67+
/// </summary>
68+
[Parameter(Mandatory = true,
69+
Position = 0,
70+
ValueFromPipelineByPropertyName = true,
71+
HelpMessage = "The database Resource ID to get backups for.")]
72+
public string ResourceId { get; set; }
73+
74+
/// <summary>
75+
/// Intializes the model adapter
76+
/// </summary>
77+
/// <returns>The server adapter</returns>
78+
protected override AzureSqlDatabaseLedgerDigestUploadAdapter InitModelAdapter()
79+
{
80+
return new AzureSqlDatabaseLedgerDigestUploadAdapter(DefaultProfile.DefaultContext);
81+
}
82+
}
83+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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;
16+
using System.Linq;
17+
using System.Collections.Generic;
18+
using System.Management.Automation;
19+
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
20+
using Microsoft.Azure.Commands.Sql.LedgerDigestUploads.Model;
21+
using Microsoft.Azure.Commands.Sql.Database.Model;
22+
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
23+
24+
namespace Microsoft.Azure.Commands.Sql.LedgerDigestUploads.Cmdlet
25+
{
26+
/// <summary>
27+
/// Defines the Disable-AzSqlDatabaseLedgerDigestUpload cmdlet
28+
/// </summary>
29+
[Cmdlet("Disable", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "SqlDatabaseLedgerDigestUpload", ConfirmImpact = ConfirmImpact.Low, SupportsShouldProcess = true), OutputType(typeof(AzureSqlDatabaseLedgerDigestLocationModel))]
30+
public class DisableAzSqlDatabaseLedgerDigestUpload : AzureSqlDatabaseLedgerDigestUploadBase
31+
{
32+
/// <summary>
33+
/// Get the entities from the service
34+
/// </summary>
35+
/// <returns>The list of entities</returns>
36+
protected override IEnumerable<AzureSqlDatabaseLedgerDigestUploadModel> GetEntity()
37+
{
38+
if (AzureSqlDatabaseObject != null)
39+
{
40+
ServerName = AzureSqlDatabaseObject.ServerName;
41+
DatabaseName = AzureSqlDatabaseObject.DatabaseName;
42+
ResourceGroupName = AzureSqlDatabaseObject.ResourceGroupName;
43+
}
44+
else if (!string.IsNullOrWhiteSpace(ResourceId))
45+
{
46+
ResourceIdentifier identifier = new ResourceIdentifier(ResourceId);
47+
DatabaseName = identifier.ResourceName;
48+
ResourceGroupName = identifier.ResourceGroupName;
49+
ServerName = identifier.ParentResource.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries)[1];
50+
}
51+
52+
ICollection<AzureSqlDatabaseLedgerDigestUploadModel> results = new List<AzureSqlDatabaseLedgerDigestUploadModel>()
53+
{
54+
ModelAdapter.GetLedgerDigestUpload(
55+
this.ResourceGroupName,
56+
this.ServerName,
57+
this.DatabaseName)
58+
};
59+
60+
return results;
61+
}
62+
63+
/// <summary>
64+
/// Create the model from user input
65+
/// </summary>
66+
/// <param name="model">Model retrieved from service</param>
67+
/// <returns>The model that was passed in</returns>
68+
protected override IEnumerable<AzureSqlDatabaseLedgerDigestUploadModel> ApplyUserInputToModel(IEnumerable<AzureSqlDatabaseLedgerDigestUploadModel> model)
69+
{
70+
return new List<AzureSqlDatabaseLedgerDigestUploadModel>()
71+
{
72+
new AzureSqlDatabaseLedgerDigestUploadModel(
73+
ResourceGroupName,
74+
ServerName,
75+
DatabaseName,
76+
new Management.Sql.Models.LedgerDigestUploads{
77+
DigestStorageEndpoint = null
78+
})
79+
};
80+
}
81+
82+
/// <summary>
83+
/// Update the entity
84+
/// </summary>
85+
/// <param name="entity">The output of apply user input to model</param>
86+
/// <returns>The input entity</returns>
87+
protected override IEnumerable<AzureSqlDatabaseLedgerDigestUploadModel> PersistChanges(IEnumerable<AzureSqlDatabaseLedgerDigestUploadModel> entity)
88+
{
89+
if (!ShouldProcess(DatabaseName)) return null;
90+
91+
return new List<AzureSqlDatabaseLedgerDigestUploadModel>() {
92+
ModelAdapter.SetLedgerDigestUpload(this.ResourceGroupName, this.ServerName, this.DatabaseName, entity.First())
93+
};
94+
}
95+
}
96+
}

0 commit comments

Comments
 (0)