From 0f2508b87559ac976f948e97577c58300bb1394d Mon Sep 17 00:00:00 2001 From: Bing Li Date: Mon, 12 Jan 2015 13:25:46 +0800 Subject: [PATCH 1/2] Add 'type' parameter in cmdlet New-AzureDataFactoryEncryptValue for supportting File encryption story: a) add a new optional parameter Type. Two values "OnPremisesSqlLinkedService", "OnPremisesFileSystemLinkedService" could be set in this parameter to indicate which encryption scenario it is. b) If Type is not set, use "OnPremisesSqlLinkedService" as default. c) Update the test case and add examples in the help contents. --- .../NewDataFactoryEncryptValueTests.cs | 16 +++--- .../Commands.DataFactories.csproj | 2 +- .../NewAzureDataFactoryEncryptValueCommand.cs | 7 ++- ....Azure.Commands.DataFactories.dll-Help.xml | 52 ++++++++++++++++++- .../Models/DataFactoryClient.Encrypt.cs | 9 ++-- .../Commands.DataFactories/packages.config | 2 +- 6 files changed, 73 insertions(+), 15 deletions(-) diff --git a/src/ResourceManager/DataFactories/Commands.DataFactories.Test/UnitTests/NewDataFactoryEncryptValueTests.cs b/src/ResourceManager/DataFactories/Commands.DataFactories.Test/UnitTests/NewDataFactoryEncryptValueTests.cs index 47a63edbd524..d1f6ce7b04c5 100644 --- a/src/ResourceManager/DataFactories/Commands.DataFactories.Test/UnitTests/NewDataFactoryEncryptValueTests.cs +++ b/src/ResourceManager/DataFactories/Commands.DataFactories.Test/UnitTests/NewDataFactoryEncryptValueTests.cs @@ -36,6 +36,7 @@ public void TestOnPremDatasourceEncryptionSQLAuth() { SecureString secureString = new SecureString(); string expectedOutput = "My encrypted string " + Guid.NewGuid(); + string linkedServiceType = "OnPremisesSqlLinkedService"; var cmdlet = new NewAzureDataFactoryEncryptValueCommand { @@ -44,17 +45,18 @@ public void TestOnPremDatasourceEncryptionSQLAuth() Value = secureString, ResourceGroupName = ResourceGroupName, DataFactoryName = DataFactoryName, - GatewayName = GatewayName + GatewayName = GatewayName, + Type = linkedServiceType }; // Arrange - this.dataFactoriesClientMock.Setup(f => f.OnPremisesEncryptString(secureString, ResourceGroupName, DataFactoryName, GatewayName, null)).Returns(expectedOutput); + this.dataFactoriesClientMock.Setup(f => f.OnPremisesEncryptString(secureString, ResourceGroupName, DataFactoryName, GatewayName, null, linkedServiceType)).Returns(expectedOutput); // Action cmdlet.ExecuteCmdlet(); // Assert - this.dataFactoriesClientMock.Verify(f => f.OnPremisesEncryptString(secureString, ResourceGroupName, DataFactoryName, GatewayName, null), Times.Once()); + this.dataFactoriesClientMock.Verify(f => f.OnPremisesEncryptString(secureString, ResourceGroupName, DataFactoryName, GatewayName, null, linkedServiceType), Times.Once()); this.commandRuntimeMock.Verify(f => f.WriteObject(expectedOutput), Times.Once()); } @@ -67,6 +69,7 @@ public void TestOnPremDatasourceEncryptionWinAuth() string winAuthUserName = "foo"; SecureString winAuthPassword = new SecureString(); PSCredential credential = new PSCredential(winAuthUserName, winAuthPassword); + string linkedServiceType = "OnPremisesFileSystemLinkedService"; var cmdlet = new NewAzureDataFactoryEncryptValueCommand { @@ -76,17 +79,18 @@ public void TestOnPremDatasourceEncryptionWinAuth() ResourceGroupName = ResourceGroupName, DataFactoryName = DataFactoryName, GatewayName = GatewayName, - Credential = credential + Credential = credential, + Type = linkedServiceType }; // Arrange - this.dataFactoriesClientMock.Setup(f => f.OnPremisesEncryptString(secureString, ResourceGroupName, DataFactoryName, GatewayName, credential)).Returns(expectedOutput); + this.dataFactoriesClientMock.Setup(f => f.OnPremisesEncryptString(secureString, ResourceGroupName, DataFactoryName, GatewayName, credential, linkedServiceType)).Returns(expectedOutput); // Action cmdlet.ExecuteCmdlet(); // Assert - this.dataFactoriesClientMock.Verify(f => f.OnPremisesEncryptString(secureString, ResourceGroupName, DataFactoryName, GatewayName, credential), Times.Once()); + this.dataFactoriesClientMock.Verify(f => f.OnPremisesEncryptString(secureString, ResourceGroupName, DataFactoryName, GatewayName, credential, linkedServiceType), Times.Once()); this.commandRuntimeMock.Verify(f => f.WriteObject(expectedOutput), Times.Once()); } } diff --git a/src/ResourceManager/DataFactories/Commands.DataFactories/Commands.DataFactories.csproj b/src/ResourceManager/DataFactories/Commands.DataFactories/Commands.DataFactories.csproj index e5f9759f391c..495f023b9f54 100644 --- a/src/ResourceManager/DataFactories/Commands.DataFactories/Commands.DataFactories.csproj +++ b/src/ResourceManager/DataFactories/Commands.DataFactories/Commands.DataFactories.csproj @@ -55,7 +55,7 @@ ..\..\..\packages\Microsoft.DataFactories.Runtime.0.11.1-preview\lib\net45\Microsoft.DataFactories.Runtime.dll - ..\..\..\packages\Microsoft.DataTransfer.Gateway.Encryption.1.1.0-preview\lib\net45\Microsoft.DataTransfer.Gateway.Encryption.dll + ..\..\..\packages\Microsoft.DataTransfer.Gateway.Encryption.1.2.0-preview\lib\net45\Microsoft.DataTransfer.Gateway.Encryption.dll False diff --git a/src/ResourceManager/DataFactories/Commands.DataFactories/Encrypt/NewAzureDataFactoryEncryptValueCommand.cs b/src/ResourceManager/DataFactories/Commands.DataFactories/Encrypt/NewAzureDataFactoryEncryptValueCommand.cs index 363ef0f55439..11d812c81e29 100644 --- a/src/ResourceManager/DataFactories/Commands.DataFactories/Encrypt/NewAzureDataFactoryEncryptValueCommand.cs +++ b/src/ResourceManager/DataFactories/Commands.DataFactories/Encrypt/NewAzureDataFactoryEncryptValueCommand.cs @@ -47,6 +47,11 @@ public class NewAzureDataFactoryEncryptValueCommand : DataFactoryBaseCmdlet [Parameter(ParameterSetName = ByFactoryName, Position = 4, Mandatory = false, HelpMessage = "The windows authentication credential.")] public PSCredential Credential { get; set; } + [Parameter(ParameterSetName = ByFactoryObject, Position = 4, Mandatory = false, HelpMessage = "The linked service type.")] + [Parameter(ParameterSetName = ByFactoryName, Position = 5, Mandatory = false, HelpMessage = "The linked service type.")] + [ValidateSet("OnPremisesSqlLinkedService", "OnPremisesFileSystemLinkedService", IgnoreCase = true)] + public string Type { get; set; } + [EnvironmentPermission(SecurityAction.Demand, Unrestricted = true)] public override void ExecuteCmdlet() { @@ -72,7 +77,7 @@ public override void ExecuteCmdlet() else { // On-premises encryption with Gateway - encryptedValue = DataFactoryClient.OnPremisesEncryptString(Value, ResourceGroupName, DataFactoryName, GatewayName, Credential); + encryptedValue = DataFactoryClient.OnPremisesEncryptString(Value, ResourceGroupName, DataFactoryName, GatewayName, Credential, Type); } WriteObject(encryptedValue); diff --git a/src/ResourceManager/DataFactories/Commands.DataFactories/Microsoft.Azure.Commands.DataFactories.dll-Help.xml b/src/ResourceManager/DataFactories/Commands.DataFactories/Microsoft.Azure.Commands.DataFactories.dll-Help.xml index 10a5165e01ca..d2f3adb57626 100644 --- a/src/ResourceManager/DataFactories/Commands.DataFactories/Microsoft.Azure.Commands.DataFactories.dll-Help.xml +++ b/src/ResourceManager/DataFactories/Commands.DataFactories/Microsoft.Azure.Commands.DataFactories.dll-Help.xml @@ -2088,6 +2088,13 @@ PSCredential + + Type + + Specifies the linked service type. This cmdlet encrypts data for the linked service type that this parameter specifies. For on premises SQL linked service, type OnPremisesSqlLinkedService. For file system linked service, type OnPremisesFileSystemLinkedService. + + String + New-AzureDataFactoryEncryptValue @@ -2126,6 +2133,13 @@ PSCredential + + Type + + Specifies the linked service type. This cmdlet encrypts data for the linked service type that this parameter specifies. For on premises SQL linked service, type OnPremisesSqlLinkedService. For file system linked service, type OnPremisesFileSystemLinkedService. + + String + @@ -2201,6 +2215,18 @@ + + Type + + Specifies the linked service type. For on premises SQL linked service, type OnPremisesSqlLinkedService. For file system linked service, type OnPremisesFileSystemLinkedService. + + String + + String + + + + @@ -2277,13 +2303,35 @@ PS C:\> $Value = ConvertTo-SecureString "Data Source=ContosoServer;Initial Catalog=catelog;Integrated Security=True" -AsPlainText -Force PS C:\> $Credential = Get-Credential - PS C:\> New-AzureDataFactoryEncryptValue -DataFactoryName "WikiADF" -GatewayName "WikiGateway" -ResourceGroupName "ADF" -Value $Value -Credential $Credential + PS C:\> New-AzureDataFactoryEncryptValue -DataFactoryName "WikiADF" -GatewayName "WikiGateway" -ResourceGroupName "ADF" -Value $Value -Credential $Credential -Type OnPremisesSqlLinkedService data source=ContosoServer;initial catalog=catelog;EncryptedCredential=KAAAAAABAAAQAAAAQUU5MUVBNzY4QkFCQkI3MEUwRTMxOUNFNkM0MjRDOTVDNDk3RTcyRi8XAXyE/H+f3JydTkdg5t2g1eC/VtyF3NAD3idYnhrAphPJmO0pCaG5nH2IY48L3XJi7wabrlrGF+ieiWh1bwdgdxrW+t2jWPnLvT/ENUXtcevpx/dmTGKagH8TU9HLcoL1CAanb7Vkpga1B/uzRxBnVdsdtfvBzxG2M810tj1WzL8lFzA1mO5GbB0+ge116y0scL1vxjerjl5Muv0r0scG3lhj+IF0sXUMITFvhQwOIqweR052E6JlfJu+mTNFLCCkpw1iV+rhRhKqJF752dBuWjzI1EoyQUE17oK4OevkquuhUbfJmzj9BhGKQ+VkndAZiSw19FEGSC7JzoUe/XWEs/FJYrQCCXIeNS94J9/VzN6KPYJR1pzAYCtnhq+p8Q== The first command uses the ConvertTo-SecureString cmdlet to convert the specified string to a SecureString object, and then stores that object in the $Value variable. The second command uses the Get-Credential cmdlet to collect the windows authentication user name and password, and then stores that PSCredential object in the $Credential variable. For more information, type Get-Help Get-Credential. - The third command creates an encrypted value for the object stored in $Value and $Credential for the specified data factory, gateway, and resource group. + The third command creates an encrypted value for the object stored in $Value and $Credential for the specified data factory, gateway, resource group, and linked service type. + + + + + + + + + Example 4: Encrypt the file system host name + + + + + PS C:\> $Value = ConvertTo-SecureString "hostname" -AsPlainText -Force + PS C:\> $Credential = Get-Credential + PS C:\> New-AzureDataFactoryEncryptValue -DataFactoryName "WikiADF" -GatewayName "WikiGateway" -ResourceGroupName "ADF" -Value $Value -Credential $Credential -Type OnPremisesFileSystemLinkedService + EncryptedCredential=KAAAAAABAAAQAAAAQUU5MUVBNzY4QkFCQkI3MEUwRTMxOUNFNkM0MjRDOTVDNDk3RTcyRi8XAXyE/H+f3JydTkdg5t2g1eC/VtyF3NAD3idYnhrAphPJmO0pCaG5nH2IY48L3XJi7wabrlrGF+ieiWh1bwdgdxrW+t2jWPnLvT/ENUXtcevpx/dmTGKagH8TU9HLcoL1CAanb7Vkpga1B/uzRxBnVdsdtfvBzxG2M810tj1WzL8lFzA1mO5GbB0+ge116y0scL1vxjerjl5Muv0r0scG3lhj+IF0sXUMITFvhQwOIqweR052E6JlfJu+mTNFLCCkpw1iV+rhRhKqJF752dBuWjzI1EoyQUE17oK4OevkquuhUbfJmzj9BhGKQ+VkndAZiSw19FEGSC7JzoUe/XWEs/FJYrQCCXIeNS94J9/VzN6KPYJR1pzAYCtnhq+p8Q== + + + The first command uses the ConvertTo-SecureString cmdlet to convert the specified string to a SecureString object, and then stores that object in the $Value variable. + The second command uses the Get-Credential cmdlet to collect the windows authentication user name and password, and then stores that PSCredential object in the $Credential variable. For more information, type Get-Help Get-Credential. + The third command creates an encrypted value for the object stored in $Value and $Credential for the specified data factory, gateway, resource group, and linked service type. diff --git a/src/ResourceManager/DataFactories/Commands.DataFactories/Models/DataFactoryClient.Encrypt.cs b/src/ResourceManager/DataFactories/Commands.DataFactories/Models/DataFactoryClient.Encrypt.cs index c3fe9eee7174..1e1aece57a5c 100644 --- a/src/ResourceManager/DataFactories/Commands.DataFactories/Models/DataFactoryClient.Encrypt.cs +++ b/src/ResourceManager/DataFactories/Commands.DataFactories/Models/DataFactoryClient.Encrypt.cs @@ -33,13 +33,15 @@ public virtual string CloudEncryptString(SecureString value, string resourceGrou resourceGroupName, dataFactoryName); } - public virtual string OnPremisesEncryptString(SecureString value, string resourceGroupName, string dataFactoryName, string gatewayName, PSCredential credential) + public virtual string OnPremisesEncryptString(SecureString value, string resourceGroupName, string dataFactoryName, string gatewayName, PSCredential credential, string type) { if (value == null) { throw new ArgumentNullException("value"); } + LinkedServiceType likedServiceType = type == null ? LinkedServiceType.OnPremisesSqlLinkedService : (LinkedServiceType) Enum.Parse(typeof(LinkedServiceType), type, true); + var response = DataPipelineManagementClient.Gateways.RetrieveConnectionInfo(resourceGroupName, dataFactoryName, gatewayName); var gatewayEncryptionInfos = new[] { @@ -54,9 +56,8 @@ public virtual string OnPremisesEncryptString(SecureString value, string resourc string userName = credential != null ? credential.UserName : null; SecureString password = credential != null ? credential.Password : null; - UserInputConnectionString connectionString = new UserInputConnectionString(value, userName, password); - var gatewayEncryptionClient = new GatewayEncryptionClient(); - return gatewayEncryptionClient.Encrypt(connectionString, gatewayEncryptionInfos); + UserInputConnectionString connectionString = new UserInputConnectionString(value, userName, password, likedServiceType); + return GatewayEncryptionClient.Encrypt(connectionString, gatewayEncryptionInfos); } } } diff --git a/src/ResourceManager/DataFactories/Commands.DataFactories/packages.config b/src/ResourceManager/DataFactories/Commands.DataFactories/packages.config index 404260a2d015..5fe5a00e8514 100644 --- a/src/ResourceManager/DataFactories/Commands.DataFactories/packages.config +++ b/src/ResourceManager/DataFactories/Commands.DataFactories/packages.config @@ -5,7 +5,7 @@ - + From 1b01ad7b9b5bcb199a8555e1f9bc45dc16433e2f Mon Sep 17 00:00:00 2001 From: Bing Li Date: Tue, 13 Jan 2015 20:02:20 +0800 Subject: [PATCH 2/2] Upgrade the Microsoft.DataTransfer.Gateway.Encryption nuget package to version 1.2.1 --- .../Commands.DataFactories/Commands.DataFactories.csproj | 2 +- .../Models/DataFactoryClient.Encrypt.cs | 4 ++-- .../DataFactories/Commands.DataFactories/packages.config | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ResourceManager/DataFactories/Commands.DataFactories/Commands.DataFactories.csproj b/src/ResourceManager/DataFactories/Commands.DataFactories/Commands.DataFactories.csproj index 495f023b9f54..50b73bf080a1 100644 --- a/src/ResourceManager/DataFactories/Commands.DataFactories/Commands.DataFactories.csproj +++ b/src/ResourceManager/DataFactories/Commands.DataFactories/Commands.DataFactories.csproj @@ -55,7 +55,7 @@ ..\..\..\packages\Microsoft.DataFactories.Runtime.0.11.1-preview\lib\net45\Microsoft.DataFactories.Runtime.dll - ..\..\..\packages\Microsoft.DataTransfer.Gateway.Encryption.1.2.0-preview\lib\net45\Microsoft.DataTransfer.Gateway.Encryption.dll + ..\..\..\packages\Microsoft.DataTransfer.Gateway.Encryption.1.2.1-preview\lib\net45\Microsoft.DataTransfer.Gateway.Encryption.dll False diff --git a/src/ResourceManager/DataFactories/Commands.DataFactories/Models/DataFactoryClient.Encrypt.cs b/src/ResourceManager/DataFactories/Commands.DataFactories/Models/DataFactoryClient.Encrypt.cs index 1e1aece57a5c..1fa12404a28e 100644 --- a/src/ResourceManager/DataFactories/Commands.DataFactories/Models/DataFactoryClient.Encrypt.cs +++ b/src/ResourceManager/DataFactories/Commands.DataFactories/Models/DataFactoryClient.Encrypt.cs @@ -40,7 +40,7 @@ public virtual string OnPremisesEncryptString(SecureString value, string resourc throw new ArgumentNullException("value"); } - LinkedServiceType likedServiceType = type == null ? LinkedServiceType.OnPremisesSqlLinkedService : (LinkedServiceType) Enum.Parse(typeof(LinkedServiceType), type, true); + LinkedServiceType linkedServiceType = type == null ? LinkedServiceType.OnPremisesSqlLinkedService : (LinkedServiceType) Enum.Parse(typeof(LinkedServiceType), type, true); var response = DataPipelineManagementClient.Gateways.RetrieveConnectionInfo(resourceGroupName, dataFactoryName, gatewayName); var gatewayEncryptionInfos = new[] @@ -56,7 +56,7 @@ public virtual string OnPremisesEncryptString(SecureString value, string resourc string userName = credential != null ? credential.UserName : null; SecureString password = credential != null ? credential.Password : null; - UserInputConnectionString connectionString = new UserInputConnectionString(value, userName, password, likedServiceType); + UserInputConnectionString connectionString = new UserInputConnectionString(value, userName, password, linkedServiceType); return GatewayEncryptionClient.Encrypt(connectionString, gatewayEncryptionInfos); } } diff --git a/src/ResourceManager/DataFactories/Commands.DataFactories/packages.config b/src/ResourceManager/DataFactories/Commands.DataFactories/packages.config index 5fe5a00e8514..aef5da9a9763 100644 --- a/src/ResourceManager/DataFactories/Commands.DataFactories/packages.config +++ b/src/ResourceManager/DataFactories/Commands.DataFactories/packages.config @@ -5,7 +5,7 @@ - +