Ejemplo n.º 1
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)
Ejemplo n.º 2
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
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
def post_groups():
    """
    Endpoint to synchronize groups from Sesam into Azure AD
    :return: 200 empty response if everything OK
    """
    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'))
    sync_group_array(json.loads(r.data))
    return Response('')
Ejemplo n.º 5
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)
Ejemplo n.º 6
0
def post_users():
    """
    Endpoint to synchronize users from Sesam into Azure AD
    :return: 200 empty response if everything OK
    """
    try:
        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'))
        sync_user_array(json.loads(r.data), str_to_bool(r.args.get("force_delete")))
        response = Response('')
    except HTTPError as error:
        logging.exception(error)
        response = Response(error.response.text, content_type=CT, status=error.response.status_code)
    return response