26
26
import com .microsoft .azure .maven .telemetry .TelemetryConfiguration ;
27
27
import com .microsoft .azure .maven .telemetry .TelemetryProxy ;
28
28
import com .microsoft .azure .maven .utils .CustomTextIoStringListReader ;
29
- import com .microsoft .azure .maven .utils . MavenAuthUtils ;
29
+ import com .microsoft .azure .maven .auth . MavenAuthManager ;
30
30
import com .microsoft .azure .maven .utils .MavenUtils ;
31
+ import com .microsoft .azure .maven .utils .ProxyUtils ;
31
32
import com .microsoft .azure .maven .utils .SystemPropertyUtils ;
32
- import com .microsoft .azure .toolkit .lib .common .proxy .ProxyManager ;
33
33
import com .microsoft .azure .tools .auth .util .AzureEnvironmentUtils ;
34
34
import com .microsoft .azure .tools .auth .exception .AzureLoginException ;
35
35
import com .microsoft .azure .tools .auth .model .AzureCredentialWrapper ;
@@ -310,7 +310,7 @@ protected String getAuthType() {
310
310
return StringUtils .firstNonBlank (auth == null ? null : auth .getType (), authType );
311
311
}
312
312
313
- protected String selectSubscription (Azure az , Subscription [] subscriptions ) throws AzureExecutionException {
313
+ protected String selectSubscription (Subscription [] subscriptions ) throws AzureExecutionException {
314
314
if (subscriptions .length == 0 ) {
315
315
throw new AzureExecutionException ("Cannot find any subscriptions in current account." );
316
316
}
@@ -319,12 +319,10 @@ protected String selectSubscription(Azure az, Subscription[] subscriptions) thro
319
319
TextUtils .blue (SubscriptionOption .getSubscriptionName (subscriptions [0 ]))));
320
320
return subscriptions [0 ].subscriptionId ();
321
321
}
322
- final String defaultId = Optional .ofNullable (az .getCurrentSubscription ()).map (Subscription ::subscriptionId ).orElse (null );
323
322
final List <SubscriptionOption > wrapSubs = Arrays .stream (subscriptions ).map (t -> new SubscriptionOption (t ))
324
323
.sorted ()
325
324
.collect (Collectors .toList ());
326
- final SubscriptionOption defaultValue = wrapSubs .stream ()
327
- .filter (t -> StringUtils .equalsIgnoreCase (t .getSubscriptionId (), defaultId )).findFirst ().orElse (null );
325
+ final SubscriptionOption defaultValue = wrapSubs .get (0 );
328
326
final TextIO textIO = TextIoFactory .getTextIO ();
329
327
final SubscriptionOption subscriptionOptionSelected = new CustomTextIoStringListReader <SubscriptionOption >(() -> textIO .getTextTerminal (), null )
330
328
.withCustomPrompt (String .format ("Please choose a subscription%s: " ,
@@ -342,7 +340,7 @@ protected Azure getOrCreateAzureClient() throws AzureAuthFailureException, Azure
342
340
mavenAuthConfiguration .setType (getAuthType ());
343
341
344
342
SystemPropertyUtils .injectCommandLineParameter ("auth" , mavenAuthConfiguration , MavenAuthConfiguration .class );
345
- azureCredentialWrapper = MavenAuthUtils .login (session , settingsDecrypter , mavenAuthConfiguration );
343
+ azureCredentialWrapper = MavenAuthManager . getInstance () .login (session , settingsDecrypter , mavenAuthConfiguration );
346
344
347
345
if (Objects .isNull (azureCredentialWrapper )) {
348
346
return null ;
@@ -354,11 +352,10 @@ protected Azure getOrCreateAzureClient() throws AzureAuthFailureException, Azure
354
352
Log .prompt (String .format (USING_AZURE_ENVIRONMENT , TextUtils .cyan (environmentName )));
355
353
}
356
354
Log .info (azureCredentialWrapper .getCredentialDescription ());
357
- final Azure tempAzure = Azure .configure ()
358
- .authenticate (azureCredentialWrapper .getAzureTokenCredentials ()).withDefaultSubscription ();
359
- final PagedList <Subscription > subscriptions = tempAzure .subscriptions ().list ();
355
+ final PagedList <Subscription > subscriptions = Azure .configure ()
356
+ .authenticate (azureCredentialWrapper .getAzureTokenCredentials ()).subscriptions ().list ();
360
357
subscriptions .loadAll ();
361
- final String targetSubscriptionId = getTargetSubscriptionId (tempAzure , subscriptions );
358
+ final String targetSubscriptionId = getTargetSubscriptionId (getSubscriptionId () , subscriptions );
362
359
checkSubscription (subscriptions , targetSubscriptionId );
363
360
azureCredentialWrapper .withDefaultSubscriptionId (targetSubscriptionId );
364
361
return AzureClientFactory .getAzureClient (azureCredentialWrapper , getUserAgent ());
@@ -445,7 +442,7 @@ public String getAuthMethod() {
445
442
public void execute () throws MojoExecutionException {
446
443
try {
447
444
// init proxy manager
448
- ProxyManager . getInstance (). init ( );
445
+ ProxyUtils . initProxy ( Optional . ofNullable ( this . session ). map ( s -> s . getRequest ()). orElse ( null ) );
449
446
450
447
// Work around for Application Insights Java SDK:
451
448
// Sometimes, NoClassDefFoundError will be thrown even after Maven build is completed successfully.
@@ -619,9 +616,9 @@ protected interface RunnableWithException {
619
616
}
620
617
//endregion
621
618
622
- private String getTargetSubscriptionId (Azure azure2 , PagedList <Subscription > subscriptions ) throws IOException , AzureExecutionException {
619
+ private String getTargetSubscriptionId (String defaultSubscriptionId , PagedList <Subscription > subscriptions ) throws IOException , AzureExecutionException {
623
620
final List <String > subsIdList = subscriptions .stream ().map (Subscription ::subscriptionId ).collect (Collectors .toList ());
624
- String targetSubscriptionId = StringUtils . firstNonBlank ( this . subscriptionId , azureCredentialWrapper . getDefaultSubscriptionId ()) ;
621
+ String targetSubscriptionId = defaultSubscriptionId ;
625
622
626
623
if (StringUtils .isBlank (targetSubscriptionId ) && ArrayUtils .isNotEmpty (azureCredentialWrapper .getFilteredSubscriptionIds ())) {
627
624
final Collection <String > filteredSubscriptions = StringListUtils .intersectIgnoreCase (subsIdList ,
@@ -632,7 +629,7 @@ private String getTargetSubscriptionId(Azure azure2, PagedList<Subscription> sub
632
629
}
633
630
634
631
if (StringUtils .isBlank (targetSubscriptionId )) {
635
- return selectSubscription (azure2 , subscriptions .toArray (new Subscription [0 ]));
632
+ return selectSubscription (subscriptions .toArray (new Subscription [0 ]));
636
633
}
637
634
return targetSubscriptionId ;
638
635
}
0 commit comments