generated from cds-snc/project-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: Refactor AWS group handling in conftest.py * feat: Add functions to retrieve groups with members from integration sources * feat: Add user synchronization functionality * chore: run fmt * feat: Add filter functions * feat: add group function to map users * feat: hoist users and groups matching functions in single function * fix: update var names to be generic * Refactor variable names and update group and user functions for readability * fix: expected output to match updated fixtures * fix: set expected value for group emails in google groups * fix: Add tests for compare_lists function in test_filters.py * chore: remove unused functions * chore: run lint * fix: Refactor function to use a dictionary for storing unique users * fix: remove unused code * fix: remove unused code * fix: lint
- Loading branch information
Showing
12 changed files
with
817 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from integrations.google_workspace import google_directory | ||
from integrations.aws import identity_store | ||
from utils import filters as filter_tools | ||
|
||
|
||
def get_groups_with_members_from_integration(integration_source, **kwargs): | ||
"""Retrieve the users from an integration group source. | ||
Supported sources are: | ||
- Google Groups | ||
- AWS Identity Center (Identity Store) | ||
Args: | ||
integration_source (str): The source of the groups. | ||
**kwargs: Additional keyword arguments. Supported arguments are: | ||
- `filters` (list): List of filters to apply to the groups. | ||
- `query` (str): The query to search for groups. | ||
- `members_details` (bool): Include the members details in the groups. | ||
Returns: | ||
list: A list of groups with members, empty list if no groups are found. | ||
""" | ||
filters = kwargs.get("filters", []) | ||
query = kwargs.get("query", None) | ||
members_details = kwargs.get("members_details", True) | ||
|
||
groups = [] | ||
match integration_source: | ||
case "google_groups": | ||
groups = google_directory.list_groups_with_members( | ||
query=query, members_details=members_details | ||
) | ||
case "aws_identity_center": | ||
groups = identity_store.list_groups_with_memberships( | ||
members_details=members_details | ||
) | ||
case _: | ||
return groups | ||
|
||
for filter in filters: | ||
groups = filter_tools.filter_by_condition(groups, filter) | ||
return groups |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from logging import getLogger | ||
|
||
from utils import filters as filter_tools | ||
|
||
|
||
logger = getLogger(__name__) | ||
|
||
|
||
def get_unique_users_from_groups(groups, key): | ||
"""Get the unique users from a list of groups with the same data schema or a single group dict. | ||
Considers the whole object for uniqueness, not specific keys. | ||
Args: | ||
groups (list or dict): A list of groups or a single group. | ||
key (str): The key to get the users from the groups. | ||
Returns: | ||
list: A list of unique users from the groups | ||
""" | ||
users_dict = {} | ||
if isinstance(groups, list): | ||
for group in groups: | ||
for user in filter_tools.get_nested_value(group, key): | ||
if user: | ||
users_dict[str(user)] = user | ||
elif isinstance(groups, dict): | ||
for user in filter_tools.get_nested_value(groups, key): | ||
if user: | ||
users_dict[str(user)] = user | ||
|
||
return list(users_dict.values()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.