in src/PSRule.Rules.Azure/Common/ResourceHelper.cs [177:230]
internal static string CombineResourceId(string subscriptionId, string resourceGroup, string[] resourceType, string[] name, int depth = int.MaxValue)
{
var resourceTypeLength = resourceType?.Length ?? 0;
var nameLength = name?.Length ?? 0;
if (resourceTypeLength != nameLength)
throw new TemplateFunctionException(nameof(resourceType), FunctionErrorType.MismatchingResourceSegments, PSRuleResources.MismatchingResourceSegments);
var parts = resourceTypeLength + nameLength;
parts += subscriptionId != null ? 2 : 0;
parts += resourceGroup != null ? 2 : 0;
for (var p = 0; resourceType != null && p < resourceType.Length; p++)
{
if (resourceType[p].Contains(DOT))
parts++;
}
var result = new string[parts * 2];
var i = 0;
var j = 0;
if (subscriptionId != null)
{
result[i++] = SLASH;
result[i++] = SUBSCRIPTIONS;
result[i++] = SLASH;
result[i++] = subscriptionId;
}
if (resourceGroup != null)
{
result[i++] = SLASH;
result[i++] = RESOURCE_GROUPS;
result[i++] = SLASH;
result[i++] = resourceGroup;
}
if (resourceTypeLength > 0 && depth >= 0)
{
while (i < result.Length && j <= depth)
{
// If a resource provider is included prepend /providers.
if (resourceType[j].Contains(DOT))
{
result[i++] = SLASH;
result[i++] = PROVIDERS;
}
result[i++] = SLASH;
result[i++] = resourceType[j];
result[i++] = SLASH;
result[i++] = name[j++];
}
}
return string.Concat(result);
}