generated from cds-snc/project-template
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/provisioning module #486
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
f303d3d
fix: Refactor AWS group handling in conftest.py
gcharest b043553
feat: Add functions to retrieve groups with members from integration …
gcharest 637ee31
feat: Add user synchronization functionality
gcharest 88741de
chore: run fmt
gcharest 3b61652
feat: Add filter functions
gcharest d646b3c
feat: add group function to map users
gcharest 0b60a31
feat: hoist users and groups matching functions in single function
gcharest eab72a9
fix: update var names to be generic
gcharest 958d018
Refactor variable names and update group and user functions for reada…
gcharest 065478e
fix: expected output to match updated fixtures
gcharest e342765
fix: set expected value for group emails in google groups
gcharest e5348db
fix: Add tests for compare_lists function in test_filters.py
gcharest a0f9693
chore: remove unused functions
gcharest 692d6c1
chore: run lint
gcharest e600885
fix: Refactor function to use a dictionary for storing unique users
gcharest f96078e
fix: remove unused code
gcharest b43c133
fix: remove unused code
gcharest aa14d0e
fix: lint
gcharest File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So much better than several if statements!