Skip to content

Commit b5d4917

Browse files
committed
Fixing auto-registration client to use current subscription id
1 parent 27d946a commit b5d4917

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/ResourceManager/Common/Commands.ResourceManager.Common/AzureRMCmdlet.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,19 @@ protected override void Dispose(bool disposing)
311311
protected override void BeginProcessing()
312312
{
313313
AzureSession.Instance.ClientFactory.RemoveHandler(typeof(RPRegistrationDelegatingHandler));
314-
AzureSession.Instance.ClientFactory.AddHandler(new RPRegistrationDelegatingHandler(
315-
() => new ResourceManagementClient(
316-
DefaultContext.Environment.GetEndpointAsUri(AzureEnvironment.Endpoint.ResourceManager),
317-
AzureSession.Instance.AuthenticationFactory.GetServiceClientCredentials(DefaultContext, AzureEnvironment.Endpoint.ResourceManager)),
318-
s => DebugMessages.Enqueue(s)));
314+
if (DefaultContext != null && DefaultContext.Subscription != null)
315+
{
316+
AzureSession.Instance.ClientFactory.AddHandler(new RPRegistrationDelegatingHandler(
317+
() =>
318+
{
319+
var client = new ResourceManagementClient(
320+
DefaultContext.Environment.GetEndpointAsUri(AzureEnvironment.Endpoint.ResourceManager),
321+
AzureSession.Instance.AuthenticationFactory.GetServiceClientCredentials(DefaultContext, AzureEnvironment.Endpoint.ResourceManager));
322+
client.SubscriptionId = DefaultContext.Subscription.Id;
323+
return client;
324+
},
325+
s => DebugMessages.Enqueue(s)));
326+
}
319327

320328
base.BeginProcessing();
321329
}

0 commit comments

Comments
 (0)