Skip to content

Commit 09d4f33

Browse files
committed
Refactorings based on PR feedback
1 parent f135b43 commit 09d4f33

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/ResourceManager/Profile/Commands.Profile/Environment/AddAzureRMEnvironment.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,12 @@ public override void ExecuteCmdlet()
172172
GeneralUtilities.EnsureTrailingSlash(ARMEndpoint)?.ToLowerInvariant(), StringComparison.CurrentCultureIgnoreCase));
173173

174174
IAzureEnvironment newEnvironment = new AzureEnvironment { Name = this.Name };
175-
var defProfile = DefaultProfile as AzureRmProfile;
176-
if (defProfile != null && defProfile.EnvironmentTable.ContainsKey(this.Name))
175+
var defProfile = GetDefaultProfile();
176+
if (defProfile != null)
177177
{
178-
newEnvironment = defProfile.EnvironmentTable[Name];
178+
IAzureEnvironment _newEnvironment;
179+
defProfile.TryGetEnvironment(this.Name, out _newEnvironment);
180+
newEnvironment = (_newEnvironment ?? newEnvironment);
179181
}
180182

181183
if (publicEnvironment.Key == null)
@@ -185,7 +187,7 @@ public override void ExecuteCmdlet()
185187
{
186188
EnvHelper = (EnvHelper == null ? new EnvironmentHelper() : EnvHelper);
187189
MetadataResponse metadataEndpoints = EnvHelper.RetrieveMetaDataEndpoints(newEnvironment.ResourceManagerUrl).Result;
188-
string domain = EnvHelper.RetrieveDomain(newEnvironment.ResourceManagerUrl);
190+
string domain = EnvHelper.RetrieveDomain(ARMEndpoint);
189191

190192
SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.ActiveDirectory,
191193
metadataEndpoints.authentication.LoginEndpoint.TrimEnd('/') + '/');

src/ResourceManager/Profile/Commands.Profile/Environment/SetAzureRMEnvironment.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,12 @@ public override void ExecuteCmdlet()
174174
GeneralUtilities.EnsureTrailingSlash(ARMEndpoint)?.ToLowerInvariant(), StringComparison.CurrentCultureIgnoreCase));
175175

176176
IAzureEnvironment newEnvironment = new AzureEnvironment { Name = this.Name };
177-
var defProfile = DefaultProfile as AzureRmProfile;
178-
if (defProfile != null && defProfile.EnvironmentTable.ContainsKey(this.Name))
177+
var defProfile = GetDefaultProfile();
178+
if (defProfile != null)
179179
{
180-
newEnvironment = defProfile.EnvironmentTable[Name];
180+
IAzureEnvironment _newEnvironment;
181+
defProfile.TryGetEnvironment(this.Name, out _newEnvironment);
182+
newEnvironment = (_newEnvironment ?? newEnvironment);
181183
}
182184

183185
if (publicEnvironment.Key == null)
@@ -187,7 +189,7 @@ public override void ExecuteCmdlet()
187189
{
188190
EnvHelper = (EnvHelper == null ? new EnvironmentHelper() : EnvHelper);
189191
MetadataResponse metadataEndpoints = EnvHelper.RetrieveMetaDataEndpoints(newEnvironment.ResourceManagerUrl).Result;
190-
string domain = EnvHelper.RetrieveDomain(newEnvironment.ResourceManagerUrl);
192+
string domain = EnvHelper.RetrieveDomain(ARMEndpoint);
191193

192194
SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.ActiveDirectory,
193195
metadataEndpoints.authentication.LoginEndpoint.TrimEnd('/') + '/');

0 commit comments

Comments
 (0)