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.
* feat: improve logging of groups found * feat: introduce ability to add args to groups sync slash command * feat: update help text to match new commands available
- Loading branch information
Showing
7 changed files
with
115 additions
and
19 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,9 @@ | |
""" | ||
|
||
import os | ||
from slack_bolt import App | ||
from slack_bolt import App, Ack, Respond | ||
from slack_sdk.web import WebClient | ||
from logging import Logger | ||
|
||
from integrations.aws.organizations import get_account_id_by_name | ||
from integrations.aws import identity_store | ||
|
@@ -20,20 +22,25 @@ | |
AWS_ADMIN_GROUPS = os.environ.get("AWS_ADMIN_GROUPS", "[email protected]").split(",") | ||
|
||
help_text = """ | ||
\n `/aws user <operation> <user1> <user2> ...` | ||
\n `/aws users <operation> <user1> <user2> ...` | ||
\n - Provision or deprovision AWS users | Provisionner ou déprovisionner des utilisateurs AWS | ||
\n Supports multiple users for a single operation | Supporte plusieurs utilisateurs pour l'opération | ||
\n `<operation>`: `create` or/ou `delete` | ||
\n `<user>`: email address or Slack username of the user | adresse courriel ou identifiant Slack de l'utilisateur | ||
\n Usage: `/aws user create @username [email protected]` | ||
\n `/aws groups <operation> <group1> <group2> ...` | ||
\n - Manage AWS groups | Gérer les groupes AWS | ||
\n `<operation>`: `sync`, `list` | ||
\n `<group>`: name of the group | nom du groupe (sync only) | ||
\n Usage: `/aws groups sync`, `/aws groups sync group-name` or/ou `/aws groups list` | ||
\n `/aws help | aide` | ||
\n - Show this help text | montre le dialogue d'aide | ||
\n | ||
\n (currently disabled) | ||
\n `/aws access` | ||
\n - starts the process to access an AWS account | débute le processus pour accéder à un compte AWS | ||
\n `/aws health` | ||
\n - Query the health of an AWS account | Demander l'état de santé d'un compte AWS | ||
\n `/aws access` | ||
\n - starts the process to access an AWS account | débute le processus pour accéder à un compte AWS | ||
""" | ||
|
||
|
||
|
@@ -48,7 +55,9 @@ def register(bot: App) -> None: | |
bot.view("aws_health_view")(aws_account_health.health_view_handler) | ||
|
||
|
||
def aws_command(ack, command, logger, respond, client, body) -> None: | ||
def aws_command( | ||
ack: Ack, command, logger: Logger, respond: Respond, client: WebClient, body | ||
) -> None: | ||
"""AWS command handler. | ||
This function handles the `/aws` command by parsing the command text and executing the appropriate action. | ||
|
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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from unittest.mock import patch, MagicMock, call | ||
from unittest.mock import patch, MagicMock, call, ANY | ||
from modules.aws import groups | ||
|
||
|
||
|
@@ -86,9 +86,44 @@ def test_request_groups_sync_synchronizes_groups( | |
) | ||
logger.info.assert_called_once_with("Synchronizing AWS Identity Center Groups.") | ||
mock_identity_center.synchronize.assert_called_once_with( | ||
enable_users_sync=False, | ||
enable_user_create=False, | ||
enable_membership_create=True, | ||
enable_membership_delete=True, | ||
pre_processing_filters=[], | ||
) | ||
respond.assert_called_once_with("AWS Groups Memberships Synchronization Initiated.") | ||
|
||
|
||
@patch("modules.aws.groups.slack_users") | ||
@patch("modules.aws.groups.permissions") | ||
@patch("modules.aws.groups.identity_center") | ||
def test_request_groups_sync_synchronizes_groups_with_args( | ||
mock_identity_center, mock_permissions, mock_slack_users | ||
): | ||
client = MagicMock() | ||
body = MagicMock() | ||
respond = MagicMock() | ||
args = ["group1", "group2"] | ||
logger = MagicMock() | ||
|
||
mock_slack_users.get_user_email_from_body.return_value = "[email protected]" | ||
mock_permissions.is_user_member_of_groups.return_value = True | ||
mock_identity_center.synchronize.return_value = None | ||
|
||
groups.request_groups_sync(client, body, respond, args, logger) | ||
|
||
mock_slack_users.get_user_email_from_body.assert_called_once_with(client, body) | ||
mock_permissions.is_user_member_of_groups.assert_called_once_with( | ||
"[email protected]", groups.AWS_ADMIN_GROUPS | ||
) | ||
logger.info.assert_called_once_with("Synchronizing AWS Identity Center Groups.") | ||
mock_identity_center.synchronize.assert_called_once_with( | ||
enable_users_sync=False, | ||
enable_user_create=False, | ||
enable_membership_create=True, | ||
enable_membership_delete=True, | ||
pre_processing_filters=ANY, | ||
) | ||
respond.assert_called_once_with("AWS Groups Memberships Synchronization Initiated.") | ||
|
||
|
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