@@ -60,11 +60,20 @@ public TClient CreateClient<TClient>(AzureProfile profile, AzureEnvironment.Endp
60
60
61
61
public TClient CreateClient < TClient > ( AzureProfile profile , AzureSubscription subscription , AzureEnvironment . Endpoint endpoint ) where TClient : ServiceClient < TClient >
62
62
{
63
- SubscriptionCloudCredentials creds = new TokenCloudCredentials ( subscription == null ? "fake_subscription" : subscription . Id . ToString ( ) , "fake_token" ) ;
63
+ if ( subscription == null )
64
+ {
65
+ throw new ArgumentException ( Commands . Common . Properties . Resources . InvalidDefaultSubscription ) ;
66
+ }
67
+
68
+ if ( profile == null )
69
+ {
70
+ profile = new AzureProfile ( Path . Combine ( AzureSession . ProfileDirectory , AzureSession . ProfileFile ) ) ;
71
+ }
72
+
73
+ SubscriptionCloudCredentials creds = new TokenCloudCredentials ( subscription . Id . ToString ( ) , "fake_token" ) ;
64
74
if ( HttpMockServer . GetCurrentMode ( ) != HttpRecorderMode . Playback )
65
75
{
66
- ProfileClient profileClient = new ProfileClient (
67
- profile ?? new AzureProfile ( Path . Combine ( AzureSession . ProfileDirectory , AzureSession . ProfileFile ) ) ) ;
76
+ ProfileClient profileClient = new ProfileClient ( profile ) ;
68
77
AzureContext context = new AzureContext (
69
78
subscription ,
70
79
profileClient . GetAccount ( subscription . Account ) ,
@@ -74,7 +83,7 @@ public TClient CreateClient<TClient>(AzureProfile profile, AzureSubscription sub
74
83
creds = AzureSession . AuthenticationFactory . GetSubscriptionCloudCredentials ( context ) ;
75
84
}
76
85
77
- Uri endpointUri = ( new ProfileClient ( profile ?? new AzureProfile ( Path . Combine ( AzureSession . ProfileDirectory , AzureSession . ProfileFile ) ) ) ) . Profile . Environments [ subscription . Environment ] . GetEndpointAsUri ( endpoint ) ;
86
+ Uri endpointUri = profile . Environments [ subscription . Environment ] . GetEndpointAsUri ( endpoint ) ;
78
87
return CreateCustomClient < TClient > ( creds , endpointUri ) ;
79
88
}
80
89
0 commit comments