Skip to content

Commit

Permalink
Add UMI. Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
viparek committed May 29, 2021
1 parent 9b775f1 commit 8a2a14a
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public string Uri
/// Optional. Gets or sets the Azure Sql Server Encryption
/// Protector Key Rotation Status
/// </summary>
public bool? AutoRotationEnabled
public bool? AutoKeyRotationEnabled
{
get { return this._isAutoRotationEnabled; }
set { this._isAutoRotationEnabled = value; }
Expand Down
32 changes: 24 additions & 8 deletions src/Sql/Sql/Common/ResourceIdentityHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,41 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using System.Collections.Generic;

namespace Microsoft.Azure.Commands.Sql.Common
{
public enum ResourceIdentityType
{
SystemAssigned
SystemAssigned,
UserAssigned,
None
}

public class ResourceIdentityHelper
{
public static Management.Sql.Models.ResourceIdentity GetIdentityObjectFromType(bool assignIdentityIsPresent)
public static Management.Sql.Models.ResourceIdentity GetSystemAssignedIdentity()
{
Management.Sql.Models.ResourceIdentity identityResult = null;

identityResult = new Management.Sql.Models.ResourceIdentity()
{
Type = ResourceIdentityType.SystemAssigned.ToString()
};

return identityResult;
}

public static Management.Sql.Models.ResourceIdentity GetUserAssignedIdentity(List<string> userAssignedIdentities)
{
Management.Sql.Models.ResourceIdentity identityResult = null;
if (assignIdentityIsPresent)

identityResult = new Management.Sql.Models.ResourceIdentity()
{
identityResult = new Management.Sql.Models.ResourceIdentity()
{
Type = ResourceIdentityType.SystemAssigned.ToString()
};
}
Type = ResourceIdentityType.UserAssigned.ToString(),
// TODO
// Add user assigned identities.
};

return identityResult;
}
Expand Down
13 changes: 10 additions & 3 deletions src/Sql/Sql/ManagedInstance/Cmdlet/NewAzureSqlManagedInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -327,16 +327,23 @@ public class NewAzureSqlManagedInstance : ManagedInstanceCmdletBase
/// Id of the primary user assigned identity
/// </summary>
[Parameter(Mandatory = false,
HelpMessage = "The primary user assigned identity id")]
HelpMessage = "The primary user managed identity(UMI) id")]
public string PrimaryUserAssignedIdentityId { get; set; }

/// <summary>
/// URI of the key to use for encryption
/// </summary>
[Parameter(Mandatory = false,
HelpMessage = "URI of the key to use for encryption")]
HelpMessage = "The Key Vault URI for encryption")]
public string KeyId { get; set; }

// <summary>
/// List of user assigned identities.
/// </summary>
[Parameter(Mandatory = false,
HelpMessage = "List of user assigned identities")]
public List<string> UserAssignedIdentities { get; set; }

/// <summary>
/// Gets or sets whether or not to run this cmdlet in the background as a job
/// </summary>
Expand Down Expand Up @@ -479,7 +486,7 @@ public override void ExecuteCmdlet()
AdministratorLogin = this.AdministratorCredential.UserName,
AdministratorPassword = this.AdministratorCredential.Password,
Tags = TagsConversionHelper.CreateTagDictionary(Tag, validate: true),
Identity = ResourceIdentityHelper.GetIdentityObjectFromType(this.AssignIdentity.IsPresent),
Identity = this.AssignIdentity.Equals(ResourceIdentityType.SystemAssigned) ? ResourceIdentityHelper.GetSystemAssignedIdentity() : ResourceIdentityHelper.GetUserAssignedIdentity(this.UserAssignedIdentities),
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.
Expand Down
13 changes: 10 additions & 3 deletions src/Sql/Sql/ManagedInstance/Cmdlet/SetAzureSqlManagedInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,14 @@ public class SetAzureSqlManagedInstance : ManagedInstanceCmdletBase
/// Id of the primary user assigned identity
/// </summary>
[Parameter(Mandatory = false,
HelpMessage = "The primary user assigned identity id")]
HelpMessage = "The primary user managed identity(UMI) id")]
public string PrimaryUserAssignedIdentityId { get; set; }

/// <summary>
/// URI of the key to use for encryption
/// </summary>
[Parameter(Mandatory = false,
HelpMessage = "URI of the key to use for encryption")]
HelpMessage = "The Key Vault URI for encryption")]
public string KeyId { get; set; }

/// <summary>
Expand All @@ -218,6 +218,13 @@ public class SetAzureSqlManagedInstance : ManagedInstanceCmdletBase
HelpMessage = "The Maintenance configuration id for the Sql Azure Managed Instance.")]
public string MaintenanceConfigurationId { get; set; }

// <summary>
/// List of user assigned identities.
/// </summary>
[Parameter(Mandatory = false,
HelpMessage = "List of user assigned identities")]
public List<string> UserAssignedIdentities { get; set; }

/// <summary>
/// Gets or sets whether or not to run this cmdlet in the background as a job
/// </summary>
Expand Down Expand Up @@ -301,7 +308,7 @@ protected override IEnumerable<AzureSqlManagedInstanceModel> ApplyUserInputToMod
PublicDataEndpointEnabled = this.PublicDataEndpointEnabled,
ProxyOverride = this.ProxyOverride,
Tags = TagsConversionHelper.CreateTagDictionary(Tag, validate: true),
Identity = model.FirstOrDefault().Identity ?? ResourceIdentityHelper.GetIdentityObjectFromType(this.AssignIdentity.IsPresent),
Identity = this.AssignIdentity.Equals(ResourceIdentityType.SystemAssigned) ? ResourceIdentityHelper.GetSystemAssignedIdentity() : ResourceIdentityHelper.GetUserAssignedIdentity(this.UserAssignedIdentities),
InstancePoolName = this.InstancePoolName,
MinimalTlsVersion = this.MinimalTlsVersion,
MaintenanceConfigurationId = this.MaintenanceConfigurationId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ private AzureReplicationLinkModel CreateReplicationLinkModelFromResponse(string
model.ServerName = serverName;
model.DatabaseName = databaseName;
model.AllowConnections = allowConnections;
model.Location = resp.Location;
model.Location = resp.PartnerLocation;
model.PartnerLocation = resp.PartnerLocation;
model.PercentComplete = resp.PercentComplete.ToString();
model.ReplicationState = resp.ReplicationState;
Expand Down
13 changes: 10 additions & 3 deletions src/Sql/Sql/Server/Cmdlet/NewAzureSqlServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,23 @@ public class NewAzureSqlServer : AzureSqlServerCmdletBase
/// Id of the primary user assigned identity
/// </summary>
[Parameter(Mandatory = false,
HelpMessage = "The primary user assigned identity id")]
HelpMessage = "The primary user managed identity(UMI) id")]
public string PrimaryUserAssignedIdentityId { get; set; }

/// <summary>
/// URI of the key to use for encryption
/// </summary>
[Parameter(Mandatory = false,
HelpMessage = "URI of the key to use for encryption")]
HelpMessage = "The Key Vault URI for encryption")]
public string KeyId { get; set; }

// <summary>
/// List of user assigned identities.
/// </summary>
[Parameter(Mandatory = false,
HelpMessage = "List of user assigned identities")]
public List<string> UserAssignedIdentities { get; set; }

/// <summary>
/// Gets or sets whether or not to run this cmdlet in the background as a job
/// </summary>
Expand Down Expand Up @@ -167,7 +174,7 @@ public override void ExecuteCmdlet()
SqlAdministratorPassword = this.SqlAdministratorCredentials.Password,
SqlAdministratorLogin = this.SqlAdministratorCredentials.UserName,
Tags = TagsConversionHelper.CreateTagDictionary(Tags, validate: true),
Identity = ResourceIdentityHelper.GetIdentityObjectFromType(this.AssignIdentity.IsPresent),
Identity = this.AssignIdentity.Equals(ResourceIdentityType.SystemAssigned) ? ResourceIdentityHelper.GetSystemAssignedIdentity() : ResourceIdentityHelper.GetUserAssignedIdentity(this.UserAssignedIdentities),
MinimalTlsVersion = this.MinimalTlsVersion,
PublicNetworkAccess = this.PublicNetworkAccess,
PrimaryUserAssignedIdentityId = this.PrimaryUserAssignedIdentityId,
Expand Down
13 changes: 10 additions & 3 deletions src/Sql/Sql/Server/Cmdlet/SetAzureSqlServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,23 @@ public class SetAzureSqlServer : AzureSqlServerCmdletBase
/// Id of the primary user assigned identity
/// </summary>
[Parameter(Mandatory = false,
HelpMessage = "The primary user assigned identity id")]
HelpMessage = "The primary user managed identity(UMI) id")]
public string PrimaryUserAssignedIdentityId { get; set; }

/// <summary>
/// URI of the key to use for encryption
/// </summary>
[Parameter(Mandatory = false,
HelpMessage = "URI of the key to use for encryption")]
HelpMessage = "The Key Vault URI for encryption")]
public string KeyId { get; set; }

// <summary>
/// List of user assigned identities.
/// </summary>
[Parameter(Mandatory = false,
HelpMessage = "List of user assigned identities")]
public List<string> UserAssignedIdentities { get; set; }

/// <summary>
/// Defines whether it is ok to skip the requesting of rule removal confirmation
/// </summary>
Expand Down Expand Up @@ -134,7 +141,7 @@ 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.IsPresent),
Identity = this.AssignIdentity.Equals(ResourceIdentityType.SystemAssigned) ? ResourceIdentityHelper.GetSystemAssignedIdentity() : ResourceIdentityHelper.GetUserAssignedIdentity(this.UserAssignedIdentities),
PublicNetworkAccess = this.PublicNetworkAccess,
MinimalTlsVersion = this.MinimalTlsVersion,
PrimaryUserAssignedIdentityId = this.PrimaryUserAssignedIdentityId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ private static AzureSqlServerTransparentDataEncryptionProtectorModel CreateEncry
Model.EncryptionProtectorType type = Model.EncryptionProtectorType.ServiceManaged;
Enum.TryParse<Model.EncryptionProtectorType>(resp.Properties.ServerKeyType, true, out type);
EncryptionProtector.Type = type;
EncryptionProtector.AutoRotationEnabled = resp.Properties.AutoRotationEnabled;
EncryptionProtector.AutoRotationEnabled = resp.Properties.AutoKeyRotationEnabled;

if (type == Model.EncryptionProtectorType.AzureKeyVault)
{
Expand Down

0 comments on commit 8a2a14a

Please sign in to comment.