@@ -86,59 +86,7 @@ public IAzureContextContainer DefaultProfile
86
86
set
87
87
{
88
88
_profile = value ;
89
- /* If the profile is from customer setting, the ServicePrincipalSecret and CertificatePassword
90
- * which is required to get access token is always removed.
91
- * Try to recover ServicePrincipalSecret and CertificatePassword from the buildin profile.
92
- */
93
- if ( null != _profile && null != AzureRmProfileProvider . Instance . Profile . Accounts )
94
- {
95
- var accountMap = CreateAccountMap ( AzureRmProfileProvider . Instance . Profile . Accounts ) ;
96
- foreach ( var currentAccount in _profile . Accounts . Where ( p => null != p ? . Id ) )
97
- {
98
- if ( accountMap . TryGetValue ( currentAccount . Id , out IList < IAzureAccount > accList ) )
99
- {
100
- foreach ( var acc in accList )
101
- {
102
- if ( currentAccount . GetTenants ( ) . All ( tId => acc . GetTenants ( ) . Contains ( tId ) ) )
103
- {
104
- MergeProperty ( currentAccount , acc , AzureAccount . Property . ServicePrincipalSecret ) ;
105
- MergeProperty ( currentAccount , acc , AzureAccount . Property . CertificatePassword ) ;
106
- break ;
107
- }
108
- }
109
- }
110
- }
111
- }
112
- }
113
- }
114
-
115
- private static Dictionary < string , IList < IAzureAccount > > CreateAccountMap ( IEnumerable < IAzureAccount > accounts )
116
- {
117
- var accountMap = new Dictionary < string , IList < IAzureAccount > > ( ) ;
118
- foreach ( var acc in accounts . Where ( acc => null != acc ? . Id && ( null != acc . GetProperty ( AzureAccount . Property . ServicePrincipalSecret )
119
- || null != acc . GetProperty ( AzureAccount . Property . CertificatePassword ) ) ) )
120
- {
121
- if ( ! accountMap . ContainsKey ( acc . Id ) )
122
- {
123
- accountMap [ acc . Id ] = new List < IAzureAccount > ( ) ;
124
- }
125
- accountMap [ acc . Id ] . Add ( acc ) ;
126
89
}
127
- return accountMap ;
128
- }
129
-
130
- private static bool MergeProperty ( IExtensibleModel dest , IExtensibleModel src , string propertyName )
131
- {
132
- if ( string . IsNullOrEmpty ( dest . GetProperty ( propertyName ) ) )
133
- {
134
- var propertyValue = src . GetProperty ( propertyName ) ;
135
- if ( ! string . IsNullOrEmpty ( propertyValue ) )
136
- {
137
- dest . SetProperty ( propertyName , propertyValue ) ;
138
- return true ;
139
- }
140
- }
141
- return false ;
142
90
}
143
91
144
92
private IAzureContextContainer GetDefaultProfile ( )
@@ -174,7 +122,10 @@ private IAzureContextContainer CloneProfileAndModifyContext()
174
122
}
175
123
profile . DefaultContext = profile . DefaultContext . DeepCopy ( ) ;
176
124
profile . DefaultContext . Subscription . CopyFrom ( matchingSub ) ;
177
- profile . DefaultContext . Tenant . Id = matchingSub . GetTenant ( ) ;
125
+ profile . DefaultContext . Tenant = new AzureTenant ( )
126
+ {
127
+ Id = matchingSub . GetTenant ( )
128
+ } ;
178
129
var matchingUser = profile . Accounts . FirstOrDefault ( account => account . Id . Equals ( matchingSub . GetAccount ( ) ) ) ;
179
130
if ( matchingUser != null )
180
131
{
0 commit comments