Skip to content

Commit 6672e47

Browse files
authored
Do not add api to IAzureContextContainer (#284)
1 parent 887ae87 commit 6672e47

File tree

3 files changed

+42
-8
lines changed

3 files changed

+42
-8
lines changed

src/Authentication.Abstractions/Interfaces/IAzureContextContainer.cs

-7
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,5 @@ public interface IAzureContextContainer: IExtensibleModel
4949
/// Remove all contexts from the container
5050
/// </summary>
5151
void Clear();
52-
53-
/// <summary>
54-
/// Copy the context container for overriding default context.
55-
/// See <see cref="SupportsSubscriptionIdAttribute"/>
56-
/// </summary>
57-
/// <returns>The copy.</returns>
58-
IAzureContextContainer CopyForContextOverriding();
5952
}
6053
}
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Commands.Common.Authentication.Abstractions.Core;
16+
17+
namespace Microsoft.WindowsAzure.Commands.Common.Utilities
18+
{
19+
/// <summary>
20+
/// Contains helper methods shared between common lib and Az.Accounts.
21+
/// An instance of a class that implements this interface should be registered to the session.
22+
/// </summary>
23+
public interface ISharedUtilities
24+
{
25+
/// <summary>
26+
/// Copy the context container for overriding default context.
27+
/// See <see cref="Attributes.SupportsSubscriptionIdAttribute"/>.
28+
/// </summary>
29+
/// <param name="contextContainer">The original.</param>
30+
/// <returns>The copy.</returns>
31+
IAzureContextContainer CopyForContextOverriding(IAzureContextContainer contextContainer);
32+
}
33+
}

src/ResourceManager/Version2016_09_01/AzureRMCmdlet.cs

+9-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
using Microsoft.Rest;
2626
using Microsoft.WindowsAzure.Commands.Common;
2727
using Microsoft.WindowsAzure.Commands.Common.Attributes;
28+
using Microsoft.WindowsAzure.Commands.Common.Utilities;
2829
using Microsoft.WindowsAzure.Commands.Utilities.Common;
2930
using System;
3031
using System.Collections.Generic;
@@ -111,7 +112,14 @@ private IAzureContextContainer CloneProfileAndModifyContext()
111112
if (matchingSub != null)
112113
{
113114
// going to modify default context, so only shallow copying other stuff
114-
profile = GetDefaultProfile().CopyForContextOverriding();
115+
if (AzureSession.Instance.TryGetComponent<ISharedUtilities>(nameof(ISharedUtilities), out var sharedUtilities))
116+
{
117+
profile = sharedUtilities.CopyForContextOverriding(GetDefaultProfile());
118+
}
119+
else
120+
{
121+
throw new AzPSException(Resources.ProfileNotInitialized, Commands.Common.ErrorKind.InternalError);
122+
}
115123
profile.DefaultContext = profile.DefaultContext.DeepCopy();
116124
profile.DefaultContext.Subscription.CopyFrom(matchingSub);
117125
profile.DefaultContext.Tenant.Id = matchingSub.GetTenant();

0 commit comments

Comments
 (0)