Skip to content

Commit 625e645

Browse files
committed
Merge branch 'dev' of github.com:Azure/azure-powershell into django
2 parents c344596 + a479b9f commit 625e645

File tree

6 files changed

+502
-0
lines changed

6 files changed

+502
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@
159159
<Compile Include="Properties\AssemblyInfo.cs" />
160160
<Compile Include="ScenarioTests\DataFactoriesScenarioTestsBase.cs" />
161161
<Compile Include="ScenarioTests\DataFactoryTests.cs" />
162+
<Compile Include="UnitTests\NewDataFactoryEncryptValueTests.cs" />
162163
<Compile Include="UnitTests\NewDataFactoryGatewayKeyTests.cs" />
163164
<Compile Include="UnitTests\NewDataFactoryGatewayTests.cs" />
164165
<Compile Include="UnitTests\NewLinkedServiceTests.cs" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Commands.DataFactories;
16+
using Microsoft.Azure.Commands.DataFactories.Test;
17+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
18+
using Moq;
19+
using System;
20+
using System.Management.Automation;
21+
using System.Security;
22+
using Xunit;
23+
24+
namespace Microsoft.WindowsAzure.Commands.Test.DataFactory
25+
{
26+
public class NewDataFactoryEncryptValueTests : DataFactoryUnitTestBase
27+
{
28+
public NewDataFactoryEncryptValueTests()
29+
{
30+
base.SetupTest();
31+
}
32+
33+
[Fact]
34+
[Trait(Category.AcceptanceType, Category.CheckIn)]
35+
public void TestOnPremDatasourceEncryptionSQLAuth()
36+
{
37+
SecureString secureString = new SecureString();
38+
string expectedOutput = "My encrypted string " + Guid.NewGuid();
39+
string linkedServiceType = "OnPremisesSqlLinkedService";
40+
41+
var cmdlet = new NewAzureDataFactoryEncryptValueCommand
42+
{
43+
CommandRuntime = this.commandRuntimeMock.Object,
44+
DataFactoryClient = this.dataFactoriesClientMock.Object,
45+
Value = secureString,
46+
ResourceGroupName = ResourceGroupName,
47+
DataFactoryName = DataFactoryName,
48+
GatewayName = GatewayName,
49+
Type = linkedServiceType
50+
};
51+
52+
// Arrange
53+
this.dataFactoriesClientMock.Setup(f => f.OnPremisesEncryptString(secureString, ResourceGroupName, DataFactoryName, GatewayName, null, linkedServiceType)).Returns(expectedOutput);
54+
55+
// Action
56+
cmdlet.ExecuteCmdlet();
57+
58+
// Assert
59+
this.dataFactoriesClientMock.Verify(f => f.OnPremisesEncryptString(secureString, ResourceGroupName, DataFactoryName, GatewayName, null, linkedServiceType), Times.Once());
60+
this.commandRuntimeMock.Verify(f => f.WriteObject(expectedOutput), Times.Once());
61+
}
62+
63+
[Fact]
64+
[Trait(Category.AcceptanceType, Category.CheckIn)]
65+
public void TestOnPremDatasourceEncryptionWinAuth()
66+
{
67+
SecureString secureString = new SecureString();
68+
string expectedOutput = "My encrypted string " + Guid.NewGuid();
69+
string winAuthUserName = "foo";
70+
SecureString winAuthPassword = new SecureString();
71+
PSCredential credential = new PSCredential(winAuthUserName, winAuthPassword);
72+
string linkedServiceType = "OnPremisesFileSystemLinkedService";
73+
74+
var cmdlet = new NewAzureDataFactoryEncryptValueCommand
75+
{
76+
CommandRuntime = this.commandRuntimeMock.Object,
77+
DataFactoryClient = this.dataFactoriesClientMock.Object,
78+
Value = secureString,
79+
ResourceGroupName = ResourceGroupName,
80+
DataFactoryName = DataFactoryName,
81+
GatewayName = GatewayName,
82+
Credential = credential,
83+
Type = linkedServiceType
84+
};
85+
86+
// Arrange
87+
this.dataFactoriesClientMock.Setup(f => f.OnPremisesEncryptString(secureString, ResourceGroupName, DataFactoryName, GatewayName, credential, linkedServiceType)).Returns(expectedOutput);
88+
89+
// Action
90+
cmdlet.ExecuteCmdlet();
91+
92+
// Assert
93+
this.dataFactoriesClientMock.Verify(f => f.OnPremisesEncryptString(secureString, ResourceGroupName, DataFactoryName, GatewayName, credential, linkedServiceType), Times.Once());
94+
this.commandRuntimeMock.Verify(f => f.WriteObject(expectedOutput), Times.Once());
95+
}
96+
}
97+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@
140140
<Compile Include="DataSlices\GetAzureDataFactorySliceCommand.cs" />
141141
<Compile Include="DataSlices\SaveAzureDataFactoryLog.cs" />
142142
<Compile Include="DataSlices\SetAzureDataFactorySliceStatusCommand.cs" />
143+
<Compile Include="Encrypt\NewAzureDataFactoryEncryptValueCommand.cs" />
143144
<Compile Include="Gateway\GetAzureDataFactoryGatewayCommand.cs" />
144145
<Compile Include="Gateway\NewAzureDataFactoryGatewayCommand.cs" />
145146
<Compile Include="Gateway\NewAzureDataFactoryGatewayKeyCommand.cs" />

src/ResourceManager/DataFactories/Commands.DataFactories/Constants.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ internal static class Constants
2828

2929
public const string GatewayKey = "AzureDataFactoryGatewayKey";
3030

31+
public const string EncryptString = "AzureDataFactoryEncryptValue";
32+
3133
public const string Table = "AzureDataFactoryTable";
3234

3335
public const string Pipeline = "AzureDataFactoryPipeline";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System;
16+
using System.Globalization;
17+
using System.Management.Automation;
18+
using System.Security;
19+
using System.Security.Permissions;
20+
using Microsoft.Azure.Commands.DataFactories.Models;
21+
using Microsoft.Azure.Commands.DataFactories.Properties;
22+
23+
namespace Microsoft.Azure.Commands.DataFactories
24+
{
25+
[Cmdlet(VerbsCommon.New, Constants.EncryptString, DefaultParameterSetName = ByFactoryName), OutputType(typeof(string))]
26+
public class NewAzureDataFactoryEncryptValueCommand : DataFactoryBaseCmdlet
27+
{
28+
[Parameter(ParameterSetName = ByFactoryObject, Position = 0, Mandatory = true, ValueFromPipelineByPropertyName = true,
29+
HelpMessage = "The data factory object.")]
30+
public PSDataFactory DataFactory { get; set; }
31+
32+
[Parameter(ParameterSetName = ByFactoryName, Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true,
33+
HelpMessage = "The data factory name.")]
34+
[ValidateNotNullOrEmpty]
35+
public string DataFactoryName { get; set; }
36+
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]
40+
public SecureString Value { get; set; }
41+
42+
[Parameter(ParameterSetName = ByFactoryObject, Position = 2, Mandatory = false, HelpMessage = "The gateway group name.")]
43+
[Parameter(ParameterSetName = ByFactoryName, Position = 3, Mandatory = false, HelpMessage = "The gateway group name.")]
44+
public string GatewayName { get; set; }
45+
46+
[Parameter(ParameterSetName = ByFactoryObject, Position = 3, Mandatory = false, HelpMessage = "The windows authentication credential.")]
47+
[Parameter(ParameterSetName = ByFactoryName, Position = 4, Mandatory = false, HelpMessage = "The windows authentication credential.")]
48+
public PSCredential Credential { get; set; }
49+
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", "OnPremisesOracleLinkedService", IgnoreCase = true)]
53+
public string Type { get; set; }
54+
55+
[EnvironmentPermission(SecurityAction.Demand, Unrestricted = true)]
56+
public override void ExecuteCmdlet()
57+
{
58+
if (ParameterSetName == ByFactoryObject)
59+
{
60+
if (DataFactory == null)
61+
{
62+
throw new PSArgumentNullException(string.Format(CultureInfo.InvariantCulture,
63+
Resources.DataFactoryArgumentInvalid));
64+
}
65+
66+
DataFactoryName = DataFactory.DataFactoryName;
67+
ResourceGroupName = DataFactory.ResourceGroupName;
68+
}
69+
70+
string encryptedValue = String.Empty;
71+
72+
if (String.IsNullOrWhiteSpace(GatewayName))
73+
{
74+
// Cloud encryption without Gateway
75+
WriteWarning("Cloud encryption has already been deprecated. Please run get-help new-azuredatafactoryencryptvalue to see other option of this command");
76+
}
77+
else
78+
{
79+
// On-premises encryption with Gateway
80+
encryptedValue = DataFactoryClient.OnPremisesEncryptString(Value, ResourceGroupName, DataFactoryName, GatewayName, Credential, Type);
81+
}
82+
83+
WriteObject(encryptedValue);
84+
}
85+
}
86+
}

0 commit comments

Comments
 (0)