Skip to content
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

Refactor scripts/generate-api-4.0-info/generate-api-4.0-info.js to use OpenAPI spec #5036

Closed
gdiazlo opened this issue Dec 23, 2022 · 5 comments · Fixed by #5519, #5552 or #5553
Closed
Assignees
Labels
level/task Task issue request/operational Operational requests type/enhancement Enhancement issue

Comments

@gdiazlo
Copy link
Member

gdiazlo commented Dec 23, 2022

Describe the solution you'd like

We want to simplify this process by using the OpenAPI spec of the wazuh manager obtained from the repository, instead of a live instance.

This process should be executed on each package generation, ensuring the appropriate information is included.

@Desvelao
Copy link
Member

Desvelao commented Apr 13, 2023

We should consider adding the data of fields supported by q query parameter to the same file related to API endpoints instead of creating a new one. This data could be used by the new search bar.

Related issue: #5370

@gdiazlo gdiazlo added the level/task Task issue label Apr 26, 2023
@Desvelao Desvelao self-assigned this May 31, 2023
@Desvelao
Copy link
Member

Desvelao commented Jun 2, 2023

Research

The current script generates API data for using a live instance of Wazuh manager:

  • endpoints: get the API spec in JSON served by the Wazuh API and get the data related to API endpoints
  • security_actions: this data is retrieved through a Wazuh API endpoint GET /security/actions

I am reviewing the API spec file in yaml and it is required to do some changes to get the same output regarding the data coming from the Wazuh API endpoint because this data is not directly get from the API spec file.

The GET /security/actions response is the result of managing the data of the endpoints. This logic is located in: https://github.com/wazuh/wazuh/blob/v4.4.3/framework/wazuh/security.py#L1090-L1105

Approach

Regarding a previous investigation to get other data (#5370 (comment)) from the Wazuh API specification, we saw that using the swagger-client dependency reduces logic to resolve the API spec references. So I decided, to implement this to reduce the overcomplication there is in the current script.

I will create a new CLI, based on the POC script of #5370 (comment)

@Desvelao
Copy link
Member

Desvelao commented Jun 2, 2023

Changes

  • Created the new CLI whose output is similar to the previous script.
  • Reduce the logic to run the package script. The previous package script run a .sh and then a .js file. Now, this was reduced to a .js file.

@Desvelao
Copy link
Member

Desvelao commented Jun 2, 2023

Problem

While I was reviewing the differences in the output files of previous and new scripts, I realized the previous output doesn't include data of the body parameters and I think that is used by the API Console section of the Wazuh plugin to display suggestions of the body parameters.

I am researching if the body parameter suggestions feature is currently in the API Console but this could not be working due to the Wazuh API data extraction done with the script don't get the body parameters.

@Desvelao
Copy link
Member

Backports

I am creating the backport for 4.5-7.10 (Kibana 7.10.2) and I found the swagger-client is not compatible with the NodeJS version of that Kibana version:

node@kibana:~/kbn/plugins/wazuh$ yarn add swagger-client
yarn add v1.22.5
[1/4] Resolving packages...
[2/4] Fetching packages...
error [email protected]: The engine "node" is incompatible with this module. Expected version ">= 12.20". Got "10.23.1"
error Found incompatible module

I was researching a previous version compatible with NodeJS 10.23.1 and I found 3.13.7: https://github.com/swagger-api/swagger-js/tree/v3.13.7

I added this version:

yarn add -D [email protected]

Then, I run the script and this seems to be working without problems:

node@kibana:~/kbn/plugins/wazuh$ yarn generate:api-data
yarn run v1.22.5
$ node scripts/generate-api-data.js --spec https://raw.githubusercontent.com/wazuh/wazuh/$(node -e "console.log(require('./package.json').version.split('.').splice(0,2).join('.'))")/api/api/spec/spec.yaml --output file --output-directory common/api-info --display-configuration
{ displayConfiguration: true,
  displayExamples: false,
  displayHelp: false,
  format: 'plugin',
  output: 'file',
  spec:
   'https://raw.githubusercontent.com/wazuh/wazuh/4.5/api/api/spec/spec.yaml',
  outputDirectory: '/home/node/kbn/plugins/wazuh/common/api-info' }
File was created! Path: /home/node/kbn/plugins/wazuh/common/api-info/security-actions.json
File was created! Path: /home/node/kbn/plugins/wazuh/common/api-info/endpoints.json
Done in 1.60s.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment