def create_group(group_name): try: resp = CLIENT.create_group(GroupName=group_name, UserPoolId=settings.USER_POOL_ID) except Exception as e: raise APIException.ParseError( "Exception in create_group {}".format(str(e)), status.HTTP_400_BAD_REQUEST) return resp
def add_user_to_group(user_details, group_name): try: response = CLIENT.admin_add_user_to_group( UserPoolId=settings.USER_POOL_ID, Username=user_details['Username'], GroupName=group_name) except Exception as e: log.error("Exception in add_user_to_group {}".format(str(e))) raise APIException.ParseError( "Exception in add_user_to_group {}".format(str(e)), status.HTTP_400_BAD_REQUEST) return response
def check_if_group_exists(group_name_stripped): try: group = CLIENT.get_group(GroupName=group_name_stripped, UserPoolId=settings.USER_POOL_ID) except CLIENT.exceptions.ResourceNotFoundException as e: log.error("Group doesnt exists %s" % str(e)) group = create_group(group_name_stripped) except Exception as e: log.error("Error while checking from group %s" % str(e)) raise APIException.ParseError( "Exception in check_if_group_exists {}".format(str(e)), status.HTTP_400_BAD_REQUEST) return group