diff --git a/src/Sql/Sql/Auditing/Services/AuditingEndpointsCommunicator.cs b/src/Sql/Sql/Auditing/Services/AuditingEndpointsCommunicator.cs index bd1588f0d7d7..deac13035ee8 100644 --- a/src/Sql/Sql/Auditing/Services/AuditingEndpointsCommunicator.cs +++ b/src/Sql/Sql/Auditing/Services/AuditingEndpointsCommunicator.cs @@ -226,7 +226,7 @@ public DiagnosticSettingsResource UpdateDiagnosticSettings(DiagnosticSettingsRes if (server.Identity == null || server.Identity.Type != ResourceIdentityType.SystemAssigned.ToString()) { - server.Identity = ResourceIdentityHelper.GetIdentityObjectFromType(true, false, null); + server.Identity = ResourceIdentityHelper.GetIdentityObjectFromType(true, "SystemAssigned", null, null); server = GetCurrentSqlClient().Servers.CreateOrUpdate(resourceGroupName, serverName, server); } diff --git a/src/Sql/Sql/Common/ResourceIdentityHelper.cs b/src/Sql/Sql/Common/ResourceIdentityHelper.cs index fca1b4917ebe..a2a90cb4a0f4 100644 --- a/src/Sql/Sql/Common/ResourceIdentityHelper.cs +++ b/src/Sql/Sql/Common/ResourceIdentityHelper.cs @@ -15,6 +15,7 @@ using Microsoft.Azure.Management.Sql.Models; using System.Collections.Generic; using System.Linq; +using System.Management.Automation; using System.Runtime.CompilerServices; namespace Microsoft.Azure.Commands.Sql.Common @@ -22,21 +23,52 @@ namespace Microsoft.Azure.Commands.Sql.Common public enum ResourceIdentityType { SystemAssigned, + SystemAssignedUserAssigned, UserAssigned, None } public class ResourceIdentityHelper { - public static Management.Sql.Models.ResourceIdentity GetIdentityObjectFromType(bool assignIdentityIsPresent, bool userAssignedIdentityIsPresent, List userAssignedIdentities) + public static Management.Sql.Models.ResourceIdentity GetIdentityObjectFromType(bool assignIdentityIsPresent, string resourceIdentityType, List userAssignedIdentities, Management.Sql.Models.ResourceIdentity existingResourceIdentity) { Management.Sql.Models.ResourceIdentity identityResult = null; - if (assignIdentityIsPresent && userAssignedIdentityIsPresent) + // If the user passes in IdentityType as None, then irrespective of previous config, we set the IdentityType to be None. + // + if (resourceIdentityType != null && resourceIdentityType.Equals(ResourceIdentityType.None.ToString())) + { + identityResult = new Management.Sql.Models.ResourceIdentity() + { + Type = ResourceIdentityType.None.ToString() + }; + + return identityResult; + } + + if (resourceIdentityType != null && assignIdentityIsPresent && resourceIdentityType.Equals(ResourceIdentityType.SystemAssignedUserAssigned.ToString())) { Dictionary umiDict = new Dictionary(); - if (userAssignedIdentities != null && userAssignedIdentities.Any()) + if (userAssignedIdentities == null) + { + throw new PSArgumentNullException("The list of user assigned identity ids needs to be passed if the IdentityType is UserAssigned or SystemAssignedUserAssigned"); + } + + if (existingResourceIdentity != null && userAssignedIdentities.Any() + && existingResourceIdentity.UserAssignedIdentities != null) + { + foreach (string identity in userAssignedIdentities) + { + existingResourceIdentity.UserAssignedIdentities.Add(identity, new UserIdentity()); + } + + identityResult = new Management.Sql.Models.ResourceIdentity() + { + Type = ResourceIdentityType.SystemAssignedUserAssigned.ToString() + }; + } + else if (userAssignedIdentities.Any()) { foreach (string identity in userAssignedIdentities) { @@ -45,34 +77,70 @@ public static Management.Sql.Models.ResourceIdentity GetIdentityObjectFromType(b identityResult = new Management.Sql.Models.ResourceIdentity() { - Type = ResourceIdentityType.UserAssigned.ToString(), + Type = ResourceIdentityType.SystemAssignedUserAssigned.ToString(), UserAssignedIdentities = umiDict }; } - else + } + else if (resourceIdentityType != null && assignIdentityIsPresent && resourceIdentityType.Equals(ResourceIdentityType.UserAssigned.ToString())) + { + Dictionary umiDict = new Dictionary(); + + if (userAssignedIdentities == null) { + throw new PSArgumentNullException("The list of user assigned identity ids needs to be passed if the IdentityType is UserAssigned or SystemAssignedUserAssigned"); + } + + if (existingResourceIdentity != null && userAssignedIdentities.Any() + && existingResourceIdentity.UserAssignedIdentities != null) + { + foreach (string identity in userAssignedIdentities) + { + existingResourceIdentity.UserAssignedIdentities.Add(identity, new UserIdentity()); + } + identityResult = new Management.Sql.Models.ResourceIdentity() { - Type = ResourceIdentityType.SystemAssigned.ToString() + Type = ResourceIdentityType.UserAssigned.ToString() + }; + } + else if (userAssignedIdentities.Any()) + { + foreach (string identity in userAssignedIdentities) + { + umiDict.Add(identity, new UserIdentity()); + } + + identityResult = new Management.Sql.Models.ResourceIdentity() + { + Type = ResourceIdentityType.UserAssigned.ToString(), + UserAssignedIdentities = umiDict }; - } + } } else if (assignIdentityIsPresent) { - identityResult = new Management.Sql.Models.ResourceIdentity() + if (existingResourceIdentity != null) { - Type = ResourceIdentityType.SystemAssigned.ToString() - }; + identityResult = existingResourceIdentity; + identityResult.Type = ResourceIdentityType.SystemAssigned.ToString(); + } + else + { + identityResult = new Management.Sql.Models.ResourceIdentity() + { + Type = ResourceIdentityType.SystemAssigned.ToString() + }; + } } - else if (!assignIdentityIsPresent && !userAssignedIdentityIsPresent) + + if (!assignIdentityIsPresent && existingResourceIdentity != null && existingResourceIdentity.PrincipalId != null) { - identityResult = new Management.Sql.Models.ResourceIdentity() - { - Type = ResourceIdentityType.None.ToString() - }; + identityResult = existingResourceIdentity; } return identityResult; + } } } diff --git a/src/Sql/Sql/ManagedInstance/Cmdlet/NewAzureSqlManagedInstance.cs b/src/Sql/Sql/ManagedInstance/Cmdlet/NewAzureSqlManagedInstance.cs index 31418a223adb..23702a1ae307 100644 --- a/src/Sql/Sql/ManagedInstance/Cmdlet/NewAzureSqlManagedInstance.cs +++ b/src/Sql/Sql/ManagedInstance/Cmdlet/NewAzureSqlManagedInstance.cs @@ -342,11 +342,15 @@ public class NewAzureSqlManagedInstance : ManagedInstanceCmdletBase /// [Parameter(Mandatory = false, HelpMessage = "List of user assigned identities")] - public List UserAssignedIdentity { get; set; } + public List UserAssignedIdentityId { get; set; } + // + /// Type of identity to be assigned to the server.. + /// [Parameter(Mandatory = false, - HelpMessage = "Generate and assign an Azure Active Directory User Assigned Identity for this server for use with key management services like Azure KeyVault.")] - public SwitchParameter AssignUserAssignIdentity { get; set; } + HelpMessage = "Type of Identity to be used. Possible values are SystemAsssigned, UserAssigned, SystemAssignedUserAssigned and None.")] + [PSArgumentCompleter("SystemAssigned", "UserAssigned", "SystemAssignedUserAssigned", "None")] + public string IdentityType { get; set; } /// /// Gets or sets whether or not to run this cmdlet in the background as a job @@ -521,7 +525,7 @@ public override void ExecuteCmdlet() AdministratorPassword = (this.AdministratorCredential != null) ? this.AdministratorCredential.Password : null, AdministratorLogin = (this.AdministratorCredential != null) ? this.AdministratorCredential.UserName : null, Tags = TagsConversionHelper.CreateTagDictionary(Tag, validate: true), - Identity = ResourceIdentityHelper.GetIdentityObjectFromType(this.AssignIdentity, this.AssignUserAssignIdentity, UserAssignedIdentity), + Identity = ResourceIdentityHelper.GetIdentityObjectFromType(this.AssignIdentity.IsPresent, this.IdentityType ?? null, UserAssignedIdentityId, null), LicenseType = this.LicenseType, // `-StorageSizeInGB 0` as a parameter to this cmdlet means "use default". // For non-MI database, we can just pass in 0 and the server will treat 0 as default. diff --git a/src/Sql/Sql/ManagedInstance/Cmdlet/SetAzureSqlManagedInstance.cs b/src/Sql/Sql/ManagedInstance/Cmdlet/SetAzureSqlManagedInstance.cs index 6df8613999a5..fd1c92c85692 100644 --- a/src/Sql/Sql/ManagedInstance/Cmdlet/SetAzureSqlManagedInstance.cs +++ b/src/Sql/Sql/ManagedInstance/Cmdlet/SetAzureSqlManagedInstance.cs @@ -223,11 +223,15 @@ public class SetAzureSqlManagedInstance : ManagedInstanceCmdletBase /// [Parameter(Mandatory = false, HelpMessage = "List of user assigned identities")] - public List UserAssignedIdentity { get; set; } + public List UserAssignedIdentityId { get; set; } + // + /// List of user assigned identities. + /// [Parameter(Mandatory = false, - HelpMessage = "Generate and assign an Azure Active Directory User Assigned Identity for this server for use with key management services like Azure KeyVault.")] - public SwitchParameter AssignUserAssignIdentity { get; set; } + HelpMessage = "Type of Identity to be used. Possible values are SystemAsssigned, UserAssigned, SystemAssignedUserAssigned and None.")] + [PSArgumentCompleter("SystemAssigned", "UserAssigned", "SystemAssignedUserAssigned", "None")] + public string IdentityType { get; set; } /// /// Gets or sets whether or not to run this cmdlet in the background as a job @@ -312,12 +316,12 @@ protected override IEnumerable ApplyUserInputToMod PublicDataEndpointEnabled = this.PublicDataEndpointEnabled, ProxyOverride = this.ProxyOverride, Tags = TagsConversionHelper.CreateTagDictionary(Tag, validate: true), - Identity = model.FirstOrDefault().Identity ?? ResourceIdentityHelper.GetIdentityObjectFromType(this.AssignIdentity, this.AssignUserAssignIdentity, UserAssignedIdentity), + Identity = ResourceIdentityHelper.GetIdentityObjectFromType(this.AssignIdentity.IsPresent, this.IdentityType ?? null, UserAssignedIdentityId, GetEntity().FirstOrDefault().Identity), InstancePoolName = this.InstancePoolName, MinimalTlsVersion = this.MinimalTlsVersion, MaintenanceConfigurationId = this.MaintenanceConfigurationId, AdministratorLogin = model.FirstOrDefault().AdministratorLogin, - PrimaryUserAssignedIdentityId = this.PrimaryUserAssignedIdentityId, + PrimaryUserAssignedIdentityId = model.FirstOrDefault().PrimaryUserAssignedIdentityId ?? this.PrimaryUserAssignedIdentityId, KeyId = this.KeyId }); return updateData; diff --git a/src/Sql/Sql/Server/Cmdlet/NewAzureSqlServer.cs b/src/Sql/Sql/Server/Cmdlet/NewAzureSqlServer.cs index 18dc897dd5b9..01c7315fdd51 100644 --- a/src/Sql/Sql/Server/Cmdlet/NewAzureSqlServer.cs +++ b/src/Sql/Sql/Server/Cmdlet/NewAzureSqlServer.cs @@ -108,11 +108,15 @@ public class NewAzureSqlServer : AzureSqlServerCmdletBase /// [Parameter(Mandatory = false, HelpMessage = "List of user assigned identities")] - public List UserAssignedIdentity { get; set; } + public List UserAssignedIdentityId { get; set; } + // + /// Type of identity to be assigned to the server.. + /// [Parameter(Mandatory = false, - HelpMessage = "Generate and assign an Azure Active Directory User Assigned Identity for this server for use with key management services like Azure KeyVault.")] - public SwitchParameter AssignUserAssignIdentity { get; set; } + HelpMessage = "Type of Identity to be used. Possible values are SystemAsssigned, UserAssigned, SystemAssignedUserAssigned and None.")] + [PSArgumentCompleter("SystemAssigned", "UserAssigned", "SystemAssignedUserAssigned", "None")] + public string IdentityType { get; set; } /// /// Gets or sets whether or not to run this cmdlet in the background as a job @@ -209,7 +213,7 @@ public override void ExecuteCmdlet() SqlAdministratorPassword = (this.SqlAdministratorCredentials != null) ? this.SqlAdministratorCredentials.Password : null, SqlAdministratorLogin = (this.SqlAdministratorCredentials != null) ? this.SqlAdministratorCredentials.UserName : null, Tags = TagsConversionHelper.CreateTagDictionary(Tags, validate: true), - Identity = ResourceIdentityHelper.GetIdentityObjectFromType(this.AssignIdentity, this.AssignUserAssignIdentity, UserAssignedIdentity), + Identity = ResourceIdentityHelper.GetIdentityObjectFromType(this.AssignIdentity.IsPresent, this.IdentityType ?? null, UserAssignedIdentityId, null), MinimalTlsVersion = this.MinimalTlsVersion, PublicNetworkAccess = this.PublicNetworkAccess, PrimaryUserAssignedIdentityId = this.PrimaryUserAssignedIdentityId, diff --git a/src/Sql/Sql/Server/Cmdlet/SetAzureSqlServer.cs b/src/Sql/Sql/Server/Cmdlet/SetAzureSqlServer.cs index facfc2d2bfb6..a178261a5bf6 100644 --- a/src/Sql/Sql/Server/Cmdlet/SetAzureSqlServer.cs +++ b/src/Sql/Sql/Server/Cmdlet/SetAzureSqlServer.cs @@ -102,11 +102,15 @@ public class SetAzureSqlServer : AzureSqlServerCmdletBase /// [Parameter(Mandatory = false, HelpMessage = "List of user assigned identities")] - public List UserAssignedIdentity { get; set; } + public List UserAssignedIdentityId { get; set; } + // + /// Type of identity to be assigned to the server.. + /// [Parameter(Mandatory = false, - HelpMessage = "Generate and assign an Azure Active Directory User Assigned Identity for this server for use with key management services like Azure KeyVault.")] - public SwitchParameter AssignUserAssignIdentity { get; set; } + HelpMessage = "Type of Identity to be used. Possible values are SystemAsssigned, UserAssigned, SystemAssignedUserAssigned and None.")] + [PSArgumentCompleter("SystemAssigned", "UserAssigned", "SystemAssignedUserAssigned", "None")] + public string IdentityType { get; set; } /// /// Defines whether it is ok to skip the requesting of rule removal confirmation @@ -145,11 +149,11 @@ public class SetAzureSqlServer : AzureSqlServerCmdletBase Tags = TagsConversionHelper.ReadOrFetchTags(this, model.FirstOrDefault().Tags), ServerVersion = this.ServerVersion, Location = model.FirstOrDefault().Location, - Identity = model.FirstOrDefault().Identity ?? ResourceIdentityHelper.GetIdentityObjectFromType(this.AssignIdentity, this.AssignUserAssignIdentity, UserAssignedIdentity), + Identity = ResourceIdentityHelper.GetIdentityObjectFromType(this.AssignIdentity.IsPresent, this.IdentityType ?? null, UserAssignedIdentityId, GetEntity().FirstOrDefault().Identity), PublicNetworkAccess = this.PublicNetworkAccess, MinimalTlsVersion = this.MinimalTlsVersion, SqlAdministratorLogin = model.FirstOrDefault().SqlAdministratorLogin, - PrimaryUserAssignedIdentityId = this.PrimaryUserAssignedIdentityId, + PrimaryUserAssignedIdentityId = model.FirstOrDefault().PrimaryUserAssignedIdentityId ?? this.PrimaryUserAssignedIdentityId, KeyId = this.KeyId }); return updateData; diff --git a/src/Sql/Sql/TransparentDataEncryption/Cmdlet/SetAzureSqlServerTransparentDataEncryptionProtector.cs b/src/Sql/Sql/TransparentDataEncryption/Cmdlet/SetAzureSqlServerTransparentDataEncryptionProtector.cs index 4841be9ab847..ed2fdb778b8a 100644 --- a/src/Sql/Sql/TransparentDataEncryption/Cmdlet/SetAzureSqlServerTransparentDataEncryptionProtector.cs +++ b/src/Sql/Sql/TransparentDataEncryption/Cmdlet/SetAzureSqlServerTransparentDataEncryptionProtector.cs @@ -55,7 +55,7 @@ public class SetAzureSqlServerTransparentDataEncryptionProtector : AzureSqlServe ValueFromPipelineByPropertyName = true, HelpMessage = "The Key Auto Rotation status")] [ValidateNotNullOrEmpty] - public SwitchParameter AutoRotationEnabled { get; set; } + public bool? AutoRotationEnabled { get; set; } /// /// Defines whether it is ok to skip the requesting of setting Transparent Data Encryption protector confirmation diff --git a/src/Sql/Sql/TransparentDataEncryption/Services/AzureSqlDatabaseTransparentDataEncryptionAdapter.cs b/src/Sql/Sql/TransparentDataEncryption/Services/AzureSqlDatabaseTransparentDataEncryptionAdapter.cs index 73830cd1265f..68af6b928a03 100644 --- a/src/Sql/Sql/TransparentDataEncryption/Services/AzureSqlDatabaseTransparentDataEncryptionAdapter.cs +++ b/src/Sql/Sql/TransparentDataEncryption/Services/AzureSqlDatabaseTransparentDataEncryptionAdapter.cs @@ -19,6 +19,7 @@ using Microsoft.Azure.Commands.Sql.TransparentDataEncryption.Model; using Microsoft.Azure.Commands.Sql.TransparentDataEncryption.Services; using Microsoft.Azure.Management.Sql.LegacySdk.Models; +using Microsoft.Azure.Management.Sql.Models; using System; using System.Collections.Generic; using System.Linq; @@ -73,13 +74,18 @@ public AzureSqlDatabaseTransparentDataEncryptionModel GetTransparentDataEncrypti /// The updated server model public AzureSqlDatabaseTransparentDataEncryptionModel UpsertTransparentDataEncryption(AzureSqlDatabaseTransparentDataEncryptionModel model) { - var resp = Communicator.CreateOrUpdate(model.ResourceGroupName, model.ServerName, model.DatabaseName, new TransparentDataEncryptionCreateOrUpdateParameters() + TransparentDataEncryptionStatus status = TransparentDataEncryptionStatus.Enabled; + + if (model.State.ToString().Equals(TransparentDataEncryptionStatus.Disabled.ToString())) { - Properties = new TransparentDataEncryptionCreateOrUpdateProperties() - { - State = model.State.ToString(), - } - }); + status = TransparentDataEncryptionStatus.Disabled; + } + + var resp = Communicator.CreateOrUpdate(model.ResourceGroupName, model.ServerName, model.DatabaseName, new Management.Sql.Models.TransparentDataEncryption() + { + Status = status + + }); ; return CreateTransparentDataEncryptionModelFromResponse(model.ResourceGroupName, model.ServerName, model.DatabaseName, resp); } @@ -103,13 +109,11 @@ public AzureSqlServerTransparentDataEncryptionProtectorModel GetEncryptionProtec /// The created or updated encryption protector model public AzureSqlServerTransparentDataEncryptionProtectorModel CreateOrUpdateEncryptionProtector(AzureSqlServerTransparentDataEncryptionProtectorModel model) { - var resp = Communicator.CreateOrUpdateEncryptionProtector(model.ResourceGroupName, model.ServerName, new EncryptionProtectorCreateOrUpdateParameters() + var resp = Communicator.CreateOrUpdateEncryptionProtector(model.ResourceGroupName, model.ServerName, new Management.Sql.Models.EncryptionProtector() { - Properties = new EncryptionProtectorCreateOrUpdateProperties() - { - ServerKeyType = model.Type.ToString(), - ServerKeyName = model.ServerKeyVaultKeyName - } + ServerKeyType = model.Type.ToString(), + ServerKeyName = model.ServerKeyVaultKeyName, + AutoRotationEnabled = model.AutoRotationEnabled }); return CreateEncryptionProtectorModelFromResponse(model.ResourceGroupName, model.ServerName, resp); } @@ -121,7 +125,7 @@ public AzureSqlServerTransparentDataEncryptionProtectorModel CreateOrUpdateEncry /// The name of the server /// The management client server response to convert /// The converted server model - private static AzureSqlDatabaseTransparentDataEncryptionModel CreateTransparentDataEncryptionModelFromResponse(string resourceGroup, string serverName, string databaseName, Management.Sql.LegacySdk.Models.TransparentDataEncryption resp) + private static AzureSqlDatabaseTransparentDataEncryptionModel CreateTransparentDataEncryptionModelFromResponse(string resourceGroup, string serverName, string databaseName, Management.Sql.Models.TransparentDataEncryption resp) { AzureSqlDatabaseTransparentDataEncryptionModel TransparentDataEncryption = new AzureSqlDatabaseTransparentDataEncryptionModel(); @@ -130,7 +134,7 @@ private static AzureSqlDatabaseTransparentDataEncryptionModel CreateTransparentD TransparentDataEncryption.DatabaseName = databaseName; TransparentDataEncryptionStateType State = TransparentDataEncryptionStateType.Disabled; - Enum.TryParse(resp.Properties.State, true, out State); + Enum.TryParse(resp.Status.ToString(), true, out State); TransparentDataEncryption.State = State; return TransparentDataEncryption; @@ -143,7 +147,7 @@ private static AzureSqlDatabaseTransparentDataEncryptionModel CreateTransparentD /// The name of the server /// The management client server response to convert /// The converted server model - private static AzureSqlDatabaseTransparentDataEncryptionActivityModel CreateTransparentDataEncryptionActivityModelFromResponse(string resourceGroup, string serverName, string databaseName, Management.Sql.LegacySdk.Models.TransparentDataEncryptionActivity resp) + private static AzureSqlDatabaseTransparentDataEncryptionActivityModel CreateTransparentDataEncryptionActivityModelFromResponse(string resourceGroup, string serverName, string databaseName, Management.Sql.Models.TransparentDataEncryptionActivity resp) { AzureSqlDatabaseTransparentDataEncryptionActivityModel TransparentDataEncryptionActivity = new AzureSqlDatabaseTransparentDataEncryptionActivityModel(); @@ -152,9 +156,9 @@ private static AzureSqlDatabaseTransparentDataEncryptionActivityModel CreateTran TransparentDataEncryptionActivity.DatabaseName = databaseName; TransparentDataEncryptionActivityStatusType status = TransparentDataEncryptionActivityStatusType.Decrypting; - Enum.TryParse(resp.Properties.Status, true, out status); + Enum.TryParse(resp.Status, true, out status); TransparentDataEncryptionActivity.Status = status; - TransparentDataEncryptionActivity.PercentComplete = resp.Properties.PercentComplete; + TransparentDataEncryptionActivity.PercentComplete = (float)resp.PercentComplete; return TransparentDataEncryptionActivity; } @@ -185,20 +189,20 @@ internal IList ListTrans /// The name of the server /// The management client server response to convert /// The converted server model - private static AzureSqlServerTransparentDataEncryptionProtectorModel CreateEncryptionProtectorModelFromResponse(string resourceGroup, string serverName, EncryptionProtector resp) + private static AzureSqlServerTransparentDataEncryptionProtectorModel CreateEncryptionProtectorModelFromResponse(string resourceGroup, string serverName, Management.Sql.Models.EncryptionProtector resp) { AzureSqlServerTransparentDataEncryptionProtectorModel EncryptionProtector = new AzureSqlServerTransparentDataEncryptionProtectorModel(); EncryptionProtector.ResourceGroupName = resourceGroup; EncryptionProtector.ServerName = serverName; - EncryptionProtector.ServerKeyVaultKeyName = resp.Properties.ServerKeyName; + EncryptionProtector.ServerKeyVaultKeyName = resp.ServerKeyName; Model.EncryptionProtectorType type = Model.EncryptionProtectorType.ServiceManaged; - Enum.TryParse(resp.Properties.ServerKeyType, true, out type); + Enum.TryParse(resp.ServerKeyType, true, out type); EncryptionProtector.Type = type; - EncryptionProtector.AutoRotationEnabled = resp.Properties.AutoKeyRotationEnabled; + EncryptionProtector.AutoRotationEnabled = resp.AutoRotationEnabled; if (type == Model.EncryptionProtectorType.AzureKeyVault) { - EncryptionProtector.KeyId = resp.Properties.Uri; + EncryptionProtector.KeyId = resp.Uri; } return EncryptionProtector; diff --git a/src/Sql/Sql/TransparentDataEncryption/Services/AzureSqlDatabaseTransparentDataEncryptionCommunicator.cs b/src/Sql/Sql/TransparentDataEncryption/Services/AzureSqlDatabaseTransparentDataEncryptionCommunicator.cs index efcfa14f50b0..73f12a347e0d 100644 --- a/src/Sql/Sql/TransparentDataEncryption/Services/AzureSqlDatabaseTransparentDataEncryptionCommunicator.cs +++ b/src/Sql/Sql/TransparentDataEncryption/Services/AzureSqlDatabaseTransparentDataEncryptionCommunicator.cs @@ -14,8 +14,9 @@ using Microsoft.Azure.Commands.Common.Authentication; using Microsoft.Azure.Commands.Common.Authentication.Abstractions; -using Microsoft.Azure.Management.Sql.LegacySdk; -using Microsoft.Azure.Management.Sql.LegacySdk.Models; +//using Microsoft.Azure.Management.Sql.LegacySdk; +//using Microsoft.Azure.Management.Sql.LegacySdk.Models; +using Microsoft.Azure.Management.Sql; using System.Collections.Generic; namespace Microsoft.Azure.Commands.Sql.TransparentDataEncryption.Services @@ -57,41 +58,41 @@ public AzureSqlDatabaseTransparentDataEncryptionCommunicator(IAzureContext conte /// /// Gets the Azure Sql Database Transparent Data Encryption /// - public Management.Sql.LegacySdk.Models.TransparentDataEncryption Get(string resourceGroupName, string serverName, string databaseName) + public Management.Sql.Models.TransparentDataEncryption Get(string resourceGroupName, string serverName, string databaseName) { - return GetCurrentSqlClient().TransparentDataEncryption.Get(resourceGroupName, serverName, databaseName).TransparentDataEncryption; + return GetCurrentSqlClient().TransparentDataEncryptions.Get(resourceGroupName, serverName, databaseName); } /// /// Creates or updates an Azure Sql Database Transparent Data Encryption /// - public Management.Sql.LegacySdk.Models.TransparentDataEncryption CreateOrUpdate(string resourceGroupName, string serverName, string databaseName, TransparentDataEncryptionCreateOrUpdateParameters parameters) + public Management.Sql.Models.TransparentDataEncryption CreateOrUpdate(string resourceGroupName, string serverName, string databaseName, Management.Sql.Models.TransparentDataEncryption parameters) { - return GetCurrentSqlClient().TransparentDataEncryption.CreateOrUpdate(resourceGroupName, serverName, databaseName, parameters).TransparentDataEncryption; + return GetCurrentSqlClient().TransparentDataEncryptions.CreateOrUpdate(resourceGroupName, serverName, databaseName, parameters); } /// /// Gets Azure Sql Database Transparent Data Encryption Activity /// - public IList ListActivity(string resourceGroupName, string serverName, string databaseName) + public IEnumerable ListActivity(string resourceGroupName, string serverName, string databaseName) { - return GetCurrentSqlClient().TransparentDataEncryption.ListActivity(resourceGroupName, serverName, databaseName).TransparentDataEncryptionActivities; + return GetCurrentSqlClient().TransparentDataEncryptionActivities.ListByConfiguration(resourceGroupName, serverName, databaseName); } /// /// Gets Azure Sql Database Transparent Data Encryption Protector /// - public Management.Sql.LegacySdk.Models.EncryptionProtector GetEncryptionProtector(string resourceGroupName, string serverName) + public Management.Sql.Models.EncryptionProtector GetEncryptionProtector(string resourceGroupName, string serverName) { - return GetCurrentSqlClient().TransparentDataEncryption.GetEncryptionProtector(resourceGroupName, serverName).EncryptionProtector; + return GetCurrentSqlClient().EncryptionProtectors.Get(resourceGroupName, serverName); } /// /// Creates or updates an Azure Sql Database Transparent Data Encryption Protector /// - public Management.Sql.LegacySdk.Models.EncryptionProtector CreateOrUpdateEncryptionProtector(string resourceGroupName, string serverName, EncryptionProtectorCreateOrUpdateParameters parameters) + public Management.Sql.Models.EncryptionProtector CreateOrUpdateEncryptionProtector(string resourceGroupName, string serverName, Management.Sql.Models.EncryptionProtector parameters) { - return GetCurrentSqlClient().TransparentDataEncryption.CreateOrUpdateEncryptionProtector(resourceGroupName, serverName, parameters).EncryptionProtector; + return GetCurrentSqlClient().EncryptionProtectors.CreateOrUpdate(resourceGroupName, serverName, parameters); } /// @@ -104,7 +105,7 @@ private SqlManagementClient GetCurrentSqlClient() // Get the SQL management client for the current subscription if (SqlClient == null) { - SqlClient = AzureSession.Instance.ClientFactory.CreateClient(Context, AzureEnvironment.Endpoint.ResourceManager); + SqlClient = AzureSession.Instance.ClientFactory.CreateArmClient(Context, AzureEnvironment.Endpoint.ResourceManager); } return SqlClient; }