/// <summary> /// Load the DataSet /// </summary> /// <param name="resources">Resources to load the DataSet from</param> /// <returns>true if load was successful, false otherwise</returns> public override bool Load(IDictionary <string, IResourceDetails> resources) { if (!base.Load(resources)) { return(false); } bool resourceStatus = LoadResource(resources, TestGroupsResourceName, out byte[] file); if (!resourceStatus) { ULSLogging.LogCodeErrorTag(0x2382108f /* tag_967cp */, Categories.TestGroupsDataSet, false, true, "Failed to retrieve resource content for TestGroupsDataSet."); } else if (file == null || file.Length == 0) { ULSLogging.LogCodeErrorTag(0x23821090 /* tag_967cq */, Categories.TestGroupsDataSet, false, true, "Null or empty resource data encountered in TestGroupsDataSet loading method"); } else { Load(file); } LastReload = DateTime.UtcNow; return(IsHealthy); }
/// <summary> /// Get group users (email or deployment identifiers) /// </summary> /// <param name="groupName">Group name</param> /// <returns>List of user group emails or deployment ids</returns> public IEnumerable <string> GetGroupUsers(string groupName) { List <string> emptyList = new List <string>(); if (string.IsNullOrWhiteSpace(groupName)) { ULSLogging.LogCodeErrorTag(0x23821092 /* tag_967cs */, Categories.TestGroupsDataSet, false, false, "Null or empty group passed to TestGroupsDataSet.GetGroupUsers"); return(emptyList); } if (m_groupUsers == null) { ULSLogging.LogCodeErrorTag(0x23821093 /* tag_967ct */, Categories.TestGroupsDataSet, false, false, "TestGroupsDataSet is not loaded."); return(emptyList); } string group = groupName.Trim(); if (DefaultGroups.Contains(group)) { return(m_userGroups.Keys.ToList()); } if (m_groupUsers.TryGetValue(group, out List <string> groupUsers)) { return(groupUsers); } return(emptyList); }
/// <summary> /// Loads the data set /// </summary> /// <param name="resources">List of resources to load from</param> /// <returns>true if load was successful, false otherwise</returns> public virtual bool Load(IDictionary <string, IResourceDetails> resources) { if (!Code.Validate((resources?.Count ?? 0) > 0, TaggingUtilities.ReserveTag(0x23821012 /* tag_967as */), "{0} should containt at least one resource, unable to load '{1}'", nameof(resources), GetType().Name)) { //Log error into ConfigurationDataSet error list to preserve old behaviour for backward compatibility ULSLogging.LogCodeErrorTag(0x23821013 /* tag_967at */, Categories.ConfigurationDataSet, false, true, "{0} should contaminant at least one resource, unable to load '{1}'", nameof(resources), GetType().Name); return(false); } LoadDetails = new List <ConfigurationDataSetLoadDetails>(resources.Count); return(true); }
/// <summary> /// Retrieves all groups for a given group email or deployment id /// </summary> /// <param name="user">User email or deployment id</param> /// <returns>List of group groups</returns> public IEnumerable <string> GetUserGroups(string user) { if (m_userGroups == null) { ULSLogging.LogCodeErrorTag(0x23821091 /* tag_967cr */, Categories.TestGroupsDataSet, false, false, "Test groups DataSet is not loaded."); return(DefaultGroups); } if (m_userGroups.TryGetValue(user.Trim(), out List <string> userGroups)) { return(userGroups); } else { return(DefaultGroups); } }
/// <summary> /// Connects user to a group /// </summary> /// <param name="userGroups">User groups dictionary</param> /// <param name="groupUsers">Group users dictionary</param> /// <param name="user">group</param> /// <param name="groupName">Group name to add</param> private void UpdateGroups(Dictionary <string, List <string> > userGroups, Dictionary <string, List <string> > groupUsers, string user, string groupName) { if (!string.IsNullOrWhiteSpace(user)) { user = user.Trim(); // Connect group to user if (userGroups.TryGetValue(user, out List <string> groups)) { if (!groups.Contains(groupName)) { groups.Add(groupName); } } else { groups = new List <string>(DefaultGroups) { groupName }; userGroups.Add(user, groups); } // Connect user to group if (groupUsers.TryGetValue(groupName, out List <string> users)) { if (!users.Contains(user)) { users.Add(user); } } else { users = new List <string> { user }; groupUsers.Add(groupName, users); } } else { ULSLogging.LogCodeErrorTag(0x2382109a /* tag_967c0 */, Categories.TestGroupsDataSet, false, true, "Empty user data found for group '{0}', skipping.", groupName); } }
/// <summary> /// Loads resource /// </summary> /// <param name="resources">List of resources</param> /// <param name="resourceName">Resource to load</param> /// <param name="resourceContent">Loaded resource content</param> /// <returns><c>true</c> if the operation succeeded; <c>false</c> otherwise.</returns> protected bool LoadResource(IDictionary <string, IResourceDetails> resources, string resourceName, out byte[] resourceContent) { resourceContent = null; if (!Code.ValidateArgument(resources, nameof(resources), TaggingUtilities.ReserveTag(0x23821014 /* tag_967au */)) || !Code.ValidateNotNullOrWhiteSpaceArgument(resourceName, nameof(resourceName), TaggingUtilities.ReserveTag(0x23821015 /* tag_967av */))) { return(false); } if (!resources.TryGetValue(resourceName, out IResourceDetails resource)) { ULSLogging.LogCodeErrorTag(0x23821016 /* tag_967aw */, Categories.ConfigurationDataSet, false, true, "Failed to find resource '{0}' for data set '{1}' in the set of loaded resources.", resourceName, GetType().Name); return(false); } LoadDetails.Add(new ConfigurationDataSetLoadDetails(resourceName, resource.LastWrite, resource.Length, resource.SHA256Hash)); resourceContent = resource.Contents; return(true); }
/// <summary> /// Load the Test Groups Data /// </summary> /// <param name="testGroupsRaw">Raw test groups data</param> /// <param name="userGroups">User groups</param> /// <param name="groupUsers">Group users</param> private void LoadGroupsData(Configuration.TestGroups testGroupsRaw, out Dictionary <string, List <string> > userGroups, out Dictionary <string, List <string> > groupUsers) { if (testGroupsRaw == null || testGroupsRaw.TestGroup == null) { ULSLogging.LogCodeErrorTag(0x23821095 /* tag_967cv */, Categories.TestGroupsDataSet, false, true, "Null raw data has been passed to TestGroupsDataSet.LoadGroupsData."); userGroups = null; groupUsers = null; return; } userGroups = new Dictionary <string, List <string> >(StringComparer.OrdinalIgnoreCase); groupUsers = new Dictionary <string, List <string> >(StringComparer.OrdinalIgnoreCase); foreach (Configuration.TestGroupsTestGroup testGroup in testGroupsRaw.TestGroup) { string testGroupName = testGroup.name.Trim(); if (string.IsNullOrWhiteSpace(testGroupName)) { ULSLogging.LogCodeErrorTag(0x23821096 /* tag_967cw */, Categories.TestGroupsDataSet, false, true, "A test user with empty name found, skipping."); continue; } if (testGroupName.Contains(ListSeparator)) { ULSLogging.LogCodeErrorTag(0x23821097 /* tag_967cx */, Categories.TestGroupsDataSet, false, true, "Test user name '{0}' contains a semicolon. This name cannot be used as the semicolon is used to delimit groups within the asset field. Skipping.", testGroupName); continue; } if (DefaultGroups.Contains(testGroupName)) { ULSLogging.LogCodeErrorTag(0x23821098 /* tag_967cy */, Categories.TestGroupsDataSet, false, true, "Test user name '{0}' is a restricted user name and cannot be manually specified. Skipping.", testGroupName); continue; } if (testGroup.Member == null) { ULSLogging.LogCodeErrorTag(0x23821099 /* tag_967cz */, Categories.TestGroupsDataSet, false, true, "Skipping test user '{0}' : the user has no members", testGroupName); continue; } if (!groupUsers.ContainsKey(testGroupName)) { groupUsers.Add(testGroupName, new List <string>()); } foreach (Configuration.TestGroupsTestGroupMember member in testGroup.Member) { if (member.email != null) { UpdateGroups(userGroups, groupUsers, member.email, testGroupName); } if (member.deploymentId != null) { UpdateGroups(userGroups, groupUsers, member.deploymentId, testGroupName); } } } }