Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Accounts/Accounts/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
## YYYY.MM.DD - Version X.Y.Z (Previous Release)
* Overview of change #1
- Additional information about change #1
-->
## Upcoming Release
* Fallback to first valid context if current default context key is "Default" which is invalid
## Version 2.2.7
* Fixed incorrect warning message on Windows PowerShell [#14556]
Expand Down
7 changes: 4 additions & 3 deletions src/Accounts/Authentication.ResourceManager/AzureRmProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ public virtual IAzureContext DefaultContext
}

IAzureContext result = null;
if (DefaultContextKey == "Default" && Contexts.Any(c => c.Key != "Default"))
if (DefaultContextKey == Constants.DefaultValue && Contexts.Any(c => c.Key != Constants.DefaultValue))
{
// If the default context is "Default", but there are other contexts set, remove the "Default" context to throw the below exception
TryCacheRemoveContext("Default");
// If the default context is "Default", but there are other contexts set, remove the "Default" context and select first avaiable context as default
TryRemoveContext(Constants.DefaultValue);
}

if (!string.IsNullOrEmpty(DefaultContextKey) && Contexts != null && Contexts.ContainsKey(DefaultContextKey))
Expand Down Expand Up @@ -292,6 +292,7 @@ public void Save(IFileProvider provider, bool serializeCache = true)

try
{
TryRemoveContext(Constants.DefaultValue);
string contents = ToString(serializeCache);
string diskContents = string.Empty;
diskContents = provider.CreateReader().ReadToEnd();
Expand Down
21 changes: 21 additions & 0 deletions src/Accounts/Authentication.ResourceManager/Constants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

namespace Microsoft.Azure.Commands.Common.Authentication.ResourceManager
{
internal static class Constants
{
public const string DefaultValue = "Default";
}
}