11
11
// See the License for the specific language governing permissions and
12
12
// limitations under the License.
13
13
// ----------------------------------------------------------------------------------
14
- using Microsoft . Azure . Commands . Common ;
15
14
using Microsoft . Azure . Commands . Common . Authentication ;
16
15
using Microsoft . Azure . Commands . Common . Authentication . Abstractions ;
17
16
using Microsoft . Azure . Commands . Common . Authentication . Models ;
18
17
using Microsoft . Azure . Commands . Common . Authentication . ResourceManager ;
19
- using Microsoft . Azure . Commands . Common . Exceptions ;
20
18
using Microsoft . Azure . Commands . Profile . Models ;
21
19
using Microsoft . Azure . Commands . Profile . Properties ;
22
20
using Microsoft . Azure . Commands . Profile . Utilities ;
23
- using Microsoft . Azure . Management . Profiles . Storage . Version2019_06_01 . Models ;
24
- using Microsoft . Identity . Client . NativeInterop ;
25
21
using Microsoft . Rest . Azure ;
26
22
using Microsoft . WindowsAzure . Commands . Common ;
27
23
28
24
using System ;
29
25
using System . Collections . Generic ;
30
26
using System . Linq ;
31
27
using System . Management . Automation ;
32
- using System . Runtime . InteropServices ;
33
28
using System . Security ;
34
- using System . Security . Authentication . ExtendedProtection ;
35
- using System . Text ;
36
29
37
30
using AuthenticationMessages = Microsoft . Azure . Commands . Common . Authentication . Properties . Resources ;
38
31
using ProfileMessages = Microsoft . Azure . Commands . Profile . Properties . Resources ;
@@ -46,7 +39,7 @@ public class RMProfileClient
46
39
private IAzureTokenCache _cache ;
47
40
public Action < string > WarningLog ;
48
41
public Action < string > DebugLog ;
49
- public Action < string > InformationLog ;
42
+ public Action < string > InteractiveInformationLog ;
50
43
internal Func < string , string > PromptAndReadLine ;
51
44
52
45
private List < AzureTenant > _queriedTenants = new List < AzureTenant > ( ) ;
@@ -137,18 +130,21 @@ public AzureRmProfile Login(
137
130
bool shouldPopulateContextList = true ,
138
131
int maxContextPopulation = Profile . ConnectAzureRmAccountCommand . DefaultMaxContextPopulation ,
139
132
string authScope = null ,
140
- bool isInteractiveAuthenticationFlow = false ,
141
133
bool IsInteractiveContextSelectionEnabled = true )
142
134
{
143
- if ( isInteractiveAuthenticationFlow ) WriteInformationMessage ( $ "{ PSStyle . ForegroundColor . BrightYellow } { Resources . PleaseSelectAccount } { PSStyle . Reset } { System . Environment . NewLine } ") ;
135
+
136
+ WriteInteractiveInformationMessage ( $ "{ PSStyle . ForegroundColor . BrightYellow } { Resources . PleaseSelectAccount } { PSStyle . Reset } { System . Environment . NewLine } ") ;
144
137
145
138
IAzureSubscription defaultSubscription = null ;
146
139
IAzureTenant defaultTenant = null ;
147
140
List < AzureSubscription > subscriptions = new List < AzureSubscription > ( ) ;
148
141
List < AzureSubscription > tempSubscriptions = null ;
149
142
string tenantName = null ;
150
143
151
- bool selectSubscriptionFromList = isInteractiveAuthenticationFlow && IsInteractiveContextSelectionEnabled && string . IsNullOrEmpty ( subscriptionId ) && string . IsNullOrEmpty ( subscriptionName ) ;
144
+ bool selectSubscriptionFromList = AzureAccount . AccountType . User . Equals ( account . Type ) &&
145
+ IsInteractiveContextSelectionEnabled &&
146
+ string . IsNullOrEmpty ( subscriptionId ) &&
147
+ string . IsNullOrEmpty ( subscriptionName ) ;
152
148
var lastUsedSubscription = selectSubscriptionFromList ? _profile ? . DefaultContext ? . Subscription : null ;
153
149
154
150
string promptBehavior =
@@ -242,7 +238,7 @@ public AzureRmProfile Login(
242
238
throw new ArgumentNullException ( string . Format ( $ "{ e . Message } { Environment . NewLine } { baseMessage } { typeMessage } ") , e ) ;
243
239
}
244
240
245
- WriteInformationMessage ( Resources . RetrievingSubscription ) ;
241
+ WriteInteractiveInformationMessage ( Resources . RetrievingSubscription ) ;
246
242
tempSubscriptions = null ;
247
243
if ( TryGetTenantSubscription (
248
244
token ,
@@ -253,8 +249,7 @@ public AzureRmProfile Login(
253
249
true ,
254
250
out defaultSubscription ,
255
251
out defaultTenant ,
256
- out tempSubscriptions ,
257
- isInteractiveAuthenticationFlow ) )
252
+ out tempSubscriptions ) )
258
253
{
259
254
account . SetOrAppendProperty ( AzureAccount . Property . Tenants , new [ ] { defaultTenant . Id . ToString ( ) } ) ;
260
255
@@ -267,7 +262,7 @@ public AzureRmProfile Login(
267
262
{
268
263
InteractiveSubscriptionSelectionHelper . SelectSubscriptionFromList (
269
264
subscriptions , _queriedTenants , tenantIdOrName , tenantName , lastUsedSubscription ,
270
- Prompt , WriteInformationMessage ,
265
+ Prompt , WriteInteractiveInformationMessage ,
271
266
ref defaultSubscription , ref defaultTenant ) ;
272
267
}
273
268
}
@@ -283,7 +278,7 @@ public AzureRmProfile Login(
283
278
IAzureSubscription tempSubscription = null ;
284
279
tempSubscriptions = null ;
285
280
286
- WriteInformationMessage ( Resources . RetrievingSubscription ) ;
281
+ WriteInteractiveInformationMessage ( Resources . RetrievingSubscription ) ;
287
282
288
283
foreach ( var tenant in _queriedTenants )
289
284
{
@@ -323,7 +318,7 @@ public AzureRmProfile Login(
323
318
324
319
if ( token != null &&
325
320
( defaultTenant == null || selectSubscriptionFromList ) &&
326
- TryGetTenantSubscription ( token , account , environment , subscriptionId , subscriptionName , false , out tempSubscription , out tempTenant , out tempSubscriptions , isInteractiveAuthenticationFlow ) )
321
+ TryGetTenantSubscription ( token , account , environment , subscriptionId , subscriptionName , false , out tempSubscription , out tempTenant , out tempSubscriptions ) )
327
322
{
328
323
// If no subscription found for the given token/tenant,discard tempTenant value.
329
324
// Continue to look for matched subscripitons until one subscription retrived by its home tenant is found.
@@ -350,7 +345,7 @@ public AzureRmProfile Login(
350
345
{
351
346
InteractiveSubscriptionSelectionHelper . SelectSubscriptionFromList (
352
347
subscriptions , _queriedTenants , tenantIdOrName , tenantName , lastUsedSubscription ,
353
- Prompt , WriteInformationMessage ,
348
+ Prompt , WriteInteractiveInformationMessage ,
354
349
ref defaultSubscription , ref defaultTenant ) ;
355
350
}
356
351
}
@@ -385,7 +380,7 @@ public AzureRmProfile Login(
385
380
WriteWarningMessage ( string . Format ( ProfileMessages . CannotSetDefaultContext , defaultContext . ToString ( ) ) ) ;
386
381
}
387
382
388
- if ( ! skipValidation && ! defaultSubscription . State . Equals ( "Enabled" , StringComparison . OrdinalIgnoreCase ) )
383
+ if ( ! skipValidation && null != defaultSubscription . State && ! defaultSubscription . State . Equals ( "Enabled" , StringComparison . OrdinalIgnoreCase ) )
389
384
{
390
385
WriteWarningMessage ( string . Format (
391
386
ProfileMessages . SelectedSubscriptionNotActive ,
@@ -707,9 +702,9 @@ private bool TryGetTenantSubscription(IAccessToken accessToken,
707
702
bool isTenantPresent ,
708
703
out IAzureSubscription subscription ,
709
704
out IAzureTenant tenant ,
710
- out List < AzureSubscription > subscriptions ,
711
- bool isInteractiveAuthentication )
705
+ out List < AzureSubscription > subscriptions )
712
706
{
707
+ bool isInteractiveAuthentication = AzureAccount . AccountType . User . Equals ( account . Type ) ;
713
708
subscriptions = new List < AzureSubscription > ( ) ;
714
709
subscription = null ;
715
710
if ( accessToken != null )
@@ -881,11 +876,11 @@ private void WriteDebugMessage(string message)
881
876
DebugLog ( message ) ;
882
877
}
883
878
}
884
- private void WriteInformationMessage ( string message )
879
+ private void WriteInteractiveInformationMessage ( string message )
885
880
{
886
- if ( InformationLog != null )
881
+ if ( InteractiveInformationLog != null )
887
882
{
888
- InformationLog ( message ) ;
883
+ InteractiveInformationLog ( message ) ;
889
884
}
890
885
}
891
886
0 commit comments