Пример #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')
Пример #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))
Пример #3
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)
Пример #4
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
Пример #5
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)
Пример #6
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)