Skip to content

Commit 5383e04

Browse files
author
Lei Jin
committed
Address review comments
1 parent dbaa757 commit 5383e04

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

src/ResourceManager/Version2016_09_01/AzureRMCmdlet.cs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -147,28 +147,26 @@ private bool ShouldCloneDefaultProfile()
147147

148148
private IAzureContextContainer _clonedDefaultProfile;
149149

150-
protected IDictionary<string, List<string>> GetAuxiliaryAuthHeaderFromTenantIds(IEnumerable<string> tenantIds)
150+
protected IDictionary<string, IList<string>> GetAuxiliaryAuthHeaderFromTenantIds(IEnumerable<string> tenantIds)
151151
{
152-
if ((tenantIds != null) && (tenantIds.Count() > 0))
152+
if ((tenantIds != null) && tenantIds.Any())
153153
{
154154
// WE can only fill in tokens for 3 tennats in the aux header, if tehre are more tenants fail now
155155
if (tenantIds.Count() > MAX_NUMBER_OF_TOKENS_ALLOWED_IN_AUX_HEADER)
156156
{
157-
throw new ArgumentException("Number of tenants (tenants other than the one in the current context), that the requested resources belong to, exceeds maximum allowed number of " + MAX_NUMBER_OF_TOKENS_ALLOWED_IN_AUX_HEADER);
157+
throw new ArgumentException($"Number of tenants (tenants other than the one in the current context), that the requested resources belong to, exceeds maximum allowed number of {MAX_NUMBER_OF_TOKENS_ALLOWED_IN_AUX_HEADER}");
158158
}
159159

160160
//get the tokens for each tenant and prepare the string in the following format :
161161
//"Header Value :: Bearer <auxiliary token1>;EncryptedBearer <auxiliary token2>; Bearer <auxiliary token3>"
162+
var tokens = tenantIds
163+
.Select(t => $"{AUX_TOKEN_PREFIX} {GetTokenForTenant(t)?.AccessToken}")?
164+
.ConcatStrings(AUX_TOKEN_APPEND_CHAR);
162165

163-
var tokens = tenantIds
164-
.Select(t => $"{AUX_TOKEN_PREFIX} {GetTokenForTenant(t)?.AccessToken}")
165-
.ConcatStrings(AUX_TOKEN_APPEND_CHAR);
166-
167-
var auxHeader = new Dictionary<String, List<String>>();
168-
169-
List<string> headerValues = new List<string>(1);
170-
headerValues.Add(tokens);
171-
auxHeader.Add(AUX_HEADER_NAME, headerValues);
166+
var auxHeader = new Dictionary<String, IList<String>>()
167+
{
168+
{ AUX_HEADER_NAME, new List<string>(1) { tokens } }
169+
};
172170
return auxHeader;
173171
}
174172
return null;

0 commit comments

Comments
 (0)