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 . DataLakeAnalytics . Models ;
16
+ using Microsoft . Azure . Commands . DataLakeAnalytics . Properties ;
17
+ using Microsoft . Azure . Management . DataLake . Analytics . Models ;
18
+ using System ;
19
+ using System . Management . Automation ;
20
+ using System . Security ;
21
+
22
+ namespace Microsoft . Azure . Commands . DataLakeAnalytics
23
+ {
24
+ [ Cmdlet ( VerbsCommon . Set , "AzureRmDataLakeAnalyticsCatalogCredential" ) , OutputType ( typeof ( USqlCredential ) ) ]
25
+ [ Alias ( "Set-AdlCatalogCredential" ) ]
26
+ public class SetAzureDataLakeAnalyticsCatalogCredential : DataLakeAnalyticsCmdletBase
27
+ {
28
+ internal const string BaseParameterSetName = "Specify full URI" ;
29
+ internal const string HostAndPortParameterSetName = "Specify host name and port" ;
30
+
31
+ [ Parameter ( ValueFromPipelineByPropertyName = true , ParameterSetName = BaseParameterSetName , Position = 0 ,
32
+ Mandatory = true , HelpMessage = "The account name that contains the catalog to create the credential in." ) ]
33
+ [ Parameter ( ValueFromPipelineByPropertyName = true , ParameterSetName = HostAndPortParameterSetName , Position = 0 ,
34
+ Mandatory = true , HelpMessage = "The account name that contains the catalog to create the credential in." ) ]
35
+ [ ValidateNotNullOrEmpty ]
36
+ [ Alias ( "AccountName" ) ]
37
+ public string Account { get ; set ; }
38
+
39
+ [ Parameter ( ValueFromPipelineByPropertyName = true , ParameterSetName = BaseParameterSetName , Position = 1 ,
40
+ Mandatory = true , HelpMessage = "The name of the database to create the credential in." ) ]
41
+ [ Parameter ( ValueFromPipelineByPropertyName = true , ParameterSetName = HostAndPortParameterSetName , Position = 1 ,
42
+ Mandatory = true , HelpMessage = "The name of the database to create the credential in." ) ]
43
+ [ ValidateNotNullOrEmpty ]
44
+ public string DatabaseName { get ; set ; }
45
+
46
+ [ Parameter ( ValueFromPipelineByPropertyName = true , ParameterSetName = BaseParameterSetName , Position = 1 ,
47
+ Mandatory = true , HelpMessage = "The name of the credential to create." ) ]
48
+ [ Parameter ( ValueFromPipelineByPropertyName = true , ParameterSetName = HostAndPortParameterSetName , Position = 1 ,
49
+ Mandatory = true , HelpMessage = "The name of the credential to create." ) ]
50
+ [ ValidateNotNullOrEmpty ]
51
+ public string CredentialName { get ; set ; }
52
+
53
+ [ Parameter ( ValueFromPipelineByPropertyName = true , ParameterSetName = BaseParameterSetName , Position = 2 ,
54
+ Mandatory = true , HelpMessage = "The credential to create, which includes the user ID and password that can authenticate to the data source" ) ]
55
+ [ Parameter ( ValueFromPipelineByPropertyName = true , ParameterSetName = HostAndPortParameterSetName , Position = 2 ,
56
+ Mandatory = true , HelpMessage = "The credential to create, which includes the user ID and password that can authenticate to the data source" ) ]
57
+ [ ValidateNotNullOrEmpty ]
58
+ public PSCredential Credential { get ; set ; }
59
+
60
+ [ Parameter ( ValueFromPipelineByPropertyName = true , ParameterSetName = BaseParameterSetName , Position = 3 ,
61
+ Mandatory = true , HelpMessage = "The new password for the credential" ) ]
62
+ [ Parameter ( ValueFromPipelineByPropertyName = true , ParameterSetName = HostAndPortParameterSetName , Position = 3 ,
63
+ Mandatory = true , HelpMessage = "The new password for the credential" ) ]
64
+ [ ValidateNotNullOrEmpty ]
65
+ public PSCredential NewPassword { get ; set ; }
66
+
67
+ [ Parameter ( ValueFromPipelineByPropertyName = true , ParameterSetName = HostAndPortParameterSetName , Position = 4 ,
68
+ Mandatory = true , HelpMessage = "The URI of the database to connect to." ) ]
69
+ public Uri Uri { get ; set ; }
70
+
71
+ [ Parameter ( ValueFromPipelineByPropertyName = true , ParameterSetName = BaseParameterSetName , Position = 4 ,
72
+ Mandatory = true , HelpMessage = "The host of the database to connect to in the format 'myhost.dns.com'." ) ]
73
+ public string DatabaseHost { get ; set ; }
74
+
75
+ [ Parameter ( ValueFromPipelineByPropertyName = true , ParameterSetName = BaseParameterSetName , Position = 5 ,
76
+ Mandatory = true , HelpMessage = "The Port associated with the host for the database to connect to." ) ]
77
+ public int Port { get ; set ; }
78
+
79
+ public override void ExecuteCmdlet ( )
80
+ {
81
+ if ( Uri != null && Uri . Port <= 0 )
82
+ {
83
+ WriteWarning ( string . Format ( Resources . NoPortSpecified , Uri ) ) ;
84
+ }
85
+
86
+ var toUse = Uri ?? new Uri ( string . Format ( "https://{0}:{1}" , DatabaseHost , Port ) ) ;
87
+
88
+ DataLakeAnalyticsClient . UpdateCredentialPassword ( Account , DatabaseName , CredentialName , Credential . UserName ,
89
+ Credential . GetNetworkCredential ( ) . Password , NewPassword . GetNetworkCredential ( ) . Password , toUse . AbsoluteUri ) ;
90
+ }
91
+ }
92
+ }
0 commit comments