<s> """<STR_LIT>""" <EOL> from joblib import Parallel , delayed <EOL> from botor . aws . iam import get_role_inline_policies <EOL> from botor . aws . iam import get_role_instance_profiles <EOL> from botor . aws . iam import get_role_managed_policies <EOL> from botor . aws . iam import list_roles <EOL> from security_monkey . decorators import record_exception , iter_account_region <EOL> from security_monkey . watcher import ChangeItem <EOL> from security_monkey . watcher import Watcher <EOL> from security_monkey import app <EOL> def _basic_config ( role ) : <EOL> return { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:path>' : role . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : role . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : role . get ( '<STR_LIT>' ) . strftime ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : role . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : role . get ( '<STR_LIT>' ) <EOL> } , <EOL> '<STR_LIT>' : role . get ( '<STR_LIT>' ) <EOL> } <EOL> @ record_exception ( ) <EOL> def process_role ( role , ** kwargs ) : <EOL> app . logger . debug ( "<STR_LIT>" . format ( <EOL> index = IAMRole . i_am_singular , <EOL> name = kwargs [ '<STR_LIT:name>' ] , <EOL> account = kwargs [ '<STR_LIT>' ] ) <EOL> ) <EOL> config = _basic_config ( role ) <EOL> config . update ( <EOL> { <EOL> '<STR_LIT>' : get_role_managed_policies ( role , ** kwargs ) , <EOL> '<STR_LIT>' : get_role_inline_policies ( role , ** kwargs ) , <EOL> '<STR_LIT>' : get_role_instance_profiles ( role , ** kwargs ) <EOL> } <EOL> ) <EOL> return config <EOL> class IAMRole ( Watcher ) : <EOL> index = '<STR_LIT>' <EOL> i_am_singular = '<STR_LIT>' <EOL> i_am_plural = '<STR_LIT>' <EOL> def __init__ ( self , accounts = None , debug = False ) : <EOL> super ( IAMRole , self ) . __init__ ( accounts = accounts , debug = debug ) <EOL> @ record_exception ( ) <EOL> def list_roles ( self , ** kwargs ) : <EOL> roles = list_roles ( ** kwargs ) <EOL> return [ role for role in roles if not self . check_ignore_list ( role [ '<STR_LIT>' ] ) ] <EOL> def slurp ( self ) : <EOL> self . prep_for_slurp ( ) <EOL> @ iter_account_region ( index = self . index , accounts = self . accounts , regions = [ '<STR_LIT>' ] ) <EOL> def slurp_items ( ** kwargs ) : <EOL> item_list = [ ] <EOL> exception_map = { } <EOL> kwargs [ '<STR_LIT>' ] = exception_map <EOL> kwargs [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> roles = self . list_roles ( ** kwargs ) <EOL> roles = zip ( <EOL> [ role [ '<STR_LIT>' ] for role in roles ] , <EOL> Parallel ( n_jobs = <NUM_LIT:2> , backend = "<STR_LIT>" ) ( <EOL> delayed ( process_role ) <EOL> ( role , name = role [ '<STR_LIT>' ] , ** kwargs ) <EOL> for role in roles <EOL> ) <EOL> ) <EOL> for role in roles : <EOL> item = IAMRoleItem ( account = kwargs [ '<STR_LIT>' ] , name = role [ <NUM_LIT:0> ] , config = role [ <NUM_LIT:1> ] ) <EOL> item_list . append ( item ) <EOL> return item_list , exception_map <EOL> return slurp_items ( ) <EOL> class IAMRoleItem ( ChangeItem ) : <EOL> def __init__ ( self , account = None , name = None , config = { } ) : <EOL> super ( IAMRoleItem , self ) . __init__ ( <EOL> index = IAMRole . index , <EOL> region = '<STR_LIT>' , <EOL> account = account , <EOL> name = name , <EOL> new_config = config ) </s>
