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