Skip to content

Change New-AzureDataFactoryEncryptValue to support on premises Windows A... #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public NewDataFactoryEncryptValueTests()

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestOnPermDatasourceEncryptionWithRawJsonContent()
public void TestOnPremDatasourceEncryptionSQLAuth()
{
SecureString secureString = new SecureString();
string expectedOutput = "My encrypted string " + Guid.NewGuid();
Expand All @@ -47,13 +47,45 @@ public void TestOnPermDatasourceEncryptionWithRawJsonContent()
};

// Arrange
this.dataFactoriesClientMock.Setup(f => f.OnPremisesEncryptString(secureString, ResourceGroupName, DataFactoryName, GatewayName)).Returns(expectedOutput);
this.dataFactoriesClientMock.Setup(f => f.OnPremisesEncryptString(secureString, ResourceGroupName, DataFactoryName, GatewayName, null, null)).Returns(expectedOutput);

// Action
cmdlet.ExecuteCmdlet();

// Assert
this.dataFactoriesClientMock.Verify(f => f.OnPremisesEncryptString(secureString, ResourceGroupName, DataFactoryName, GatewayName), Times.Once());
this.dataFactoriesClientMock.Verify(f => f.OnPremisesEncryptString(secureString, ResourceGroupName, DataFactoryName, GatewayName, null, null), Times.Once());
this.commandRuntimeMock.Verify(f => f.WriteObject(expectedOutput), Times.Once());
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestOnPremDatasourceEncryptionWinAuth()
{
SecureString secureString = new SecureString();
string expectedOutput = "My encrypted string " + Guid.NewGuid();
string WinAuthUserName = "foo";
SecureString winAuthPassword = new SecureString();

var cmdlet = new NewAzureDataFactoryEncryptValueCommand
{
CommandRuntime = this.commandRuntimeMock.Object,
DataFactoryClient = this.dataFactoriesClientMock.Object,
Value = secureString,
ResourceGroupName = ResourceGroupName,
DataFactoryName = DataFactoryName,
GatewayName = GatewayName,
UserName = WinAuthUserName,
Password = winAuthPassword
};

// Arrange
this.dataFactoriesClientMock.Setup(f => f.OnPremisesEncryptString(secureString, ResourceGroupName, DataFactoryName, GatewayName, WinAuthUserName, winAuthPassword)).Returns(expectedOutput);

// Action
cmdlet.ExecuteCmdlet();

// Assert
this.dataFactoriesClientMock.Verify(f => f.OnPremisesEncryptString(secureString, ResourceGroupName, DataFactoryName, GatewayName, WinAuthUserName, winAuthPassword), Times.Once());
this.commandRuntimeMock.Verify(f => f.WriteObject(expectedOutput), Times.Once());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<HintPath>..\..\..\packages\Microsoft.DataFactories.Runtime.0.11.1-preview\lib\net45\Microsoft.DataFactories.Runtime.dll</HintPath>
</Reference>
<Reference Include="Microsoft.DataTransfer.Gateway.Encryption">
<HintPath>..\..\..\packages\Microsoft.DataTransfer.Gateway.Encryption.1.0.0-preview\lib\net45\Microsoft.DataTransfer.Gateway.Encryption.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.DataTransfer.Gateway.Encryption.1.1.0-preview\lib\net45\Microsoft.DataTransfer.Gateway.Encryption.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ public class NewAzureDataFactoryEncryptValueCommand : DataFactoryBaseCmdlet
[Parameter(ParameterSetName = ByFactoryName, Position = 3, Mandatory = false, HelpMessage = "The gateway group name.")]
public string GatewayName { get; set; }

[Parameter(ParameterSetName = ByFactoryObject, Position = 3, Mandatory = false, HelpMessage = "The windows authentication user name.")]
[Parameter(ParameterSetName = ByFactoryName, Position = 4, Mandatory = false, HelpMessage = "The windows authentication user name.")]
public string UserName { get; set; }

[Parameter(ParameterSetName = ByFactoryObject, Position = 4, Mandatory = false, HelpMessage = "The windows authentication password.")]
[Parameter(ParameterSetName = ByFactoryName, Position = 5, Mandatory = false, HelpMessage = "The windows authentication password.")]
public SecureString Password { get; set; }

[EnvironmentPermission(SecurityAction.Demand, Unrestricted = true)]
public override void ExecuteCmdlet()
{
Expand All @@ -68,7 +76,7 @@ public override void ExecuteCmdlet()
else
{
// On-premises encryption with Gateway
encryptedValue = DataFactoryClient.OnPremisesEncryptString(Value, ResourceGroupName, DataFactoryName, GatewayName);
encryptedValue = DataFactoryClient.OnPremisesEncryptString(Value, ResourceGroupName, DataFactoryName, GatewayName, UserName, Password);
}

WriteObject(encryptedValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2083,6 +2083,20 @@
</maml:description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
</command:parameter>
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="4" aliases="">
<maml:name>UserName</maml:name>
<maml:description>
<maml:para>Specifies the windows authentication user name. This cmdlet encrypts data for the gateway that this parameter specifies.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
</command:parameter>
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="5" aliases="">
<maml:name>Password</maml:name>
<maml:description>
<maml:para>Specifies the windows authentication password. This cmdlet encrypts data for the gateway that this parameter specifies.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">SecureString</command:parameterValue>
</command:parameter>
</command:syntaxItem>
<command:syntaxItem>
<maml:name>New-AzureDataFactoryEncryptValue</maml:name>
Expand Down Expand Up @@ -2114,6 +2128,20 @@
</maml:description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
</command:parameter>
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="5" aliases="">
<maml:name>UserName</maml:name>
<maml:description>
<maml:para>Specifies the windows authentication user name. This cmdlet encrypts data for the gateway that this parameter specifies.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
</command:parameter>
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="6" aliases="">
<maml:name>Password</maml:name>
<maml:description>
<maml:para>Specifies the windows authentication password. This cmdlet encrypts data for the gateway that this parameter specifies.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">SecureString</command:parameterValue>
</command:parameter>
</command:syntaxItem>
</command:syntax>
<command:parameters>
Expand Down Expand Up @@ -2177,6 +2205,30 @@
</dev:type>
<dev:defaultValue></dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="5" aliases="">
<maml:name>UserName</maml:name>
<maml:description>
<maml:para>Specifies the windows authentication user name. This cmdlet encrypts data for the gateway that this parameter specifies.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
<dev:type>
<maml:name>String</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue></dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="6" aliases="">
<maml:name>Password</maml:name>
<maml:description>
<maml:para>Specifies the windows authentication password. This cmdlet encrypts data for the gateway that this parameter specifies.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">SecureString</command:parameterValue>
<dev:type>
<maml:name>SecureString</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue></dev:defaultValue>
</command:parameter>
</command:parameters>
<command:inputTypes>
<command:inputType>
Expand Down Expand Up @@ -2213,10 +2265,7 @@
<dev:code>
PS C:\&gt; $Value = ConvertTo-SecureString "Data Source=ContosoServer;Initial Catalog=catelog;user id =user123;password=password123" -AsPlainText -Force
PS C:\&gt; New-AzureDataFactoryEncryptValue -DataFactoryName "UncycloADF" -GatewayName "UncycloGateway" -ResourceGroupName "ADF" -Value $Value
data source=ContosoServer;initial catalog=catelog;EncryptedCredential=KAAAAAABAAAQAAAAQUU5MUVBNzY4QkFCQkI3MEUwRTMxOUNFNkM0MjRDOTVDNDk3RTcyRi8XAXyE/
H+f3JydTkdg5t2g1eC/VtyF3NAD3idYnhrAphPJmO0pCaG5nH2IY48L3XJi7wabrlrGF+ieiWh1bwdgdxrW+t2jWPnLvT/ENUXtcevpx/dmTGKagH8TU9HLcoL1CAanb7Vkpga1B/uzRxBnVdsdtfv
BzxG2M810tj1WzL8lFzA1mO5GbB0+ge116y0scL1vxjerjl5Muv0r0scG3lhj+IF0sXUMITFvhQwOIqweR052E6JlfJu+mTNFLCCkpw1iV+rhRhKqJF752dBuWjzI1EoyQUE17oK4OevkquuhUbfJmzj9B
hGKQ+VkndAZiSw19FEGSC7JzoUe/XWEs/FJYrQCCXIeNS94J9/VzN6KPYJR1pzAYCtnhq+p8Q==
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==
</dev:code>
<dev:remarks>
<maml:para>The first command uses the ConvertTo-SecureString cmdlet to convert the specified connection string to a SecureString object, and then stores that object in the $Value variable. For more information, type Get-Help ConvertTo-SecureString.</maml:para>
Expand All @@ -2236,10 +2285,7 @@
<dev:code>
PS C:\&gt; $Value = ConvertTo-SecureString "Test123" -AsPlainText -Force
PS C:\&gt; New-AzureDataFactoryEncryptValue -DataFactoryName "UncycloADF" -ResourceGroupName "ADF" -Value $Value
$Encrypted$String$KAAAAAABAAAQAAAAQUU5MUVBNzY4QkFCQkI3MEUwRTMxOUNFNkM0MjRDOTVDNDk3RTcyRi8XAXyE/H+f3JydTkdg5t2g1eC/VtyF3NAD3idYnhrAphPJm
O0pCaG5nH2IY48L3XJi7wabrlrGF+ieiWh1bwdgdxrW+t2jWPnLvT/ENUXtcevpxdmTGKagH8TU9HLcoL1CAanb7Vkpga1B/uzRxBnVdsdtfvBzxG2M810tj1WzL8lFzA1mO5GbB0+ge116y
0scL1vxjerjl5Muv0r0scG3lhj+IF0sXUMITFvhQwOIqweR052E6JlfJu+mTNFLCCkpw1iV+rhRhKqJF752dBuWjzI1EoyQUE17oK4OevkquuhUbfJmzj9BhGKQ+VkndAZiSw19FEGSC7JzoUe
/XWEs/FJYrQCCXIeNS94J9/VzN6KPYJR1pzAYCtnhq+p8Q==
$Encrypted$String$KAAAAAABAAAQAAAAQUU5MUVBNzY4QkFCQkI3MEUwRTMxOUNFNkM0MjRDOTVDNDk3RTcyRi8XAXyE/H+f3JydTkdg5t2g1eC/VtyF3NAD3idYnhrAphPJmO0pCaG5nH2IY48L3XJi7wabrlrGF+ieiWh1bwdgdxrW+t2jWPnLvT/ENUXtcevpxdmTGKagH8TU9HLcoL1CAanb7Vkpga1B/uzRxBnVdsdtfvBzxG2M810tj1WzL8lFzA1mO5GbB0+ge116y0scL1vxjerjl5Muv0r0scG3lhj+IF0sXUMITFvhQwOIqweR052E6JlfJu+mTNFLCCkpw1iV+rhRhKqJF752dBuWjzI1EoyQUE17oK4OevkquuhUbfJmzj9BhGKQ+VkndAZiSw19FEGSC7JzoUe/XWEs/FJYrQCCXIeNS94J9/VzN6KPYJR1pzAYCtnhq+p8Q==
</dev:code>
<dev:remarks>
<maml:para>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.</maml:para>
Expand All @@ -2251,6 +2297,28 @@
</command:commandLine>
</command:commandLines>
</command:example>
<command:example>
<maml:title>Example 3: Encrypt a windows authentication connection string</maml:title>
<maml:introduction>
<maml:para></maml:para>
</maml:introduction>
<dev:code>
PS C:\&gt; $Value = ConvertTo-SecureString "Data Source=ContosoServer;Initial Catalog=catelog;Integrated Security=True" -AsPlainText -Force
PS C:\&gt; $Password = ConvertTo-SecureString "password" -AsPlainText -Force
PS C:\&gt; New-AzureDataFactoryEncryptValue -DataFactoryName "UncycloADF" -GatewayName "UncycloGateway" -ResourceGroupName "ADF" -Value $Value -Us -UserName "username" -Password $Password
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==
</dev:code>
<dev:remarks>
<maml:para>The first command uses the ConvertTo-SecureString cmdlet to convert the specified connection string to a SecureString object, and then stores that object in the $Value variable. For more information, type Get-Help ConvertTo-SecureString.</maml:para>
<maml:para>The second command uses the ConvertTo-SecureString cmdlet to convert the windows authentication password string to a SecureString object, and then stores that object in the $Password variable. For more information, type Get-Help ConvertTo-SecureString.</maml:para>
<maml:para>The third command creates an encrypted value for the object stored in $Value for the specified data factory, gateway, and resource group.</maml:para>
</dev:remarks>
<command:commandLines>
<command:commandLine>
<command:commandText />
</command:commandLine>
</command:commandLines>
</command:example>
</command:examples>
<maml:relatedLinks>
<maml:navigationLink>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public virtual string CloudEncryptString(SecureString value, string resourceGrou
resourceGroupName, dataFactoryName);
}

public virtual string OnPremisesEncryptString(SecureString value, string resourceGroupName, string dataFactoryName, string gatewayName)
public virtual string OnPremisesEncryptString(SecureString value, string resourceGroupName, string dataFactoryName, string gatewayName, string userName, SecureString password)
{
if (value == null)
{
Expand All @@ -46,12 +46,14 @@ public virtual string OnPremisesEncryptString(SecureString value, string resourc
{
ServiceToken = response.ConnectionInfo.ServiceToken,
IdentityCertThumbprint = response.ConnectionInfo.IdentityCertThumbprint,
HostServiceUri = response.ConnectionInfo.HostServiceUri
HostServiceUri = response.ConnectionInfo.HostServiceUri,
InstanceVersionString = response.ConnectionInfo.Version
}
};

UserInputConnectionString connectionString = new UserInputConnectionString(value, userName, password);
var gatewayEncryptionClient = new GatewayEncryptionClient();
return gatewayEncryptionClient.Encrypt(value, gatewayEncryptionInfos);
return gatewayEncryptionClient.Encrypt(connectionString, gatewayEncryptionInfos);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net45" />
<package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net45" />
<package id="Microsoft.DataFactories.Runtime" version="0.11.1-preview" targetFramework="net45" />
<package id="Microsoft.DataTransfer.Gateway.Encryption" version="1.0.0-preview" targetFramework="net45" />
<package id="Microsoft.DataTransfer.Gateway.Encryption" version="1.1.0-preview" targetFramework="net45" />
<package id="Microsoft.Net.Http" version="2.2.28" targetFramework="net45" />
<package id="Microsoft.WindowsAzure.Common" version="1.4.1" targetFramework="net45" />
<package id="Microsoft.WindowsAzure.Common.Dependencies" version="1.1.1" targetFramework="net45" />
Expand Down