Skip to content

Commit a684f22

Browse files
committed
Merge remote-tracking branch 'aws-samples/master'
2 parents d9aa737 + d9f7f58 commit a684f22

File tree

3 files changed

+98
-67
lines changed

3 files changed

+98
-67
lines changed

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ arguments:
198198
accounts to the behavior graph. If the master account already has a behavior graph in a Region, then
199199
the member accounts are added to that behavior graph. If you do not provide a list of Regions, then
200200
the script acts across all Regions that Detective supports.
201-
201+
--disable_email If this flag is included, then emails will not be sent to the member accounts. Member accounts must still accept
202+
the invitation before they are added to the behavior graph.
202203
```
203204

204205

@@ -237,3 +238,15 @@ arguments:
237238
behavior graphs, the script disables Detective for the master account in all of the specified Regions.
238239
When Detective is disabled for a master account, the master account's behavior graph is disabled.
239240
```
241+
242+
## Contributing to this project
243+
244+
### Running tests
245+
246+
```
247+
# Install requirements
248+
pip3 install boto3 pytest
249+
250+
# In the tests/ directory...
251+
pytest -s
252+
```

enableDetective.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ def __call__(self, parser, namespace, values, option_string=None):
6464
parser.add_argument('--enabled_regions', type=str,
6565
help=('Regions to enable Detective. If not specified, '
6666
'all available regions enabled.'))
67+
parser.add_argument('--disable_email', action='store_true',
68+
help=('Don\'t send emails to the member accounts. Member '
69+
'accounts must still accept the invitation before '
70+
'they are added to the behavior graph.'))
6771
parser.add_argument('--tags',
6872
action=ParseCommaSeparatedKeyValuePairsAction,
6973
help='Comma-separated list of tag key-value pairs to be added '
@@ -240,7 +244,7 @@ def _master_memberList(g: str) -> typing.List[typing.Dict]:
240244
{g: {x['AccountId'] for x in v if x['Status'] == 'INVITED'} for g, v in pending})
241245

242246

243-
def create_members(d_client: botocore.client.BaseClient, graph_arn: str, account_ids: typing.Set[str],
247+
def create_members(d_client: botocore.client.BaseClient, graph_arn: str, disable_email: bool, account_ids: typing.Set[str],
244248
account_csv: typing.Dict[str, str]) -> typing.Set[str]:
245249
"""
246250
Creates member accounts for all accounts in the csv that are not present in the graph member set.
@@ -269,7 +273,8 @@ def create_members(d_client: botocore.client.BaseClient, graph_arn: str, account
269273
for x in set_difference]
270274
response = d_client.create_members(GraphArn=graph_arn,
271275
Message='Automatically generated invitation',
272-
Accounts=new_members)
276+
Accounts=new_members,
277+
DisableEmailNotification=disable_email)
273278
for error in response['UnprocessedAccounts']:
274279
logging.exception(f'Could not create member for account {error["AccountId"]} in '
275280
f'graph {graph_arn}: {error["Reason"]}')
@@ -348,7 +353,7 @@ def enable_detective(d_client: botocore.client.BaseClient, region: str, tags: di
348353

349354
for graph, members in all_members.items():
350355
new_accounts = create_members(
351-
d_client, graph, members, aws_account_dict)
356+
d_client, graph, args.disable_email, members, aws_account_dict)
352357
print("Sleeping for 5s to allow new members' invitations to propagate.")
353358
time.sleep(5)
354359
accept_invitations(args.assume_role, itertools.chain(

0 commit comments

Comments
 (0)