diff --git a/src/Sql/Sql.LegacySdk/Generated/Models/EncryptionProtectorCreateOrUpdateProperties.cs b/src/Sql/Sql.LegacySdk/Generated/Models/EncryptionProtectorCreateOrUpdateProperties.cs index 0adab03f825e..cf0e31d8c22f 100644 --- a/src/Sql/Sql.LegacySdk/Generated/Models/EncryptionProtectorCreateOrUpdateProperties.cs +++ b/src/Sql/Sql.LegacySdk/Generated/Models/EncryptionProtectorCreateOrUpdateProperties.cs @@ -53,7 +53,7 @@ public string ServerKeyType get { return this._serverKeyType; } set { this._serverKeyType = value; } } - + /// /// Initializes a new instance of the /// EncryptionProtectorCreateOrUpdateProperties class. diff --git a/src/Sql/Sql/Auditing/Services/AuditingEndpointsCommunicator.cs b/src/Sql/Sql/Auditing/Services/AuditingEndpointsCommunicator.cs index 20f52cc0d210..7e6a105e14b1 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); + server.Identity = ResourceIdentityHelper.GetIdentityObjectFromType(server.Identity.Type, 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 ab5a69c56034..9c45c0bc3327 100644 --- a/src/Sql/Sql/Common/ResourceIdentityHelper.cs +++ b/src/Sql/Sql/Common/ResourceIdentityHelper.cs @@ -12,7 +12,10 @@ // limitations under the License. // ---------------------------------------------------------------------------------- +using Microsoft.Azure.Management.Sql.Models; using System.Collections.Generic; +using System.Linq; +using System.Runtime.CompilerServices; namespace Microsoft.Azure.Commands.Sql.Common { @@ -24,30 +27,35 @@ public enum ResourceIdentityType } public class ResourceIdentityHelper - { - public static Management.Sql.Models.ResourceIdentity GetSystemAssignedIdentity() + { + public static Management.Sql.Models.ResourceIdentity GetIdentityObjectFromType(string AssignIdentity, List userAssignedIdentities) { Management.Sql.Models.ResourceIdentity identityResult = null; - - identityResult = new Management.Sql.Models.ResourceIdentity() + + if (AssignIdentity.Equals(ResourceIdentityType.SystemAssigned)) { - Type = ResourceIdentityType.SystemAssigned.ToString() - }; - - return identityResult; - } + identityResult = new Management.Sql.Models.ResourceIdentity() + { + Type = ResourceIdentityType.SystemAssigned.ToString() + }; + } - public static Management.Sql.Models.ResourceIdentity GetUserAssignedIdentity(List userAssignedIdentities) - { - Management.Sql.Models.ResourceIdentity identityResult = null; - - identityResult = new Management.Sql.Models.ResourceIdentity() + if (AssignIdentity.Equals(ResourceIdentityType.UserAssigned) && userAssignedIdentities.Any()) { - Type = ResourceIdentityType.UserAssigned.ToString(), - // TODO - // Add user assigned identities. - }; - + Dictionary umiDict = new Dictionary(); + + foreach (string identity in userAssignedIdentities) + { + umiDict.Add(identity, new UserIdentity()); + } + + identityResult = new Management.Sql.Models.ResourceIdentity() + { + Type = ResourceIdentityType.UserAssigned.ToString(), + UserAssignedIdentities = umiDict + }; + } + return identityResult; } } diff --git a/src/Sql/Sql/ManagedInstance/Cmdlet/NewAzureSqlManagedInstance.cs b/src/Sql/Sql/ManagedInstance/Cmdlet/NewAzureSqlManagedInstance.cs index dee40495748e..5d889cd78261 100644 --- a/src/Sql/Sql/ManagedInstance/Cmdlet/NewAzureSqlManagedInstance.cs +++ b/src/Sql/Sql/ManagedInstance/Cmdlet/NewAzureSqlManagedInstance.cs @@ -486,7 +486,7 @@ public override void ExecuteCmdlet() AdministratorLogin = this.AdministratorCredential.UserName, AdministratorPassword = this.AdministratorCredential.Password, Tags = TagsConversionHelper.CreateTagDictionary(Tag, validate: true), - Identity = this.AssignIdentity.Equals(ResourceIdentityType.SystemAssigned) ? ResourceIdentityHelper.GetSystemAssignedIdentity() : ResourceIdentityHelper.GetUserAssignedIdentity(this.UserAssignedIdentities), + Identity = ResourceIdentityHelper.GetIdentityObjectFromType(this.AssignIdentity.IsPresent ? this.AssignIdentity.ToString() : null, UserAssignedIdentities ?? 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 572887765151..65c3adc43883 100644 --- a/src/Sql/Sql/ManagedInstance/Cmdlet/SetAzureSqlManagedInstance.cs +++ b/src/Sql/Sql/ManagedInstance/Cmdlet/SetAzureSqlManagedInstance.cs @@ -308,7 +308,7 @@ protected override IEnumerable ApplyUserInputToMod PublicDataEndpointEnabled = this.PublicDataEndpointEnabled, ProxyOverride = this.ProxyOverride, Tags = TagsConversionHelper.CreateTagDictionary(Tag, validate: true), - Identity = this.AssignIdentity.Equals(ResourceIdentityType.SystemAssigned) ? ResourceIdentityHelper.GetSystemAssignedIdentity() : ResourceIdentityHelper.GetUserAssignedIdentity(this.UserAssignedIdentities), + Identity = model.FirstOrDefault().Identity ?? ResourceIdentityHelper.GetIdentityObjectFromType(this.AssignIdentity.IsPresent ? this.AssignIdentity.ToString() : null, UserAssignedIdentities ?? null), InstancePoolName = this.InstancePoolName, MinimalTlsVersion = this.MinimalTlsVersion, MaintenanceConfigurationId = this.MaintenanceConfigurationId, diff --git a/src/Sql/Sql/Server/Cmdlet/NewAzureSqlServer.cs b/src/Sql/Sql/Server/Cmdlet/NewAzureSqlServer.cs index ed6410294f19..35ef7d0a939a 100644 --- a/src/Sql/Sql/Server/Cmdlet/NewAzureSqlServer.cs +++ b/src/Sql/Sql/Server/Cmdlet/NewAzureSqlServer.cs @@ -174,11 +174,12 @@ public override void ExecuteCmdlet() SqlAdministratorPassword = this.SqlAdministratorCredentials.Password, SqlAdministratorLogin = this.SqlAdministratorCredentials.UserName, Tags = TagsConversionHelper.CreateTagDictionary(Tags, validate: true), - Identity = this.AssignIdentity.Equals(ResourceIdentityType.SystemAssigned) ? ResourceIdentityHelper.GetSystemAssignedIdentity() : ResourceIdentityHelper.GetUserAssignedIdentity(this.UserAssignedIdentities), + Identity = ResourceIdentityHelper.GetIdentityObjectFromType(this.AssignIdentity.IsPresent ? this.AssignIdentity.ToString() : null, UserAssignedIdentities ?? null), MinimalTlsVersion = this.MinimalTlsVersion, PublicNetworkAccess = this.PublicNetworkAccess, PrimaryUserAssignedIdentityId = this.PrimaryUserAssignedIdentityId, - KeyId = this.KeyId + KeyId = this.KeyId, + }); return newEntity; } diff --git a/src/Sql/Sql/Server/Cmdlet/SetAzureSqlServer.cs b/src/Sql/Sql/Server/Cmdlet/SetAzureSqlServer.cs index 73d882839081..c2b799bb8e97 100644 --- a/src/Sql/Sql/Server/Cmdlet/SetAzureSqlServer.cs +++ b/src/Sql/Sql/Server/Cmdlet/SetAzureSqlServer.cs @@ -141,7 +141,7 @@ public class SetAzureSqlServer : AzureSqlServerCmdletBase Tags = TagsConversionHelper.ReadOrFetchTags(this, model.FirstOrDefault().Tags), ServerVersion = this.ServerVersion, Location = model.FirstOrDefault().Location, - Identity = this.AssignIdentity.Equals(ResourceIdentityType.SystemAssigned) ? ResourceIdentityHelper.GetSystemAssignedIdentity() : ResourceIdentityHelper.GetUserAssignedIdentity(this.UserAssignedIdentities), + Identity = model.FirstOrDefault().Identity ?? ResourceIdentityHelper.GetIdentityObjectFromType(this.AssignIdentity.IsPresent ? this.AssignIdentity.ToString() : null, UserAssignedIdentities ?? null), PublicNetworkAccess = this.PublicNetworkAccess, MinimalTlsVersion = this.MinimalTlsVersion, PrimaryUserAssignedIdentityId = this.PrimaryUserAssignedIdentityId,