Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL Ledger Cmdlets #14974

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Sql/Sql/Common/ResourceIdentityHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ public enum ResourceIdentityType

public class ResourceIdentityHelper
{
public static Management.Sql.Models.ResourceIdentity GetIdentityObjectFromType(bool assignIdentityIsPresent)
public static Management.Sql.Models.ResourceIdentityWithUserAssignedIdentities GetIdentityObjectFromType(bool assignIdentityIsPresent)
rewongmicrosoft marked this conversation as resolved.
Show resolved Hide resolved
{
Management.Sql.Models.ResourceIdentity identityResult = null;
Management.Sql.Models.ResourceIdentityWithUserAssignedIdentities identityResult = null;
if (assignIdentityIsPresent)
{
identityResult = new Management.Sql.Models.ResourceIdentity()
identityResult = new Management.Sql.Models.ResourceIdentityWithUserAssignedIdentities()
{
Type = ResourceIdentityType.SystemAssigned.ToString()
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ public class AzureSqlDatabaseLongTermRetentionPolicyModel
/// <summary>
/// Gets or sets the long term retention policy of the database
/// </summary>
public BackupLongTermRetentionPolicy Policy { get; set; }
public LongTermRetentionPolicy Policy { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ internal AzureSqlDatabaseBackupLongTermRetentionPolicyModel GetDatabaseBackupLon
string serverName,
string databaseName)
{
Management.Sql.Models.BackupLongTermRetentionPolicy response = Communicator.GetDatabaseLongTermRetentionPolicy(
Management.Sql.Models.LongTermRetentionPolicy response = Communicator.GetDatabaseLongTermRetentionPolicy(
resourceGroup,
serverName,
databaseName);
Expand Down Expand Up @@ -324,11 +324,11 @@ internal AzureSqlDatabaseBackupLongTermRetentionPolicyModel SetDatabaseBackupLon
string databaseName,
AzureSqlDatabaseBackupLongTermRetentionPolicyModel model)
{
Management.Sql.Models.BackupLongTermRetentionPolicy response = Communicator.SetDatabaseLongTermRetentionPolicy(
Management.Sql.Models.LongTermRetentionPolicy response = Communicator.SetDatabaseLongTermRetentionPolicy(
resourceGroup,
serverName,
databaseName,
new Management.Sql.Models.BackupLongTermRetentionPolicy()
new Management.Sql.Models.LongTermRetentionPolicy()
{
WeeklyRetention = model.WeeklyRetention,
MonthlyRetention = model.MonthlyRetention,
Expand Down Expand Up @@ -524,7 +524,7 @@ internal AzureSqlDatabaseModel RestoreDatabase(string resourceGroup, DateTime re
Capacity = model.Capacity
},
LicenseType = model.LicenseType,
StorageAccountType = MapExternalBackupStorageRedundancyToInternal(model.BackupStorageRedundancy),
RequestedBackupStorageRedundancy = MapExternalBackupStorageRedundancyToInternal(model.BackupStorageRedundancy),
};

if (model.CreateMode == Management.Sql.Models.CreateMode.Recovery)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,12 @@ public Management.Sql.LegacySdk.Models.DatabaseBackupLongTermRetentionPolicy Set
/// <param name="resourceGroup">The resource group name.</param>
/// <param name="serverName">The server name.</param>
/// <param name="databaseName">The database name.</param>
public Management.Sql.Models.BackupLongTermRetentionPolicy GetDatabaseLongTermRetentionPolicy(
public Management.Sql.Models.LongTermRetentionPolicy GetDatabaseLongTermRetentionPolicy(
string resourceGroup,
string serverName,
string databaseName)
{
return GetCurrentSqlClient().BackupLongTermRetentionPolicies.Get(resourceGroup, serverName, databaseName);
return GetCurrentSqlClient().LongTermRetentionPolicies.Get(resourceGroup, serverName, databaseName);
}

/// <summary>
Expand All @@ -239,13 +239,13 @@ public Management.Sql.Models.BackupLongTermRetentionPolicy GetDatabaseLongTermRe
/// <param name="serverName">The server name.</param>
/// <param name="databaseName">The database name.</param>
/// <param name="policy">The Long Term Retention policy to apply.</param>
public Management.Sql.Models.BackupLongTermRetentionPolicy SetDatabaseLongTermRetentionPolicy(
public Management.Sql.Models.LongTermRetentionPolicy SetDatabaseLongTermRetentionPolicy(
string resourceGroup,
string serverName,
string databaseName,
Management.Sql.Models.BackupLongTermRetentionPolicy policy)
Management.Sql.Models.LongTermRetentionPolicy policy)
{
return GetCurrentSqlClient().BackupLongTermRetentionPolicies.CreateOrUpdate(resourceGroup, serverName, databaseName, policy);
return GetCurrentSqlClient().LongTermRetentionPolicies.CreateOrUpdate(resourceGroup, serverName, databaseName, policy);
}

/// <summary>
Expand Down
8 changes: 8 additions & 0 deletions src/Sql/Sql/Database/Cmdlet/NewAzureSqlDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,13 @@ public class NewAzureSqlDatabase : AzureSqlDatabaseCmdletBase<AzureSqlDatabaseCr
HelpMessage = "The Maintenance configuration id for the SQL Database.")]
public string MaintenanceConfigurationId { get; set; }

/// <summary>
/// Gets or sets the ledger option to assign to the Azure SQL Database
/// </summary>
[Parameter(Mandatory = false,
HelpMessage = "The enable ledger option for the Azure Sql Database")]
public SwitchParameter EnableLedger { get; set; }

/// <summary>
/// Overriding to add warning message
/// </summary>
Expand Down Expand Up @@ -315,6 +322,7 @@ protected override AzureSqlDatabaseCreateOrUpdateModel ApplyUserInputToModel(Azu
BackupStorageRedundancy = BackupStorageRedundancy,
SecondaryType = SecondaryType,
MaintenanceConfigurationId = MaintenanceConfigurationId,
EnableLedger = this.IsParameterBound(p => p.EnableLedger) ? EnableLedger.ToBool() : (bool?)null,
};

if (ParameterSetName == DtuDatabaseParameterSet)
Expand Down
8 changes: 8 additions & 0 deletions src/Sql/Sql/Database/Cmdlet/SetAzureSqlDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,13 @@ public class SetAzureSqlDatabase : AzureSqlDatabaseCmdletBase<IEnumerable<AzureS
HelpMessage = "The Maintenance configuration id for the SQL Database.")]
public string MaintenanceConfigurationId { get; set; }

/// <summary>
/// Gets or sets the ledger option to assign to the Azure SQL Database
/// </summary>
[Parameter(Mandatory = false,
HelpMessage = "The enable ledger option for the Azure Sql Database")]
public SwitchParameter EnableLedger { get; set; }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we don't allow alterting this, should this be part of the Set cmdlet?


/// <summary>
/// Overriding to add warning message
/// </summary>
Expand Down Expand Up @@ -311,6 +318,7 @@ protected override IEnumerable<AzureSqlDatabaseModel> ApplyUserInputToModel(IEnu
BackupStorageRedundancy = BackupStorageRedundancy,
SecondaryType = SecondaryType,
MaintenanceConfigurationId = MaintenanceConfigurationId,
EnableLedger = MyInvocation.BoundParameters.ContainsKey("EnableLedger") ? (bool?)EnableLedger.ToBool() : null,
};

var database = ModelAdapter.GetDatabase(ResourceGroupName, ServerName, DatabaseName);
Expand Down
9 changes: 8 additions & 1 deletion src/Sql/Sql/Database/Model/AzureSqlDatabaseModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ public class AzureSqlDatabaseModel
/// </summary>
public string MaintenanceConfigurationId { get; set; }

/// <summary>
/// Gets or sets the ledger property for the database
/// </summary>
public bool? EnableLedger { get; set; }

/// <summary>
/// Construct AzureSqlDatabaseModel
/// </summary>
Expand Down Expand Up @@ -257,6 +262,7 @@ public AzureSqlDatabaseModel(string resourceGroup, string serverName, Management
BackupStorageRedundancy = null;
SecondaryType = null;
MaintenanceConfigurationId = null;
EnableLedger = false;
}

/// <summary>
Expand Down Expand Up @@ -308,9 +314,10 @@ public AzureSqlDatabaseModel(string resourceGroup, string serverName, Management
AutoPauseDelayInMinutes = database.AutoPauseDelay;
MinimumCapacity = database.MinCapacity;
HighAvailabilityReplicaCount = database.HighAvailabilityReplicaCount;
BackupStorageRedundancy = MapInternalBackupStorageRedundancyToExternal(database.StorageAccountType);
BackupStorageRedundancy = MapInternalBackupStorageRedundancyToExternal(database.CurrentBackupStorageRedundancy);
SecondaryType = database.SecondaryType;
MaintenanceConfigurationId = database.MaintenanceConfigurationId;
EnableLedger = database.IsLedgerOn;
}

/// <summary>
Expand Down
3 changes: 2 additions & 1 deletion src/Sql/Sql/Database/Services/AzureSqlDatabaseAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,10 @@ internal AzureSqlDatabaseModel UpsertDatabaseWithNewSdk(string resourceGroup, st
AutoPauseDelay = model.Database.AutoPauseDelayInMinutes,
MinCapacity = model.Database.MinimumCapacity,
HighAvailabilityReplicaCount = model.Database.HighAvailabilityReplicaCount,
StorageAccountType = MapExternalBackupStorageRedundancyToInternal(model.Database.BackupStorageRedundancy),
RequestedBackupStorageRedundancy = MapExternalBackupStorageRedundancyToInternal(model.Database.BackupStorageRedundancy),
SecondaryType = model.Database.SecondaryType,
MaintenanceConfigurationId = MaintenanceConfigurationHelper.ConvertMaintenanceConfigurationIdArgument(model.Database.MaintenanceConfigurationId, _subscription.Id),
IsLedgerOn = model.Database.EnableLedger,
});

return CreateDatabaseModelFromResponse(resourceGroup, serverName, resp);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
using Microsoft.Azure.Commands.Common.Authentication.Models;
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
using Microsoft.Azure.Commands.Sql.Common;
using Microsoft.Azure.Commands.Sql.Database.Model;
using Microsoft.Azure.Commands.Sql.LedgerDigestUploads.Services;
using Microsoft.Azure.Commands.Sql.LedgerDigestUploads.Model;
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
using System;
using System.Collections.Generic;
using System.Management.Automation;

namespace Microsoft.Azure.Commands.Sql.LedgerDigestUploads.Cmdlet
{
public abstract class AzureSqlDatabaseLedgerDigestUploadBase : AzureSqlCmdletBase<IEnumerable<AzureSqlDatabaseLedgerDigestUploadModel>, AzureSqlDatabaseLedgerDigestUploadAdapter>
{
/// <summary>
/// Gets or sets the name of the Azure Sql server to use
/// </summary>
[Parameter(Mandatory = true,
ValueFromPipelineByPropertyName = true,
Position = 1,
HelpMessage = "The Azure Sql Server name.")]
[ResourceNameCompleter("Microsoft.Sql/servers", "ResourceGroupName")]
[ValidateNotNullOrEmpty]
public string ServerName { get; set; }

/// <summary>
/// Gets or sets the name of the database to use.
/// </summary>
[Parameter(Mandatory = true,
ValueFromPipelineByPropertyName = true,
Position = 2,
HelpMessage = "The name of the Azure SQL Database.")]
[ResourceNameCompleter("Microsoft.Sql/servers/databases", "ResourceGroupName", "ServerName")]
[ValidateNotNullOrEmpty]
public string DatabaseName { get; set; }

/// <summary>
/// Gets or sets the Database object to get the ledger digest upload configuration for
/// </summary>
[Parameter(
ParameterSetName = "DatabaseObjectParameterSet",
Mandatory = true,
ValueFromPipeline = true,
HelpMessage = "The database object to manage its ledger digest upload configuration.")]
[ValidateNotNullOrEmpty]
[Alias("AzureSqlDatabase")]
public AzureSqlDatabaseModel AzureSqlDatabaseObject { get; set; }

/// <summary>
/// Gets or sets the Database Resource ID to get backups for
/// </summary>
[Parameter(Mandatory = true,
rewongmicrosoft marked this conversation as resolved.
Show resolved Hide resolved
Position = 0,
ValueFromPipelineByPropertyName = true,
HelpMessage = "The database Resource ID to get backups for.")]
rewongmicrosoft marked this conversation as resolved.
Show resolved Hide resolved
public string ResourceId { get; set; }

/// <summary>
/// Intializes the model adapter
/// </summary>
/// <returns>The server adapter</returns>
protected override AzureSqlDatabaseLedgerDigestUploadAdapter InitModelAdapter()
{
return new AzureSqlDatabaseLedgerDigestUploadAdapter(DefaultProfile.DefaultContext);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;
using System.Linq;
using System.Collections.Generic;
using System.Management.Automation;
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
using Microsoft.Azure.Commands.Sql.LedgerDigestUploads.Model;
using Microsoft.Azure.Commands.Sql.Database.Model;
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;

namespace Microsoft.Azure.Commands.Sql.LedgerDigestUploads.Cmdlet
{
/// <summary>
/// Defines the Disable-AzSqlDatabaseLedgerDigestUpload cmdlet
/// </summary>
[Cmdlet("Disable", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "SqlDatabaseLedgerDigestUpload", ConfirmImpact = ConfirmImpact.Low, SupportsShouldProcess = true), OutputType(typeof(AzureSqlDatabaseLedgerDigestLocationModel))]
public class DisableAzSqlDatabaseLedgerDigestUpload : AzureSqlDatabaseLedgerDigestUploadBase
{
/// <summary>
/// Get the entities from the service
/// </summary>
/// <returns>The list of entities</returns>
protected override IEnumerable<AzureSqlDatabaseLedgerDigestUploadModel> GetEntity()
{
if (AzureSqlDatabaseObject != null)
{
ServerName = AzureSqlDatabaseObject.ServerName;
DatabaseName = AzureSqlDatabaseObject.DatabaseName;
ResourceGroupName = AzureSqlDatabaseObject.ResourceGroupName;
}
else if (!string.IsNullOrWhiteSpace(ResourceId))
{
ResourceIdentifier identifier = new ResourceIdentifier(ResourceId);
DatabaseName = identifier.ResourceName;
ResourceGroupName = identifier.ResourceGroupName;
ServerName = identifier.ParentResource.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries)[1];
}

ICollection<AzureSqlDatabaseLedgerDigestUploadModel> results = new List<AzureSqlDatabaseLedgerDigestUploadModel>()
{
ModelAdapter.GetLedgerDigestUpload(
this.ResourceGroupName,
this.ServerName,
this.DatabaseName)
};

return results;
}

/// <summary>
/// Create the model from user input
/// </summary>
/// <param name="model">Model retrieved from service</param>
/// <returns>The model that was passed in</returns>
protected override IEnumerable<AzureSqlDatabaseLedgerDigestUploadModel> ApplyUserInputToModel(IEnumerable<AzureSqlDatabaseLedgerDigestUploadModel> model)
{
return new List<AzureSqlDatabaseLedgerDigestUploadModel>()
{
new AzureSqlDatabaseLedgerDigestUploadModel(
ResourceGroupName,
ServerName,
DatabaseName,
new Management.Sql.Models.LedgerDigestUploads{
DigestStorageEndpoint = null
})
};
}

/// <summary>
/// Update the entity
/// </summary>
/// <param name="entity">The output of apply user input to model</param>
/// <returns>The input entity</returns>
protected override IEnumerable<AzureSqlDatabaseLedgerDigestUploadModel> PersistChanges(IEnumerable<AzureSqlDatabaseLedgerDigestUploadModel> entity)
{
if (!ShouldProcess(DatabaseName)) return null;

return new List<AzureSqlDatabaseLedgerDigestUploadModel>() {
ModelAdapter.SetLedgerDigestUpload(this.ResourceGroupName, this.ServerName, this.DatabaseName, entity.First())
};
}
}
}
Loading