Skip to content

Commit

Permalink
refactor(arm): improve ArmEnvironment (Azure#26951)
Browse files Browse the repository at this point in the history
1. change `DefaultScope` to return null when initialized by `default` keyword
2. improve the performance of `DefaultScope` a little bit
3. use common `HashCodebuilder` to generate the hash code

follow up of Azure#26635
  • Loading branch information
archerzz authored and yanfa317 committed Mar 8, 2022
1 parent 9081361 commit 3e56cdc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
13 changes: 3 additions & 10 deletions sdk/resourcemanager/Azure.ResourceManager/src/ArmEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace Azure.ResourceManager
/// <summary>
/// Gets default authentication scope.
/// </summary>
public string DefaultScope => GetScope(".default");
public string DefaultScope { get; }

/// <summary>
/// Construct an <see cref="ArmEnvironment"/> using the given value.
Expand All @@ -53,11 +53,7 @@ public ArmEnvironment(Uri baseUri, string audience)

BaseUri = baseUri;
Audience = audience;
}

private string GetScope(string permission)
{
return $"{Audience}/{permission}";
DefaultScope = $"{Audience}/.default";
}

/// <summary> Determines if two <see cref="ArmEnvironment"/> values are the same. </summary>
Expand All @@ -77,10 +73,7 @@ private string GetScope(string permission)
[EditorBrowsable(EditorBrowsableState.Never)]
public override int GetHashCode()
{
int hash = 17;
hash = hash * 23 + BaseUri.GetHashCode();
hash = hash * 23 + Audience.GetHashCode();
return hash;
return HashCodeBuilder.Combine(BaseUri, Audience);
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public void DefaultValueIsNull()
var defaultValue = default(ArmEnvironment);
Assert.IsNull(defaultValue.BaseUri);
Assert.IsNull(defaultValue.Audience);
Assert.IsNull(defaultValue.DefaultScope);
}

[TestCase]
Expand Down

0 comments on commit 3e56cdc

Please sign in to comment.