-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merge group files endpoints #21653
Merge group files endpoints #21653
Conversation
1412554
to
586795c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work @GGP1
LGTM!,
My only question is if it would be better for readibility purposes to change the raw default value to a bool False
instead of `None.
I've seen both in the code, I don't think there's a standard but I agree that using |
f84e142
to
cedccbc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Just some minor changes were requested. Also, I found a strange behaviour. I guess this is expected, but I would like to confirm.
I tried creating a test.json
file. When the content-type returned is application/json
, it is seen this way:
curl -k -X GET "https://localhost:55000/groups/default/files/test.json?raw=true" -H "Authorization: Bearer $TOKEN" -v
However, this does not happen when xml content is returned as application/xml
:
@@ -1360,9 +1361,9 @@ async def get_group_files(request, group_id: str, pretty: bool = False, wait_for | |||
return web.json_response(data=data, status=200, dumps=prettify if pretty else dumps) | |||
|
|||
|
|||
async def get_group_file_json(request, group_id: str, file_name: str, pretty: bool = False, | |||
async def get_group_file(request, group_id: str, file_name: str, raw: bool = False, pretty: bool = False, | |||
wait_for_complete: bool = False) -> web.Response: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wait_for_complete: bool = False) -> web.Response: | |
wait_for_complete: bool = False) -> web.Response | ConnexionResponse: |
response = ConnexionResponse(body=data["data"], mimetype='application/xml') | ||
|
||
return response | ||
return ConnexionResponse(body=data["data"], mimetype=mimetype) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return ConnexionResponse(body=data["data"], mimetype=mimetype) | |
return ConnexionResponse(body=data["data"], mimetype=mimetype) | |
|
||
# ![file_size] [file_name] | ||
regex_header = re.compile(r"^!(\d+)\s*(.*)") | ||
regex_comment = re.compile(r"^\s*#") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's worth skipping comments since the way to mark a comment could be different in each file inside the merged.mg
. The agent.conf
comments (for example) are still being included while those in rcl files are not.
The first line should be skipped though.
@@ -770,33 +820,33 @@ def get_agent_conf_multigroup(multigroup_id: str = None, offset: int = 0, limit: | |||
return {'totalItems': len(data), 'items': cut_array(data, offset=offset, limit=limit)} | |||
|
|||
|
|||
def get_file_conf(filename: str, group_id: str = None, type_conf: str = None, return_format: str = None) -> dict: | |||
"""Return the configuration file as dictionary. | |||
def get_file_conf(filename: str, group_id: str = None, type_conf: str = None, raw: bool = False) -> dict: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def get_file_conf(filename: str, group_id: str = None, type_conf: str = None, raw: bool = False) -> dict: | |
def get_file_conf(filename: str, group_id: str = None, type_conf: str = None, raw: bool = False) -> dict | str: |
|
||
Raises | ||
------ | ||
WazuhResourceNotFound(1710) | ||
Group was not found. | ||
WazuhError(1006) | ||
agent.conf does not exist or there is a problem with the permissions. | ||
The file does not exist or there is a problem with the permissions. | ||
WazuhError(1104) | ||
Invalid file type. | ||
|
||
Returns | ||
------- | ||
dict |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dict | |
dict or str |
@Selutario This is expected, the content of the file is returned as a string, and if the Content-Type is In order to include all the content inside the string, new lines have to be literal and double quotes have to be escaped. The other content types do not behave the same because they don't need to escape or wrap anything (and thus the output is the actual file content). |
02c18e5
to
b4f9e3a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I think we'll need to update the documentation too, at least the RBAC reference.
Please, open a PR for this @GGP1
Description
Merges the
/groups/:group_id/files/:file_name/json
and/groups/:group_id/files/:file_name/xml
endpoints into a single one that takes theraw
parameter which defines whether the response content will be formatted in json or plain text. The response content-type is defined based on the file extension retrieved.Logs/Alerts example
Get merged.mg in plain text
GET /groups/default/files/merged.mg?raw=true
Get merged.mg in JSON
GET /groups/default/files/merged.mg
Get file content using a configuration type
GET /groups/default/files/agent.conf?type=conf