Beispiel #1
0
async def put_files(request, body, overwrite=False, pretty=False, wait_for_complete=False, path=None):
    """Upload file in manager or local_node.

    :param body: Body request with the content of the file to be uploaded
    :param overwrite: If set to false, an exception will be raised when updating contents of an already existing
    filename.
    :param pretty: Show results in human-readable format
    :param wait_for_complete: Disable timeout response
    :param path: Filepath to return.
    """
    # Parse body to utf-8
    Body.validate_content_type(request, expected_content_type='application/octet-stream')
    parsed_body = Body.decode_body(body, unicode_error=1911, attribute_error=1912)

    f_kwargs = {'path': path,
                'overwrite': overwrite,
                'content': parsed_body}

    dapi = DistributedAPI(f=manager.upload_file,
                          f_kwargs=remove_nones_to_dict(f_kwargs),
                          request_type='local_any',
                          is_async=False,
                          wait_for_complete=wait_for_complete,
                          logger=logger,
                          rbac_permissions=request['token_info']['rbac_policies']
                          )
    data = raise_if_exc(await dapi.distribute_function())

    return web.json_response(data=data, status=200, dumps=prettify if pretty else dumps)
Beispiel #2
0
async def update_configuration(request,
                               body,
                               pretty=False,
                               wait_for_complete=False):
    """Update manager's or local_node's configuration (ossec.conf).

    Parameters
    ----------
    pretty : bool, optional
        Show results in human-readable format. It only works when `raw` is False (JSON format). Default `True`
    wait_for_complete : bool, optional
        Disable response timeout or not. Default `False`
    """
    # Parse body to utf-8
    Body.validate_content_type(
        request, expected_content_type='application/octet-stream')
    parsed_body = Body.decode_body(body,
                                   unicode_error=1911,
                                   attribute_error=1912)

    f_kwargs = {'new_conf': parsed_body}

    dapi = DistributedAPI(
        f=manager.update_ossec_conf,
        f_kwargs=remove_nones_to_dict(f_kwargs),
        request_type='local_any',
        is_async=False,
        wait_for_complete=wait_for_complete,
        logger=logger,
        rbac_permissions=request['token_info']['rbac_policies'])
    data = raise_if_exc(await dapi.distribute_function())

    return web.json_response(data=data,
                             status=200,
                             dumps=prettify if pretty else dumps)
Beispiel #3
0
async def put_group_config(request, body, group_id, pretty=False, wait_for_complete=False):
    """Update group configuration.

    Update an specified group's configuration. This API call expects a full valid XML file with the shared configuration
    tags/syntax.

    :param body: Body parameters
    :param pretty: Show results in human-readable format
    :param wait_for_complete: Disable timeout response
    :param group_id: Group ID.
    :return: ApiResponse
    """
    # Parse body to utf-8
    Body.validate_content_type(request, expected_content_type='application/xml')
    parsed_body = Body.decode_body(body, unicode_error=2006, attribute_error=2007)

    f_kwargs = {'group_list': [group_id],
                'file_data': parsed_body}

    dapi = DistributedAPI(f=agent.upload_group_file,
                          f_kwargs=remove_nones_to_dict(f_kwargs),
                          request_type='local_master',
                          is_async=False,
                          wait_for_complete=wait_for_complete,
                          logger=logger,
                          rbac_permissions=request['token_info']['rbac_policies']
                          )
    data = raise_if_exc(await dapi.distribute_function())

    return web.json_response(data=data, status=200, dumps=prettify if pretty else dumps)
async def put_files_node(request, body, node_id, path, overwrite=False, pretty=False, wait_for_complete=False):
    """Upload file contents in a specified cluster node.

    :param body: Body request with the content of the file to be uploaded
    :param node_id: Cluster node name
    :param path: Filepath to upload the new file
    :param overwrite: If set to false, an exception will be raised when uploading an already existing filename.
    :param pretty: Show results in human-readable format
    :param wait_for_complete: Disable timeout response
    """

    # parse body to utf-8
    parsed_body = Body.decode_body(body, unicode_error=1911, attribute_error=1912)

    f_kwargs = {'node_id': node_id,
                'path': path,
                'overwrite': overwrite,
                'content': parsed_body}

    nodes = await get_system_nodes()
    dapi = DistributedAPI(f=manager.upload_file,
                          f_kwargs=remove_nones_to_dict(f_kwargs),
                          request_type='distributed_master',
                          is_async=False,
                          wait_for_complete=wait_for_complete,
                          logger=logger,
                          rbac_permissions=request['token_info']['rbac_policies'],
                          nodes=nodes,
                          cluster_required=True
                          )
    data = raise_if_exc(await dapi.distribute_function())

    return web.json_response(data=data, status=200, dumps=prettify if pretty else dumps)
Beispiel #5
0
async def put_file(request,
                   body,
                   filename=None,
                   overwrite=False,
                   pretty=False,
                   wait_for_complete=False):
    """Upload a rule file.
    
    Parameters
    ----------
    body : dict
        Body request with the file content to be uploaded.
    filename : str, optional
        Name of the file. Default `None`
    overwrite : bool, optional
        If set to false, an exception will be raised when updating contents of an already existing file. Default `False`
    pretty : bool, optional
        Show results in human-readable format. Default `False`
    wait_for_complete : bool, optional
        Disable timeout response. Default `False`

    Returns
    -------
    web.json_response
    """
    # Parse body to utf-8
    Body.validate_content_type(
        request, expected_content_type='application/octet-stream')
    parsed_body = Body.decode_body(body,
                                   unicode_error=1911,
                                   attribute_error=1912)

    f_kwargs = {
        'filename': filename,
        'overwrite': overwrite,
        'content': parsed_body
    }

    dapi = DistributedAPI(
        f=rule_framework.upload_rule_file,
        f_kwargs=remove_nones_to_dict(f_kwargs),
        request_type='local_master',
        is_async=False,
        wait_for_complete=wait_for_complete,
        logger=logger,
        rbac_permissions=request['token_info']['rbac_policies'])
    data = raise_if_exc(await dapi.distribute_function())

    return web.json_response(data=data,
                             status=200,
                             dumps=prettify if pretty else dumps)