Skip to content

Commit 1712c28

Browse files
committed
[Azure PowerShell]Add ODBC connection string credential encyrption support on New-AzureDataFactoryEncryptValue
1 parent 638cca1 commit 1712c28

File tree

6 files changed

+149
-31
lines changed

6 files changed

+149
-31
lines changed

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public void TestOnPremDatasourceEncryptionSQLAuth()
3737
SecureString secureString = new SecureString();
3838
string expectedOutput = "My encrypted string " + Guid.NewGuid();
3939
string linkedServiceType = "OnPremisesSqlLinkedService";
40+
string nonCredentialValue = "Driver=mydriver;server=myserver";
41+
string authenticationType = "Basic";
4042

4143
var cmdlet = new NewAzureDataFactoryEncryptValueCommand
4244
{
@@ -46,17 +48,19 @@ public void TestOnPremDatasourceEncryptionSQLAuth()
4648
ResourceGroupName = ResourceGroupName,
4749
DataFactoryName = DataFactoryName,
4850
GatewayName = GatewayName,
49-
Type = linkedServiceType
51+
Type = linkedServiceType,
52+
NonCredentialValue = nonCredentialValue,
53+
AuthenticationType = authenticationType
5054
};
5155

5256
// Arrange
53-
this.dataFactoriesClientMock.Setup(f => f.OnPremisesEncryptString(secureString, ResourceGroupName, DataFactoryName, GatewayName, null, linkedServiceType)).Returns(expectedOutput);
57+
this.dataFactoriesClientMock.Setup(f => f.OnPremisesEncryptString(secureString, ResourceGroupName, DataFactoryName, GatewayName, null, linkedServiceType, nonCredentialValue, authenticationType)).Returns(expectedOutput);
5458

5559
// Action
5660
cmdlet.ExecuteCmdlet();
5761

5862
// Assert
59-
this.dataFactoriesClientMock.Verify(f => f.OnPremisesEncryptString(secureString, ResourceGroupName, DataFactoryName, GatewayName, null, linkedServiceType), Times.Once());
63+
this.dataFactoriesClientMock.Verify(f => f.OnPremisesEncryptString(secureString, ResourceGroupName, DataFactoryName, GatewayName, null, linkedServiceType, nonCredentialValue, authenticationType), Times.Once());
6064
this.commandRuntimeMock.Verify(f => f.WriteObject(expectedOutput), Times.Once());
6165
}
6266

@@ -70,6 +74,8 @@ public void TestOnPremDatasourceEncryptionWinAuth()
7074
SecureString winAuthPassword = new SecureString();
7175
PSCredential credential = new PSCredential(winAuthUserName, winAuthPassword);
7276
string linkedServiceType = "OnPremisesFileSystemLinkedService";
77+
string nonCredentialValue = "Driver=mydriver;server=myserver";
78+
string authenticationType = "Basic";
7379

7480
var cmdlet = new NewAzureDataFactoryEncryptValueCommand
7581
{
@@ -80,17 +86,19 @@ public void TestOnPremDatasourceEncryptionWinAuth()
8086
DataFactoryName = DataFactoryName,
8187
GatewayName = GatewayName,
8288
Credential = credential,
83-
Type = linkedServiceType
89+
Type = linkedServiceType,
90+
NonCredentialValue = nonCredentialValue,
91+
AuthenticationType = authenticationType
8492
};
8593

8694
// Arrange
87-
this.dataFactoriesClientMock.Setup(f => f.OnPremisesEncryptString(secureString, ResourceGroupName, DataFactoryName, GatewayName, credential, linkedServiceType)).Returns(expectedOutput);
95+
this.dataFactoriesClientMock.Setup(f => f.OnPremisesEncryptString(secureString, ResourceGroupName, DataFactoryName, GatewayName, credential, linkedServiceType, nonCredentialValue, authenticationType)).Returns(expectedOutput);
8896

8997
// Action
9098
cmdlet.ExecuteCmdlet();
9199

92100
// Assert
93-
this.dataFactoriesClientMock.Verify(f => f.OnPremisesEncryptString(secureString, ResourceGroupName, DataFactoryName, GatewayName, credential, linkedServiceType), Times.Once());
101+
this.dataFactoriesClientMock.Verify(f => f.OnPremisesEncryptString(secureString, ResourceGroupName, DataFactoryName, GatewayName, credential, linkedServiceType, nonCredentialValue, authenticationType), Times.Once());
94102
this.commandRuntimeMock.Verify(f => f.WriteObject(expectedOutput), Times.Once());
95103
}
96104
}

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.3.0-preview\lib\net45\Microsoft.DataTransfer.Gateway.Encryption.dll</HintPath>
76+
<HintPath>..\..\..\packages\Microsoft.DataTransfer.Gateway.Encryption.1.4.0-preview\lib\net45\Microsoft.DataTransfer.Gateway.Encryption.dll</HintPath>
7777
</Reference>
7878
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory">
7979
<SpecificVersion>False</SpecificVersion>

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ public class NewAzureDataFactoryEncryptValueCommand : DataFactoryBaseCmdlet
3434
[ValidateNotNullOrEmpty]
3535
public string DataFactoryName { get; set; }
3636

37-
[Parameter(ParameterSetName = ByFactoryObject, Position = 1, Mandatory = true, HelpMessage = "The value to encrypt.")]
38-
[Parameter(ParameterSetName = ByFactoryName, Position = 2, Mandatory = true, HelpMessage = "The value to encrypt.")]
39-
[ValidateNotNullOrEmpty]
37+
[Parameter(ParameterSetName = ByFactoryObject, Position = 1, Mandatory = false, HelpMessage = "The value to encrypt.")]
38+
[Parameter(ParameterSetName = ByFactoryName, Position = 2, Mandatory = false, HelpMessage = "The value to encrypt.")]
4039
public SecureString Value { get; set; }
4140

4241
[Parameter(ParameterSetName = ByFactoryObject, Position = 2, Mandatory = false, HelpMessage = "The gateway group name.")]
@@ -49,9 +48,18 @@ public class NewAzureDataFactoryEncryptValueCommand : DataFactoryBaseCmdlet
4948

5049
[Parameter(ParameterSetName = ByFactoryObject, Position = 4, Mandatory = false, HelpMessage = "The linked service type.")]
5150
[Parameter(ParameterSetName = ByFactoryName, Position = 5, Mandatory = false, HelpMessage = "The linked service type.")]
52-
[ValidateSet("OnPremisesSqlLinkedService", "OnPremisesFileSystemLinkedService", "OnPremisesOracleLinkedService", IgnoreCase = true)]
51+
[ValidateSet("OnPremisesSqlLinkedService", "OnPremisesFileSystemLinkedService", "OnPremisesOracleLinkedService", "OnPremisesOdbcLinkedService", IgnoreCase = true)]
5352
public string Type { get; set; }
5453

54+
[Parameter(ParameterSetName = ByFactoryObject, Position = 5, Mandatory = false, HelpMessage = "The non-credential value.")]
55+
[Parameter(ParameterSetName = ByFactoryName, Position = 6, Mandatory = false, HelpMessage = "The non-credential value.")]
56+
public string NonCredentialValue { get; set; }
57+
58+
[Parameter(ParameterSetName = ByFactoryObject, Position = 6, Mandatory = false, HelpMessage = "The authentication type.")]
59+
[Parameter(ParameterSetName = ByFactoryName, Position = 7, Mandatory = false, HelpMessage = "The authentication type.")]
60+
[ValidateSet("Windows", "Basic", "Anonymous", IgnoreCase = true)]
61+
public string AuthenticationType { get; set; }
62+
5563
[EnvironmentPermission(SecurityAction.Demand, Unrestricted = true)]
5664
public override void ExecuteCmdlet()
5765
{
@@ -77,7 +85,7 @@ public override void ExecuteCmdlet()
7785
else
7886
{
7987
// On-premises encryption with Gateway
80-
encryptedValue = DataFactoryClient.OnPremisesEncryptString(Value, ResourceGroupName, DataFactoryName, GatewayName, Credential, Type);
88+
encryptedValue = DataFactoryClient.OnPremisesEncryptString(Value, ResourceGroupName, DataFactoryName, GatewayName, Credential, Type, NonCredentialValue, AuthenticationType);
8189
}
8290

8391
WriteObject(encryptedValue);

0 commit comments

Comments
 (0)