parameters: (cleaner, iot_policy_name)
docstring: Detaches all policies from the client. It will construct a list of resources and detaches them. There is
      currently no boto3 functionality to check if a policy is attached to a principal, so we are skipping validation.
      :param cleaner: A Cleaner object from the main cleanup.py script
      :return: None
docstring_summary: Detaches all policies from the client. It will construct a list of resources and detaches them. There is
      currently no boto3 functionality to check if a policy is attached to a principal, so we are skipping validation.
      :param cleaner: A Cleaner object from the main cleanup.py script
      :return: None
docstring_tokens: Detaches all policies from the client . It will construct a list of resources and detaches them . There is currently no boto3 functionality to check if a policy is attached to a principal so we are skipping validation . : param cleaner : A Cleaner object from the main cleanup . py script : return : None
function: def _detach_policies_from_principals(cleaner, iot_policy_name):
      """
      Detaches all policies from the client. It will construct a list of resources and detaches them. There is
      currently no boto3 functionality to check if a policy is attached to a principal, so we are skipping validation.
      :param cleaner: A Cleaner object from the main cleanup.py script
      :return: None
      """
      iot_principal_name_list = []
  
      # Construct list
      try:
          iot_principal_policies_paginator = cleaner.iot_client.get_paginator('list_policy_principals')
          iot_principal_policies_iterator = iot_principal_policies_paginator.paginate(policyName=iot_policy_name)
  
          for page in iot_principal_policies_iterator:
              for iot_principal_info in page['principals']:
                  if ':cert/' in iot_principal_info:
                      # For a cert, the principal is the full arn
                      principal_name = iot_principal_info
                  else:
                      # Response is in the form of accountId:CognitoId - when we detach we only want cognitoId
                      principal_name = iot_principal_info.split(':', 1)[1]
                  print('  found principal {}'.format(principal_name))
                  iot_principal_name_list.append(principal_name)
      except KeyError as e:
          print("      ERROR: Unexpected KeyError while detaching policies from principals. {}".format(
              exception_utils.message(e)))
          return
      except ClientError as e:
          print("      ERROR: Unexpected error for paginator for the iot client. {}".format(exception_utils.message(e)))
          return
  
      # Detach policies from principals
      for principal_name in iot_principal_name_list:
          try:
              print('  Detaching policy {} from principal {}'.format(iot_policy_name, principal_name))
              cleaner.iot_client.detach_principal_policy(policyName=iot_policy_name, principal=principal_name)
          except ClientError as e:
              if e.response["Error"]["Code"] == "TooManyRequestsException":
                  print('    too many requests, sleeping...')
                  time.sleep(cleaner.wait_interval)
              else:
                  print('      ERROR: Failed to detach policy {0} from principal {1} due to {2}'
                        .format(iot_policy_name, principal_name, exception_utils.message(e)))
                  cleaner.add_to_failed_resources("iot", principal_name)
function_tokens: def _detach_policies_from_principals ( cleaner , iot_policy_name ) : iot_principal_name_list = [ ] # Construct list try : iot_principal_policies_paginator = cleaner . iot_client . get_paginator ( 'list_policy_principals' ) iot_principal_policies_iterator = iot_principal_policies_paginator . paginate ( policyName = iot_policy_name ) for page in iot_principal_policies_iterator : for iot_principal_info in page [ 'principals' ] : if ':cert/' in iot_principal_info : # For a cert, the principal is the full arn principal_name = iot_principal_info else : # Response is in the form of accountId:CognitoId - when we detach we only want cognitoId principal_name = iot_principal_info . split ( ':' , 1 ) [ 1 ] print ( '  found principal {}' . format ( principal_name ) ) iot_principal_name_list . append ( principal_name ) except KeyError as e : print ( "      ERROR: Unexpected KeyError while detaching policies from principals. {}" . format ( exception_utils . message ( e ) ) ) return except ClientError as e : print ( "      ERROR: Unexpected error for paginator for the iot client. {}" . format ( exception_utils . message ( e ) ) ) return # Detach policies from principals for principal_name in iot_principal_name_list : try : print ( '  Detaching policy {} from principal {}' . format ( iot_policy_name , principal_name ) ) cleaner . iot_client . detach_principal_policy ( policyName = iot_policy_name , principal = principal_name ) except ClientError as e : if e . response [ "Error" ] [ "Code" ] == "TooManyRequestsException" : print ( '    too many requests, sleeping...' ) time . sleep ( cleaner . wait_interval ) else : print ( '      ERROR: Failed to detach policy {0} from principal {1} due to {2}' . format ( iot_policy_name , principal_name , exception_utils . message ( e ) ) ) cleaner . add_to_failed_resources ( "iot" , principal_name )