Skip to content

Commit a22f115

Browse files
committed
Add UMI. Address comments
1 parent a5e9fed commit a22f115

File tree

8 files changed

+67
-23
lines changed

8 files changed

+67
-23
lines changed

src/Sql/Sql.LegacySdk/Generated/Models/EncryptionProtectorProperties.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public string Uri
6969
/// Optional. Gets or sets the Azure Sql Server Encryption
7070
/// Protector Key Rotation Status
7171
/// </summary>
72-
public bool? AutoRotationEnabled
72+
public bool? AutoKeyRotationEnabled
7373
{
7474
get { return this._isAutoRotationEnabled; }
7575
set { this._isAutoRotationEnabled = value; }

src/Sql/Sql/Common/ResourceIdentityHelper.cs

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,41 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using System.Collections.Generic;
16+
1517
namespace Microsoft.Azure.Commands.Sql.Common
1618
{
1719
public enum ResourceIdentityType
1820
{
19-
SystemAssigned
21+
SystemAssigned,
22+
UserAssigned,
23+
None
2024
}
2125

2226
public class ResourceIdentityHelper
2327
{
24-
public static Management.Sql.Models.ResourceIdentity GetIdentityObjectFromType(bool assignIdentityIsPresent)
28+
public static Management.Sql.Models.ResourceIdentity GetSystemAssignedIdentity()
29+
{
30+
Management.Sql.Models.ResourceIdentity identityResult = null;
31+
32+
identityResult = new Management.Sql.Models.ResourceIdentity()
33+
{
34+
Type = ResourceIdentityType.SystemAssigned.ToString()
35+
};
36+
37+
return identityResult;
38+
}
39+
40+
public static Management.Sql.Models.ResourceIdentity GetUserAssignedIdentity(List<string> userAssignedIdentities)
2541
{
2642
Management.Sql.Models.ResourceIdentity identityResult = null;
27-
if (assignIdentityIsPresent)
43+
44+
identityResult = new Management.Sql.Models.ResourceIdentity()
2845
{
29-
identityResult = new Management.Sql.Models.ResourceIdentity()
30-
{
31-
Type = ResourceIdentityType.SystemAssigned.ToString()
32-
};
33-
}
46+
Type = ResourceIdentityType.UserAssigned.ToString(),
47+
// TODO
48+
// Add user assigned identities.
49+
};
3450

3551
return identityResult;
3652
}

src/Sql/Sql/ManagedInstance/Cmdlet/NewAzureSqlManagedInstance.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,16 +327,23 @@ public class NewAzureSqlManagedInstance : ManagedInstanceCmdletBase
327327
/// Id of the primary user assigned identity
328328
/// </summary>
329329
[Parameter(Mandatory = false,
330-
HelpMessage = "The primary user assigned identity id")]
330+
HelpMessage = "The primary user managed identity(UMI) id")]
331331
public string PrimaryUserAssignedIdentityId { get; set; }
332332

333333
/// <summary>
334334
/// URI of the key to use for encryption
335335
/// </summary>
336336
[Parameter(Mandatory = false,
337-
HelpMessage = "URI of the key to use for encryption")]
337+
HelpMessage = "The Key Vault URI for encryption")]
338338
public string KeyId { get; set; }
339339

340+
// <summary>
341+
/// List of user assigned identities.
342+
/// </summary>
343+
[Parameter(Mandatory = false,
344+
HelpMessage = "List of user assigned identities")]
345+
public List<string> UserAssignedIdentities { get; set; }
346+
340347
/// <summary>
341348
/// Gets or sets whether or not to run this cmdlet in the background as a job
342349
/// </summary>
@@ -510,7 +517,7 @@ public override void ExecuteCmdlet()
510517
AdministratorPassword = (this.AdministratorCredential != null) ? this.AdministratorCredential.Password : null,
511518
AdministratorLogin = (this.AdministratorCredential != null) ? this.AdministratorCredential.UserName : null,
512519
Tags = TagsConversionHelper.CreateTagDictionary(Tag, validate: true),
513-
Identity = ResourceIdentityHelper.GetIdentityObjectFromType(this.AssignIdentity.IsPresent),
520+
Identity = this.AssignIdentity.Equals(ResourceIdentityType.SystemAssigned) ? ResourceIdentityHelper.GetSystemAssignedIdentity() : ResourceIdentityHelper.GetUserAssignedIdentity(this.UserAssignedIdentities),
514521
LicenseType = this.LicenseType,
515522
// `-StorageSizeInGB 0` as a parameter to this cmdlet means "use default".
516523
// For non-MI database, we can just pass in 0 and the server will treat 0 as default.

src/Sql/Sql/ManagedInstance/Cmdlet/SetAzureSqlManagedInstance.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,14 @@ public class SetAzureSqlManagedInstance : ManagedInstanceCmdletBase
186186
/// Id of the primary user assigned identity
187187
/// </summary>
188188
[Parameter(Mandatory = false,
189-
HelpMessage = "The primary user assigned identity id")]
189+
HelpMessage = "The primary user managed identity(UMI) id")]
190190
public string PrimaryUserAssignedIdentityId { get; set; }
191191

192192
/// <summary>
193193
/// URI of the key to use for encryption
194194
/// </summary>
195195
[Parameter(Mandatory = false,
196-
HelpMessage = "URI of the key to use for encryption")]
196+
HelpMessage = "The Key Vault URI for encryption")]
197197
public string KeyId { get; set; }
198198

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

221+
// <summary>
222+
/// List of user assigned identities.
223+
/// </summary>
224+
[Parameter(Mandatory = false,
225+
HelpMessage = "List of user assigned identities")]
226+
public List<string> UserAssignedIdentities { get; set; }
227+
221228
/// <summary>
222229
/// Gets or sets whether or not to run this cmdlet in the background as a job
223230
/// </summary>
@@ -301,7 +308,7 @@ protected override IEnumerable<AzureSqlManagedInstanceModel> ApplyUserInputToMod
301308
PublicDataEndpointEnabled = this.PublicDataEndpointEnabled,
302309
ProxyOverride = this.ProxyOverride,
303310
Tags = TagsConversionHelper.CreateTagDictionary(Tag, validate: true),
304-
Identity = model.FirstOrDefault().Identity ?? ResourceIdentityHelper.GetIdentityObjectFromType(this.AssignIdentity.IsPresent),
311+
Identity = this.AssignIdentity.Equals(ResourceIdentityType.SystemAssigned) ? ResourceIdentityHelper.GetSystemAssignedIdentity() : ResourceIdentityHelper.GetUserAssignedIdentity(this.UserAssignedIdentities),
305312
InstancePoolName = this.InstancePoolName,
306313
MinimalTlsVersion = this.MinimalTlsVersion,
307314
MaintenanceConfigurationId = this.MaintenanceConfigurationId,

src/Sql/Sql/Replication/Services/AzureSqlDatabaseReplicationAdapter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ private AzureReplicationLinkModel CreateReplicationLinkModelFromResponse(string
393393
model.ServerName = serverName;
394394
model.DatabaseName = databaseName;
395395
model.AllowConnections = allowConnections;
396-
model.Location = GetServerLocation(resourceGroupName, serverName);
396+
model.Location = resp.Location;
397397
model.PartnerLocation = resp.PartnerLocation;
398398
model.PercentComplete = resp.PercentComplete.ToString();
399399
model.ReplicationState = resp.ReplicationState;

src/Sql/Sql/Server/Cmdlet/NewAzureSqlServer.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,23 @@ public class NewAzureSqlServer : AzureSqlServerCmdletBase
9393
/// Id of the primary user assigned identity
9494
/// </summary>
9595
[Parameter(Mandatory = false,
96-
HelpMessage = "The primary user assigned identity id")]
96+
HelpMessage = "The primary user managed identity(UMI) id")]
9797
public string PrimaryUserAssignedIdentityId { get; set; }
9898

9999
/// <summary>
100100
/// URI of the key to use for encryption
101101
/// </summary>
102102
[Parameter(Mandatory = false,
103-
HelpMessage = "URI of the key to use for encryption")]
103+
HelpMessage = "The Key Vault URI for encryption")]
104104
public string KeyId { get; set; }
105105

106+
// <summary>
107+
/// List of user assigned identities.
108+
/// </summary>
109+
[Parameter(Mandatory = false,
110+
HelpMessage = "List of user assigned identities")]
111+
public List<string> UserAssignedIdentities { get; set; }
112+
106113
/// <summary>
107114
/// Gets or sets whether or not to run this cmdlet in the background as a job
108115
/// </summary>
@@ -198,7 +205,7 @@ public override void ExecuteCmdlet()
198205
SqlAdministratorPassword = (this.SqlAdministratorCredentials != null) ? this.SqlAdministratorCredentials.Password : null,
199206
SqlAdministratorLogin = (this.SqlAdministratorCredentials != null) ? this.SqlAdministratorCredentials.UserName : null,
200207
Tags = TagsConversionHelper.CreateTagDictionary(Tags, validate: true),
201-
Identity = ResourceIdentityHelper.GetIdentityObjectFromType(this.AssignIdentity.IsPresent),
208+
Identity = this.AssignIdentity.Equals(ResourceIdentityType.SystemAssigned) ? ResourceIdentityHelper.GetSystemAssignedIdentity() : ResourceIdentityHelper.GetUserAssignedIdentity(this.UserAssignedIdentities),
202209
MinimalTlsVersion = this.MinimalTlsVersion,
203210
PublicNetworkAccess = this.PublicNetworkAccess,
204211
PrimaryUserAssignedIdentityId = this.PrimaryUserAssignedIdentityId,

src/Sql/Sql/Server/Cmdlet/SetAzureSqlServer.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,23 @@ public class SetAzureSqlServer : AzureSqlServerCmdletBase
8787
/// Id of the primary user assigned identity
8888
/// </summary>
8989
[Parameter(Mandatory = false,
90-
HelpMessage = "The primary user assigned identity id")]
90+
HelpMessage = "The primary user managed identity(UMI) id")]
9191
public string PrimaryUserAssignedIdentityId { get; set; }
9292

9393
/// <summary>
9494
/// URI of the key to use for encryption
9595
/// </summary>
9696
[Parameter(Mandatory = false,
97-
HelpMessage = "URI of the key to use for encryption")]
97+
HelpMessage = "The Key Vault URI for encryption")]
9898
public string KeyId { get; set; }
9999

100+
// <summary>
101+
/// List of user assigned identities.
102+
/// </summary>
103+
[Parameter(Mandatory = false,
104+
HelpMessage = "List of user assigned identities")]
105+
public List<string> UserAssignedIdentities { get; set; }
106+
100107
/// <summary>
101108
/// Defines whether it is ok to skip the requesting of rule removal confirmation
102109
/// </summary>
@@ -134,7 +141,7 @@ public class SetAzureSqlServer : AzureSqlServerCmdletBase
134141
Tags = TagsConversionHelper.ReadOrFetchTags(this, model.FirstOrDefault().Tags),
135142
ServerVersion = this.ServerVersion,
136143
Location = model.FirstOrDefault().Location,
137-
Identity = model.FirstOrDefault().Identity ?? ResourceIdentityHelper.GetIdentityObjectFromType(this.AssignIdentity.IsPresent),
144+
Identity = this.AssignIdentity.Equals(ResourceIdentityType.SystemAssigned) ? ResourceIdentityHelper.GetSystemAssignedIdentity() : ResourceIdentityHelper.GetUserAssignedIdentity(this.UserAssignedIdentities),
138145
PublicNetworkAccess = this.PublicNetworkAccess,
139146
MinimalTlsVersion = this.MinimalTlsVersion,
140147
SqlAdministratorLogin = model.FirstOrDefault().SqlAdministratorLogin,

src/Sql/Sql/TransparentDataEncryption/Services/AzureSqlDatabaseTransparentDataEncryptionAdapter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ private static AzureSqlServerTransparentDataEncryptionProtectorModel CreateEncry
194194
Model.EncryptionProtectorType type = Model.EncryptionProtectorType.ServiceManaged;
195195
Enum.TryParse<Model.EncryptionProtectorType>(resp.Properties.ServerKeyType, true, out type);
196196
EncryptionProtector.Type = type;
197-
EncryptionProtector.AutoRotationEnabled = resp.Properties.AutoRotationEnabled;
197+
EncryptionProtector.AutoRotationEnabled = resp.Properties.AutoKeyRotationEnabled;
198198

199199
if (type == Model.EncryptionProtectorType.AzureKeyVault)
200200
{

0 commit comments

Comments
 (0)