Example #1
0
def list_all_tasks(var):
    """
    Endpoint for calling Graph API
    """
    init_dao(client_id, client_secret, tenant_id, refresh_token)

    if var.lower() == "tasks":
        app.logger.info(f'Requesting {var} from the graph API')
        return Response(stream_as_json(
            get_tasks(get_plans(get_all_objects('/groups/')))),
                        content_type='application/json')
    elif var.lower() == "plans":
        app.logger.info(f'Requesting {var} from the graph API')
        return Response(stream_as_json(get_plans(get_all_objects('/groups/'))),
                        request.args.get('since'),
                        content_type='application/json')
    elif var.lower() == "create_plans":
        app.logger.info(f'Requesting {var} from the graph API')
        request_data = request.get_data()
        return create_plans(json.loads(str(request_data.decode("utf-8"))))
    elif var.lower() == "groups":
        app.logger.info(f'Requesting {var} from the graph API')
        return Response(get_all_groups(request.args.get('since')),
                        content_type='application/json')
    elif var.lower() == "users":
        app.logger.info(f'Requesting {var} from the graph API')
        return Response(get_all_users(request.args.get('since')),
                        content_type='application/json')
    elif var.lower() == "create_tasks":
        app.logger.info(f'Requesting {var} from the graph API')
        request_data = request.get_data()
        return create_tasks(json.loads(str(request_data.decode("utf-8"))))
    elif var.lower() == "update_tasks":
        app.logger.info(f'Requesting {var} from the graph API')
        request_data = request.get_data()
        return update_tasks(json.loads(str(request_data.decode("utf-8"))))
    elif var.lower() == "create_buckets":
        app.logger.info(f'Requesting {var} from the graph API')
        request_data = request.get_data()
        return create_buckets(json.loads(str(request_data.decode("utf-8"))))

    else:
        app.logger.warning(
            f'The following request value : {var} \n - does not comply with what is currently configured backend'
        )
        return Response(json.dumps({
            "You need to choose a configured <value> in the path '/planner/<value>'":
            "I.e. : 'tasks', 'plans', 'groups' or 'users'"
        }),
                        content_type='application/json')
Example #2
0
def get_all_users(delta=None):
    """
    Fetch and stream back users from Azure AD via MS Graph API
    :param delta: delta token from last request
    :return: generated JSON output with all fetched users
    """
    yield from stream_as_json(get_all_objects(f'{RESOURCE_PATH}delta', delta))
def get_posts_for_thread(group_id, thread):
    try:
        yield from get_all_objects(
            f'/groups/{group_id}/threads/{thread}/posts')
    except requests.exceptions.HTTPError:
        # already logged in make_request function, no action needed
        pass
def get_threads_for_conversation(group_id, conversation_id):
    try:
        yield from get_all_objects(
            f'/groups/{group_id}/conversations/{conversation_id}/threads')
    except requests.exceptions.HTTPError:
        # already logged in make_request function, no action needed
        pass
Example #5
0
def list_all_tasks():
    if r.args.get('auth') and r.args.get('auth') == 'user':
        init_dao_on_behalf_on(env('client_id'), env('client_secret'), env('tenant_id'), env('username'),
                              env('password'))
    else:
        init_dao(env('client_id'), env('client_secret'), env('tenant_id'))
    return Response(stream_as_json(get_tasks(get_plans(get_all_objects('/groups/')))), content_type=CT)
Example #6
0
def generic_graph_api_request(path=None):
    """
    Generic Endpoint to call Microsoft Graph API.
    Any request in Microsoft Graph API can be issued here.
    :return: 200 for successful GET requests
             200 and malformed json for erronous GET requests
             code and response from graghapi for other cases
    """
    if r.args.get('auth') and r.args.get('auth') == 'user':
        init_dao_on_behalf_on(env('client_id'), env('client_secret'), env('tenant_id'), env('username'),
                              env('password'))
    else:
        init_dao(env('client_id'), env('client_secret'), env('tenant_id'))
    try:
        if r.method.lower() == 'get':
            response = Response(stream_as_json(get_all_objects(f'/{path}', params=r.args)), content_type=CT, status=200)
        else:
            url=f'{GRAPH_URL}/{path}'
            data=json.loads(r.data) if r.data else None

            response = Response(json.dumps(make_request(url=url, method=r.method, data=data)), content_type=CT, status=200)
    except HTTPError as error:
        logging.exception(error)
        response = Response(error.response.text, content_type=CT, status=error.response.status_code)

    return response
Example #7
0
def list_all_plans():
    """
    Endpoint to list all plans from Microsoft Planner service
    :return:
    """
    if r.args.get('auth') and r.args.get('auth') == 'user':
        init_dao_on_behalf_on(env('client_id'), env('client_secret'), env('tenant_id'), env('username'),
                              env('password'))
    else:
        init_dao(env('client_id'), env('client_secret'), env('tenant_id'))
    return Response(stream_as_json(get_plans(get_all_objects('/groups/'))), r.args.get('since'), content_type=CT)
Example #8
0
def list_objects(kind):
    """
    Endpoint to fetch all objects of given type from MS graph API
    :request_argument since - delta token returned from last request (if exist)
    :return: JSON array with fetched groups
    """
    if r.args.get('auth') and r.args.get('auth') == 'user':
        init_dao_on_behalf_on(env('client_id'), env('client_secret'), env('tenant_id'), env('username'),
                              env('password'))
    else:
        init_dao(env('client_id'), env('client_secret'), env('tenant_id'))
    return Response(
        stream_as_json(get_all_objects(f'/{kind}/{"delta" if SUPPORTS_SINCE else ""}', r.args.get('since'))),
        content_type=CT)
def get_plans_for_group(group_id):
    try:
        yield from get_all_objects(f'/groups/{group_id}/planner/plans')
    except requests.exceptions.HTTPError:
        # already logged in make_request function, no action needed
        pass
def get_tasks_for_plan(plan_id):
    yield from get_all_objects(f'/planner/plans/{plan_id}/tasks')
 def _get_plans_generator(self, group_id):
     yield from get_all_objects(f'/groups/{group_id}/planner/plans')
 def _get_objects_in_plan_generator(self, plan_id):
     yield from get_all_objects(f'/planner/plans/{plan_id}/tasks')