Skip to content

Commit fb9886c

Browse files
committed
Addressed PR comments
1 parent c2ff3bd commit fb9886c

File tree

7 files changed

+14
-42
lines changed

7 files changed

+14
-42
lines changed
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,20 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using Microsoft.Azure.Commands.Sql.TransparentDataEncryption.Model;
1516
using System;
1617
using System.Collections.Generic;
1718
using System.Linq;
1819
using System.Text;
1920
using System.Text.RegularExpressions;
2021
using System.Threading.Tasks;
2122

22-
namespace Microsoft.Azure.Commands.Sql.TransparentDataEncryption.Model
23+
namespace Microsoft.Azure.Commands.Sql.Common
2324
{
2425
/// <summary>
2526
/// Helper class for Managed instance key
2627
/// </summary>
27-
class ManagedInstanceKeyHelper
28+
class TdeKeyHelper
2829
{
2930
/// <summary>
3031
/// Creates the SQL Server Key Name from an Azure Key Vault KeyId

src/Sql/Sql/ServerKeyVaultKey/Cmdlet/AddAzureSqlServerKeyVaultKey.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using System.Collections.Generic;
1616
using System.Linq;
1717
using System.Management.Automation;
18+
using Microsoft.Azure.Commands.Sql.Common;
1819
using Microsoft.Azure.Commands.Sql.ServerKeyVaultKey.Model;
1920
using Microsoft.Azure.Commands.Sql.ServerKeyVaultKey.Services;
2021

@@ -65,7 +66,7 @@ protected override IEnumerable<AzureSqlServerKeyVaultKeyModel> ApplyUserInputToM
6566
{
6667
ResourceGroupName = this.ResourceGroupName,
6768
ServerName = this.ServerName,
68-
ServerKeyName = AzureSqlServerKeyVaultKeyModel.CreateServerKeyNameFromKeyId(this.KeyId),
69+
ServerKeyName = TdeKeyHelper.CreateServerKeyNameFromKeyId(this.KeyId),
6970
Uri = this.KeyId,
7071
Type = AzureSqlServerKeyVaultKeyModel.ServerKeyType.AzureKeyVault
7172
});

src/Sql/Sql/ServerKeyVaultKey/Model/AzureSqlServerKeyVaultKeyModel.cs

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -61,39 +61,5 @@ public enum ServerKeyType { AzureKeyVault, ServiceManaged };
6161
/// Gets or sets the creation date of the server key
6262
/// </summary>
6363
public DateTime? CreationDate { get; set; }
64-
65-
/// <summary>
66-
/// Creates the SQL Server Key Name from an Azure Key Vault KeyId
67-
/// Throws an exception if the provided KeyId is malformed.
68-
/// An example of a well formed Azure Key Vault KeyId is: https://YourVaultName.vault.azure.net/keys/YourKeyName/01234567890123456789012345678901
69-
/// </summary>
70-
/// <param name="keyId">The full Azure Key Vault KeyId</param>
71-
/// <returns>The Server Key Name for the provided KeyId</returns>
72-
public static string CreateServerKeyNameFromKeyId(string keyId)
73-
{
74-
if (string.IsNullOrEmpty(keyId))
75-
{
76-
return ServerKeyType.ServiceManaged.ToString();
77-
}
78-
79-
// Validate that the url is a keyvault url and has a key and version
80-
Regex r = new Regex(@"https(.)+\.vault(.)+\/keys\/[^\/]+\/[0-9a-zA-Z]+$", RegexOptions.IgnoreCase);
81-
if (!r.IsMatch(keyId))
82-
{
83-
// Throw an error here, since we don't want to use a non keyvault url
84-
//
85-
throw new ArgumentException(String.Format("Invalid parameter format for keyId: {0}."
86-
+ " It should be a well formed Azure Key Vault KeyId like: https://YourVaultName.vault.azure.net/keys/YourKeyName/01234567890123456789012345678901", keyId)
87-
, "KeyId");
88-
}
89-
90-
var uri = new Uri(keyId);
91-
92-
string vault = uri.Host.Split('.').First();
93-
string key = uri.Segments[2].TrimEnd('/');
94-
string version = uri.Segments.Last();
95-
96-
return String.Format("{0}_{1}_{2}", vault, key, version);
97-
}
9864
}
9965
}

src/Sql/Sql/ServerKeyVaultKey/Services/AzureSqlServerKeyVaultKeyAdapter.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
1616
using Microsoft.Azure.Commands.Common.Authentication.Models;
17+
using Microsoft.Azure.Commands.Sql.Common;
1718
using Microsoft.Azure.Commands.Sql.ServerKeyVaultKey.Model;
1819
using Microsoft.Azure.Commands.Sql.Services;
1920
using Microsoft.Azure.Management.Sql.LegacySdk.Models;
@@ -57,7 +58,7 @@ public AzureSqlServerKeyVaultKeyAdapter(IAzureContext context)
5758
/// <returns>The Server Key Vault Key</returns>
5859
public AzureSqlServerKeyVaultKeyModel Get(string resourceGroupName, string serverName, string keyId)
5960
{
60-
string keyName = AzureSqlServerKeyVaultKeyModel.CreateServerKeyNameFromKeyId(keyId);
61+
string keyName = TdeKeyHelper.CreateServerKeyNameFromKeyId(keyId);
6162
var resp = Communicator.Get(resourceGroupName, serverName, keyName);
6263
return CreateServerKeyModelFromResponse(resourceGroupName, serverName, keyName, resp);
6364
}
@@ -104,7 +105,7 @@ public AzureSqlServerKeyVaultKeyModel CreateOrUpdate(AzureSqlServerKeyVaultKeyMo
104105
/// <param name="keyId">KeyId of the Server Key Vault Key</param>
105106
public void Delete(string resourceGroupName, string serverName, string keyId)
106107
{
107-
string keyName = AzureSqlServerKeyVaultKeyModel.CreateServerKeyNameFromKeyId(keyId);
108+
string keyName = TdeKeyHelper.CreateServerKeyNameFromKeyId(keyId);
108109
Communicator.Delete(resourceGroupName, serverName, keyName);
109110
}
110111

src/Sql/Sql/TransparentDataEncryption/Cmdlet/SetAzureSqlServerTransparentDataEncryptionProtector.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using Microsoft.Azure.Commands.Sql.Common;
1516
using Microsoft.Azure.Commands.Sql.ServerKeyVaultKey.Model;
1617
using Microsoft.Azure.Commands.Sql.TransparentDataEncryption.Model;
1718
using System.Collections.Generic;
@@ -82,7 +83,7 @@ public class SetAzureSqlServerTransparentDataEncryptionProtector : AzureSqlServe
8283
ResourceGroupName = this.ResourceGroupName,
8384
ServerName = this.ServerName,
8485
Type = this.Type,
85-
ServerKeyVaultKeyName = AzureSqlServerKeyVaultKeyModel.CreateServerKeyNameFromKeyId(this.KeyId),
86+
ServerKeyVaultKeyName = TdeKeyHelper.CreateServerKeyNameFromKeyId(this.KeyId),
8687
KeyId = this.KeyId
8788
});
8889
return newEntity;

src/Sql/Sql/TransparentDataEncryption/Model/AzureRmSqlManagedInstanceKeyVaultKeyModel.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using System;
1616
using System.Linq;
1717
using System.Text.RegularExpressions;
18+
using Microsoft.Azure.Commands.Sql.Common;
1819
using Microsoft.Azure.Management.Sql.Models;
1920

2021
namespace Microsoft.Azure.Commands.Sql.TransparentDataEncryption.Model
@@ -29,7 +30,7 @@ public AzureRmSqlManagedInstanceKeyVaultKeyModel(string resourceGroupName, strin
2930
ResourceGroupName = resourceGroupName;
3031
ManagedInstanceName = managedInstanceName;
3132
KeyId = keyId;
32-
ManagedInstanceKeyName = ManagedInstanceKeyHelper.CreateServerKeyNameFromKeyId(keyId);
33+
ManagedInstanceKeyName = TdeKeyHelper.CreateServerKeyNameFromKeyId(keyId);
3334
}
3435

3536
private AzureRmSqlManagedInstanceKeyVaultKeyModel() { }

src/Sql/Sql/TransparentDataEncryption/Services/AzureSqlDatabaseTransparentDataEncryptionArmAdapter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
using Microsoft.Rest.Azure;
2727
using Microsoft.WindowsAzure.Commands.Common;
2828
using ServerKeyType = Microsoft.Azure.Management.Sql.Models.ServerKeyType;
29+
using Microsoft.Azure.Commands.Sql.Common;
2930

3031
namespace Microsoft.Azure.Commands.Sql.TransparentDataEncryption.Adapter
3132
{
@@ -156,7 +157,7 @@ public AzureRmSqlManagedInstanceTransparentDataEncryptionProtectorModel CreateOr
156157
managedInstanceEncryptionProtector: new ManagedInstanceEncryptionProtector()
157158
{
158159
ServerKeyType = model.Type.ToString(),
159-
ServerKeyName = ManagedInstanceKeyHelper.CreateServerKeyNameFromKeyId(model.KeyId)
160+
ServerKeyName = TdeKeyHelper.CreateServerKeyNameFromKeyId(model.KeyId)
160161
});
161162

162163
return AzureRmSqlManagedInstanceTransparentDataEncryptionProtectorModel

0 commit comments

Comments
 (0)