44import logging
55import boto3
66import time
7+ from typing import Dict , List , Optional , Any
78
89from botocore .exceptions import ClientError
910
1718class ControlTowerWrapper :
1819 """Encapsulates AWS Control Tower and Control Catalog functionality."""
1920
20- def __init__ (self , controltower_client , controlcatalog_client ):
21+ def __init__ (
22+ self , controltower_client : boto3 .client , controlcatalog_client : boto3 .client
23+ ):
2124 """
2225 :param controltower_client: A Boto3 Amazon ControlTower client.
2326 :param controlcatalog_client: A Boto3 Amazon ControlCatalog client.
@@ -66,10 +69,10 @@ def list_baselines(self):
6669 # snippet-start:[python.example_code.controltower.EnableBaseline]
6770 def enable_baseline (
6871 self ,
69- target_identifier ,
70- identity_center_baseline ,
71- baseline_identifier ,
72- baseline_version ,
72+ target_identifier : str ,
73+ identity_center_baseline : str ,
74+ baseline_identifier : str ,
75+ baseline_version : str ,
7376 ):
7477 """
7578 Enables a baseline for the specified target if it's not already enabled.
@@ -154,7 +157,7 @@ def list_controls(self):
154157 # snippet-end:[python.example_code.controltower.ListControls]
155158
156159 # snippet-start:[python.example_code.controltower.EnableControl]
157- def enable_control (self , control_arn , target_identifier ):
160+ def enable_control (self , control_arn : str , target_identifier : str ):
158161 """
159162 Enables a control for a specified target.
160163
@@ -187,8 +190,11 @@ def enable_control(self, control_arn, target_identifier):
187190 ):
188191 logger .info ("Control is already enabled for this target" )
189192 return None
190- elif (err .response ["Error" ]["Code" ] == "ResourceNotFoundException"
191- and "not registered with AWS Control Tower" in err .response ["Error" ]["Message" ]):
193+ elif (
194+ err .response ["Error" ]["Code" ] == "ResourceNotFoundException"
195+ and "not registered with AWS Control Tower"
196+ in err .response ["Error" ]["Message" ]
197+ ):
192198 logger .error ("Control Tower must be enabled to work with controls." )
193199 return None
194200 logger .error (
@@ -201,7 +207,7 @@ def enable_control(self, control_arn, target_identifier):
201207 # snippet-end:[python.example_code.controltower.EnableControl]
202208
203209 # snippet-start:[python.example_code.controltower.GetControlOperation]
204- def get_control_operation (self , operation_id ):
210+ def get_control_operation (self , operation_id : str ):
205211 """
206212 Gets the status of a control operation.
207213
@@ -228,7 +234,7 @@ def get_control_operation(self, operation_id):
228234 # snippet-end:[python.example_code.controltower.GetControlOperation]
229235
230236 # snippet-start:[python.example_code.controltower.GetBaselineOperation]
231- def get_baseline_operation (self , operation_id ):
237+ def get_baseline_operation (self , operation_id : str ):
232238 """
233239 Gets the status of a baseline operation.
234240
@@ -255,7 +261,7 @@ def get_baseline_operation(self, operation_id):
255261 # snippet-end:[python.example_code.controltower.GetBaselineOperation]
256262
257263 # snippet-start:[python.example_code.controltower.DisableControl]
258- def disable_control (self , control_arn , target_identifier ):
264+ def disable_control (self , control_arn : str , target_identifier : str ):
259265 """
260266 Disables a control for a specified target.
261267
@@ -350,7 +356,7 @@ def list_enabled_baselines(self):
350356 # snippet-end:[python.example_code.controltower.ListEnabledBaselines]
351357
352358 # snippet-start:[python.example_code.controltower.ResetEnabledBaseline]
353- def reset_enabled_baseline (self , enabled_baseline_identifier ):
359+ def reset_enabled_baseline (self , enabled_baseline_identifier : str ):
354360 """
355361 Resets an enabled baseline for a specific target.
356362
@@ -384,7 +390,7 @@ def reset_enabled_baseline(self, enabled_baseline_identifier):
384390 # snippet-end:[python.example_code.controltower.ResetEnabledBaseline]
385391
386392 # snippet-start:[python.example_code.controltower.DisableBaseline]
387- def disable_baseline (self , enabled_baseline_identifier ):
393+ def disable_baseline (self , enabled_baseline_identifier : str ):
388394 """
389395 Disables a baseline for a specific target and waits for the operation to complete.
390396
@@ -423,7 +429,7 @@ def disable_baseline(self, enabled_baseline_identifier):
423429 # snippet-end:[python.example_code.controltower.DisableBaseline]
424430
425431 # snippet-start:[python.example_code.controltower.ListEnabledControls]
426- def list_enabled_controls (self , target_identifier ):
432+ def list_enabled_controls (self , target_identifier : str ):
427433 """
428434 Lists all enabled controls for a specific target.
429435
@@ -445,8 +451,11 @@ def list_enabled_controls(self, target_identifier):
445451 "Access denied. Please ensure you have the necessary permissions."
446452 )
447453 return enabled_controls
448- elif (err .response ["Error" ]["Code" ] == "ResourceNotFoundException"
449- and "not registered with AWS Control Tower" in err .response ["Error" ]["Message" ]):
454+ elif (
455+ err .response ["Error" ]["Code" ] == "ResourceNotFoundException"
456+ and "not registered with AWS Control Tower"
457+ in err .response ["Error" ]["Message" ]
458+ ):
450459 logger .error ("Control Tower must be enabled to work with controls." )
451460 return enabled_controls
452461 else :
0 commit comments