Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
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