Add classified NTFS path template placeholders
This commit is contained in:
@@ -62,6 +62,7 @@ namespace C4IT_IAM_SET
|
||||
public string groupNameSanitizeReplacement = Helper.DefaultGroupNameSanitizeReplacement;
|
||||
public bool preserveAdGroupNameCase;
|
||||
public bool WhatIf;
|
||||
public Func<string, Helper.RootPathTemplateContext> GetTemplateContextForPath;
|
||||
|
||||
public int ReadACLPermission = cLiamAclPermissionDefaults.Read;
|
||||
public int WriteACLPermission = cLiamAclPermissionDefaults.Write;
|
||||
@@ -331,6 +332,12 @@ namespace C4IT_IAM_SET
|
||||
};
|
||||
}
|
||||
|
||||
private Helper.RootPathTemplateContext GetEffectiveTemplateContext(string path)
|
||||
{
|
||||
return GetTemplateContextForPath?.Invoke(path)
|
||||
?? Helper.GetRootPathTemplateContext(baseFolder, groupNameSanitizeReplacement);
|
||||
}
|
||||
|
||||
private ResultToken ValidateTraverseBoundaryForCurrentFolder()
|
||||
{
|
||||
var resultToken = new ResultToken(System.Reflection.MethodBase.GetCurrentMethod().ToString());
|
||||
@@ -569,7 +576,8 @@ namespace C4IT_IAM_SET
|
||||
0,
|
||||
0,
|
||||
groupNameSanitizeReplacement,
|
||||
preserveAdGroupNameCase);
|
||||
preserveAdGroupNameCase,
|
||||
GetEffectiveTemplateContext(newDataArea.IAM_Folders[0].technicalName));
|
||||
|
||||
var existingGroups = new List<IAM_SecurityGroup>();
|
||||
foreach (var securityGroup in newSecurityGroups.IAM_SecurityGroups)
|
||||
@@ -803,7 +811,7 @@ namespace C4IT_IAM_SET
|
||||
? sanitizedSegments[sanitizedSegments.Length - 1]
|
||||
: Helper.SanitizePathSegment(Path.GetFileName(parent.FullName.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar)), groupNameSanitizeReplacement);
|
||||
var traverseTags = GetTraverseReplacementTags(parent.FullName, traverseGroupTemplate.Scope);
|
||||
var rootContext = Helper.GetRootPathTemplateContext(baseFolder, groupNameSanitizeReplacement);
|
||||
var rootContext = GetEffectiveTemplateContext(parent.FullName);
|
||||
var boundedTraverseContext = Helper.GetBoundedAdGroupTemplateContext(
|
||||
traverseGroupTemplate.NamingTemplate,
|
||||
true,
|
||||
@@ -1605,7 +1613,8 @@ namespace C4IT_IAM_SET
|
||||
0,
|
||||
0,
|
||||
groupNameSanitizeReplacement,
|
||||
preserveAdGroupNameCase);
|
||||
preserveAdGroupNameCase,
|
||||
GetEffectiveTemplateContext(newDataArea.IAM_Folders[0].technicalName));
|
||||
|
||||
List<UserPrincipal> owners = getUserPrincipalBySid(ownerUserSids);
|
||||
List<UserPrincipal> writers = getUserPrincipalBySid(writerUserSids);
|
||||
@@ -1771,7 +1780,8 @@ namespace C4IT_IAM_SET
|
||||
existingADGroupCount,
|
||||
0,
|
||||
groupNameSanitizeReplacement,
|
||||
preserveAdGroupNameCase);
|
||||
preserveAdGroupNameCase,
|
||||
GetEffectiveTemplateContext(newDataArea.IAM_Folders[0].technicalName));
|
||||
/*
|
||||
if (existingADGroupCount > 0 && !templates.All(t => t.Type == SecurityGroupType.Traverse || Regex.IsMatch(t.NamingTemplate, @"(?<loopTag>{{(?<prefix>[^}]*)(?<loop>LOOP)(?<postfix>[^{]*)}})")))
|
||||
{
|
||||
|
||||
@@ -33,6 +33,9 @@ namespace C4IT_IAM_Engine
|
||||
public sealed class RootPathTemplateContext
|
||||
{
|
||||
public string Server { get; set; } = string.Empty;
|
||||
public string ServerName { get; set; } = string.Empty;
|
||||
public string DfsNamespaceName { get; set; } = string.Empty;
|
||||
public string ShareName { get; set; } = string.Empty;
|
||||
public string[] Segments { get; set; } = Array.Empty<string>();
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string Path { get; set; } = string.Empty;
|
||||
@@ -109,6 +112,8 @@ namespace C4IT_IAM_Engine
|
||||
return new RootPathTemplateContext
|
||||
{
|
||||
Server = server,
|
||||
ServerName = server,
|
||||
ShareName = sanitizedPathSegments.Length == 0 ? string.Empty : sanitizedPathSegments[sanitizedPathSegments.Length - 1],
|
||||
Segments = sanitizedPathSegments,
|
||||
Name = sanitizedPathSegments.Length == 0 ? string.Empty : sanitizedPathSegments[sanitizedPathSegments.Length - 1],
|
||||
Path = sanitizedPathSegments.Length == 0 ? string.Empty : JoinSanitizedPathSegments(sanitizedPathSegments, groupNameSanitizeReplacement),
|
||||
@@ -308,6 +313,9 @@ namespace C4IT_IAM_Engine
|
||||
|
||||
var context = rootContext ?? new RootPathTemplateContext();
|
||||
var result = Regex.Replace(templateValue, @"{{\s*ROOT_SERVER\s*}}", context.Server ?? string.Empty, RegexOptions.IgnoreCase);
|
||||
result = Regex.Replace(result, @"{{\s*SERVER_NAME\s*}}", context.ServerName ?? context.Server ?? string.Empty, RegexOptions.IgnoreCase);
|
||||
result = Regex.Replace(result, @"{{\s*DFS_NAMESPACE_NAME\s*}}", context.DfsNamespaceName ?? string.Empty, RegexOptions.IgnoreCase);
|
||||
result = Regex.Replace(result, @"{{\s*SHARE_NAME\s*}}", context.ShareName ?? string.Empty, RegexOptions.IgnoreCase);
|
||||
result = Regex.Replace(result, @"{{\s*ROOT_NAME\s*}}", context.Name ?? string.Empty, RegexOptions.IgnoreCase);
|
||||
result = Regex.Replace(result, @"{{\s*ROOT_PATH(?:\s*\(\s*(\d+)\s*\))?\s*}}", match =>
|
||||
{
|
||||
|
||||
@@ -142,7 +142,8 @@ namespace C4IT_IAM_Engine
|
||||
int loop = 0,
|
||||
int existingADGroupCount = 0,
|
||||
string groupNameSanitizeReplacement = Helper.DefaultGroupNameSanitizeReplacement,
|
||||
bool preserveAdGroupNameCase = false)
|
||||
bool preserveAdGroupNameCase = false,
|
||||
Helper.RootPathTemplateContext templateContext = null)
|
||||
{
|
||||
LogMethodBegin(MethodBase.GetCurrentMethod());
|
||||
try
|
||||
@@ -163,7 +164,7 @@ namespace C4IT_IAM_Engine
|
||||
var folderName = sanitizedSegments.Length > 0
|
||||
? sanitizedSegments[sanitizedSegments.Length - 1]
|
||||
: Helper.SanitizePathSegment(Path.GetFileName(newFolderPath.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar)), groupNameSanitizeReplacement);
|
||||
var rootContext = Helper.GetRootPathTemplateContext(baseFolder, groupNameSanitizeReplacement);
|
||||
var rootContext = templateContext ?? Helper.GetRootPathTemplateContext(baseFolder, groupNameSanitizeReplacement);
|
||||
|
||||
foreach (var template in resolvedTemplates)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user