Skip to content

Commit fe9bb87

Browse files
committed
Merge pull request Azure#82 from jtlibing/dev5
Add 'type' parameter in cmdlet New-AzureDataFactoryEncryptValue for supporting file linked service encryption
2 parents 18d4840 + 159c740 commit fe9bb87

File tree

6 files changed

+73
-15
lines changed

6 files changed

+73
-15
lines changed

src/ResourceManager/DataFactories/Commands.DataFactories.Test/UnitTests/NewDataFactoryEncryptValueTests.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public void TestOnPremDatasourceEncryptionSQLAuth()
3636
{
3737
SecureString secureString = new SecureString();
3838
string expectedOutput = "My encrypted string " + Guid.NewGuid();
39+
string linkedServiceType = "OnPremisesSqlLinkedService";
3940

4041
var cmdlet = new NewAzureDataFactoryEncryptValueCommand
4142
{
@@ -44,17 +45,18 @@ public void TestOnPremDatasourceEncryptionSQLAuth()
4445
Value = secureString,
4546
ResourceGroupName = ResourceGroupName,
4647
DataFactoryName = DataFactoryName,
47-
GatewayName = GatewayName
48+
GatewayName = GatewayName,
49+
Type = linkedServiceType
4850
};
4951

5052
// Arrange
51-
this.dataFactoriesClientMock.Setup(f => f.OnPremisesEncryptString(secureString, ResourceGroupName, DataFactoryName, GatewayName, null)).Returns(expectedOutput);
53+
this.dataFactoriesClientMock.Setup(f => f.OnPremisesEncryptString(secureString, ResourceGroupName, DataFactoryName, GatewayName, null, linkedServiceType)).Returns(expectedOutput);
5254

5355
// Action
5456
cmdlet.ExecuteCmdlet();
5557

5658
// Assert
57-
this.dataFactoriesClientMock.Verify(f => f.OnPremisesEncryptString(secureString, ResourceGroupName, DataFactoryName, GatewayName, null), Times.Once());
59+
this.dataFactoriesClientMock.Verify(f => f.OnPremisesEncryptString(secureString, ResourceGroupName, DataFactoryName, GatewayName, null, linkedServiceType), Times.Once());
5860
this.commandRuntimeMock.Verify(f => f.WriteObject(expectedOutput), Times.Once());
5961
}
6062

@@ -67,6 +69,7 @@ public void TestOnPremDatasourceEncryptionWinAuth()
6769
string winAuthUserName = "foo";
6870
SecureString winAuthPassword = new SecureString();
6971
PSCredential credential = new PSCredential(winAuthUserName, winAuthPassword);
72+
string linkedServiceType = "OnPremisesFileSystemLinkedService";
7073

7174
var cmdlet = new NewAzureDataFactoryEncryptValueCommand
7275
{
@@ -76,17 +79,18 @@ public void TestOnPremDatasourceEncryptionWinAuth()
7679
ResourceGroupName = ResourceGroupName,
7780
DataFactoryName = DataFactoryName,
7881
GatewayName = GatewayName,
79-
Credential = credential
82+
Credential = credential,
83+
Type = linkedServiceType
8084
};
8185

8286
// Arrange
83-
this.dataFactoriesClientMock.Setup(f => f.OnPremisesEncryptString(secureString, ResourceGroupName, DataFactoryName, GatewayName, credential)).Returns(expectedOutput);
87+
this.dataFactoriesClientMock.Setup(f => f.OnPremisesEncryptString(secureString, ResourceGroupName, DataFactoryName, GatewayName, credential, linkedServiceType)).Returns(expectedOutput);
8488

8589
// Action
8690
cmdlet.ExecuteCmdlet();
8791

8892
// Assert
89-
this.dataFactoriesClientMock.Verify(f => f.OnPremisesEncryptString(secureString, ResourceGroupName, DataFactoryName, GatewayName, credential), Times.Once());
93+
this.dataFactoriesClientMock.Verify(f => f.OnPremisesEncryptString(secureString, ResourceGroupName, DataFactoryName, GatewayName, credential, linkedServiceType), Times.Once());
9094
this.commandRuntimeMock.Verify(f => f.WriteObject(expectedOutput), Times.Once());
9195
}
9296
}

src/ResourceManager/DataFactories/Commands.DataFactories/Commands.DataFactories.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
<HintPath>..\..\..\packages\Microsoft.DataFactories.Runtime.0.11.1-preview\lib\net45\Microsoft.DataFactories.Runtime.dll</HintPath>
7474
</Reference>
7575
<Reference Include="Microsoft.DataTransfer.Gateway.Encryption">
76-
<HintPath>..\..\..\packages\Microsoft.DataTransfer.Gateway.Encryption.1.1.0-preview\lib\net45\Microsoft.DataTransfer.Gateway.Encryption.dll</HintPath>
76+
<HintPath>..\..\..\packages\Microsoft.DataTransfer.Gateway.Encryption.1.2.1-preview\lib\net45\Microsoft.DataTransfer.Gateway.Encryption.dll</HintPath>
7777
</Reference>
7878
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory, Version=2.11.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
7979
<SpecificVersion>False</SpecificVersion>

src/ResourceManager/DataFactories/Commands.DataFactories/Encrypt/NewAzureDataFactoryEncryptValueCommand.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ public class NewAzureDataFactoryEncryptValueCommand : DataFactoryBaseCmdlet
4747
[Parameter(ParameterSetName = ByFactoryName, Position = 4, Mandatory = false, HelpMessage = "The windows authentication credential.")]
4848
public PSCredential Credential { get; set; }
4949

50+
[Parameter(ParameterSetName = ByFactoryObject, Position = 4, Mandatory = false, HelpMessage = "The linked service type.")]
51+
[Parameter(ParameterSetName = ByFactoryName, Position = 5, Mandatory = false, HelpMessage = "The linked service type.")]
52+
[ValidateSet("OnPremisesSqlLinkedService", "OnPremisesFileSystemLinkedService", IgnoreCase = true)]
53+
public string Type { get; set; }
54+
5055
[EnvironmentPermission(SecurityAction.Demand, Unrestricted = true)]
5156
public override void ExecuteCmdlet()
5257
{
@@ -72,7 +77,7 @@ public override void ExecuteCmdlet()
7277
else
7378
{
7479
// On-premises encryption with Gateway
75-
encryptedValue = DataFactoryClient.OnPremisesEncryptString(Value, ResourceGroupName, DataFactoryName, GatewayName, Credential);
80+
encryptedValue = DataFactoryClient.OnPremisesEncryptString(Value, ResourceGroupName, DataFactoryName, GatewayName, Credential, Type);
7681
}
7782

7883
WriteObject(encryptedValue);

src/ResourceManager/DataFactories/Commands.DataFactories/Microsoft.Azure.Commands.DataFactories.dll-Help.xml

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2088,6 +2088,13 @@
20882088
</maml:description>
20892089
<command:parameterValue required="true" variableLength="false">PSCredential</command:parameterValue>
20902090
</command:parameter>
2091+
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="5" aliases="">
2092+
<maml:name>Type</maml:name>
2093+
<maml:description>
2094+
<maml:para>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.</maml:para>
2095+
</maml:description>
2096+
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
2097+
</command:parameter>
20912098
</command:syntaxItem>
20922099
<command:syntaxItem>
20932100
<maml:name>New-AzureDataFactoryEncryptValue</maml:name>
@@ -2126,6 +2133,13 @@
21262133
</maml:description>
21272134
<command:parameterValue required="true" variableLength="false">PSCredential</command:parameterValue>
21282135
</command:parameter>
2136+
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="6" aliases="">
2137+
<maml:name>Type</maml:name>
2138+
<maml:description>
2139+
<maml:para>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.</maml:para>
2140+
</maml:description>
2141+
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
2142+
</command:parameter>
21292143
</command:syntaxItem>
21302144
</command:syntax>
21312145
<command:parameters>
@@ -2201,6 +2215,18 @@
22012215
</dev:type>
22022216
<dev:defaultValue></dev:defaultValue>
22032217
</command:parameter>
2218+
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="6" aliases="">
2219+
<maml:name>Type</maml:name>
2220+
<maml:description>
2221+
<maml:para>Specifies the linked service type. For on premises SQL linked service, type OnPremisesSqlLinkedService. For file system linked service, type OnPremisesFileSystemLinkedService. </maml:para>
2222+
</maml:description>
2223+
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
2224+
<dev:type>
2225+
<maml:name>String</maml:name>
2226+
<maml:uri />
2227+
</dev:type>
2228+
<dev:defaultValue></dev:defaultValue>
2229+
</command:parameter>
22042230
</command:parameters>
22052231
<command:inputTypes>
22062232
<command:inputType>
@@ -2277,13 +2303,35 @@
22772303
<dev:code>
22782304
PS C:\&gt; $Value = ConvertTo-SecureString "Data Source=ContosoServer;Initial Catalog=catelog;Integrated Security=True" -AsPlainText -Force
22792305
PS C:\&gt; $Credential = Get-Credential
2280-
PS C:\&gt; New-AzureDataFactoryEncryptValue -DataFactoryName "UncycloADF" -GatewayName "UncycloGateway" -ResourceGroupName "ADF" -Value $Value -Credential $Credential
2306+
PS C:\&gt; New-AzureDataFactoryEncryptValue -DataFactoryName "UncycloADF" -GatewayName "UncycloGateway" -ResourceGroupName "ADF" -Value $Value -Credential $Credential -Type OnPremisesSqlLinkedService
22812307
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==
22822308
</dev:code>
22832309
<dev:remarks>
22842310
<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>
22852311
<maml:para>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.</maml:para>
2286-
<maml:para>The third command creates an encrypted value for the object stored in $Value and $Credential for the specified data factory, gateway, and resource group. </maml:para>
2312+
<maml:para>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. </maml:para>
2313+
</dev:remarks>
2314+
<command:commandLines>
2315+
<command:commandLine>
2316+
<command:commandText />
2317+
</command:commandLine>
2318+
</command:commandLines>
2319+
</command:example>
2320+
<command:example>
2321+
<maml:title>Example 4: Encrypt the file system host name</maml:title>
2322+
<maml:introduction>
2323+
<maml:para></maml:para>
2324+
</maml:introduction>
2325+
<dev:code>
2326+
PS C:\&gt; $Value = ConvertTo-SecureString "hostname" -AsPlainText -Force
2327+
PS C:\&gt; $Credential = Get-Credential
2328+
PS C:\&gt; New-AzureDataFactoryEncryptValue -DataFactoryName "UncycloADF" -GatewayName "UncycloGateway" -ResourceGroupName "ADF" -Value $Value -Credential $Credential -Type OnPremisesFileSystemLinkedService
2329+
EncryptedCredential=KAAAAAABAAAQAAAAQUU5MUVBNzY4QkFCQkI3MEUwRTMxOUNFNkM0MjRDOTVDNDk3RTcyRi8XAXyE/H+f3JydTkdg5t2g1eC/VtyF3NAD3idYnhrAphPJmO0pCaG5nH2IY48L3XJi7wabrlrGF+ieiWh1bwdgdxrW+t2jWPnLvT/ENUXtcevpx/dmTGKagH8TU9HLcoL1CAanb7Vkpga1B/uzRxBnVdsdtfvBzxG2M810tj1WzL8lFzA1mO5GbB0+ge116y0scL1vxjerjl5Muv0r0scG3lhj+IF0sXUMITFvhQwOIqweR052E6JlfJu+mTNFLCCkpw1iV+rhRhKqJF752dBuWjzI1EoyQUE17oK4OevkquuhUbfJmzj9BhGKQ+VkndAZiSw19FEGSC7JzoUe/XWEs/FJYrQCCXIeNS94J9/VzN6KPYJR1pzAYCtnhq+p8Q==
2330+
</dev:code>
2331+
<dev:remarks>
2332+
<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>
2333+
<maml:para>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.</maml:para>
2334+
<maml:para>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. </maml:para>
22872335
</dev:remarks>
22882336
<command:commandLines>
22892337
<command:commandLine>

src/ResourceManager/DataFactories/Commands.DataFactories/Models/DataFactoryClient.Encrypt.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@ public virtual string CloudEncryptString(SecureString value, string resourceGrou
3333
resourceGroupName, dataFactoryName);
3434
}
3535

36-
public virtual string OnPremisesEncryptString(SecureString value, string resourceGroupName, string dataFactoryName, string gatewayName, PSCredential credential)
36+
public virtual string OnPremisesEncryptString(SecureString value, string resourceGroupName, string dataFactoryName, string gatewayName, PSCredential credential, string type)
3737
{
3838
if (value == null)
3939
{
4040
throw new ArgumentNullException("value");
4141
}
4242

43+
LinkedServiceType linkedServiceType = type == null ? LinkedServiceType.OnPremisesSqlLinkedService : (LinkedServiceType) Enum.Parse(typeof(LinkedServiceType), type, true);
44+
4345
var response = DataPipelineManagementClient.Gateways.RetrieveConnectionInfo(resourceGroupName, dataFactoryName, gatewayName);
4446
var gatewayEncryptionInfos = new[]
4547
{
@@ -54,9 +56,8 @@ public virtual string OnPremisesEncryptString(SecureString value, string resourc
5456

5557
string userName = credential != null ? credential.UserName : null;
5658
SecureString password = credential != null ? credential.Password : null;
57-
UserInputConnectionString connectionString = new UserInputConnectionString(value, userName, password);
58-
var gatewayEncryptionClient = new GatewayEncryptionClient();
59-
return gatewayEncryptionClient.Encrypt(connectionString, gatewayEncryptionInfos);
59+
UserInputConnectionString connectionString = new UserInputConnectionString(value, userName, password, linkedServiceType);
60+
return GatewayEncryptionClient.Encrypt(connectionString, gatewayEncryptionInfos);
6061
}
6162
}
6263
}

src/ResourceManager/DataFactories/Commands.DataFactories/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net45" />
1111
<package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net45" />
1212
<package id="Microsoft.DataFactories.Runtime" version="0.11.1-preview" targetFramework="net45" />
13-
<package id="Microsoft.DataTransfer.Gateway.Encryption" version="1.1.0-preview" targetFramework="net45" />
13+
<package id="Microsoft.DataTransfer.Gateway.Encryption" version="1.2.1-preview" targetFramework="net45" />
1414
<package id="Microsoft.IdentityModel.Clients.ActiveDirectory" version="2.11.10918.1222" targetFramework="net45" />
1515
<package id="Microsoft.Net.Http" version="2.2.28" targetFramework="net45" />
1616
<package id="Microsoft.WindowsAzure.Management" version="4.0.0" targetFramework="net45" />

0 commit comments

Comments
 (0)