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

Create CLI to extract API data from specification file #5519

Merged
merged 4 commits into from
Jun 12, 2023

Conversation

Desvelao
Copy link
Member

@Desvelao Desvelao commented Jun 5, 2023

Description

This pull request is adds a new CLI to extract API data from the specification file.

Changes

  • Create a new CLI
  • Add a new script package

Issues Resolved

#5036

Evidence

  • CLI help
node@osd:~/kbn/plugins/wazuh$ node scripts/generate-api-data.js 
Wazuh API data extractor - Help
Extract the Wazuh API data

Some warning messages are sent to stderr.

Usage: node /home/node/kbn/plugins/wazuh/scripts/generate-api-data.js --spec <URL OpenAPI file/local file in POJO> [options]

Options:
  --display-configuration                             Display the configuration. Log to sterr.
  --examples                                          Display examples of usage.
  --help                                              Display the help.
  --format <format>                                   Set the format. Default: plugin.
    <format> is one of:
      plugin: Plugin
  --output <output>                                   Set the output. Default: stdout.
    <output> is one of:
      file: file.
      stdout: stdout.
  --output-directory <directory>                      Set the directory.
  --spec <URL OpenAPI file/local file in POJO>        Define the specification file.

  • package script
node@osd:~/kbn/plugins/wazuh$ yarn generate:api-data
yarn run v1.22.19
warning Skipping preferred cache folder "/home/node/.cache/yarn" because it is not writable.
warning Selected the next writable cache folder in the list, will be "/tmp/.yarn-cache-1000".
$ 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 2.35s.

Test

wka-pr-5519-tests.md

Check List

  • All tests pass
    • yarn test:jest
  • New functionality includes testing.
  • New functionality has been documented.
  • Update CHANGELOG.md
  • Commits are signed per the DCO using --signoff

Desvelao added 2 commits June 5, 2023 09:14
- Create a new CLI to get the API data from the API specification file
- Add a new package script to get the data from the development major.minor
  version of API
- Remove the previous scripts and package script
@Desvelao Desvelao self-assigned this Jun 5, 2023
@Desvelao Desvelao marked this pull request as ready for review June 5, 2023 08:34
@Desvelao Desvelao requested a review from a team as a code owner June 5, 2023 08:34
@yenienserrano
Copy link
Member

Wazuh dashboard

Legend:
⚫: none
🟢: pass
🟡: warning
🔴: fail
⚪: not applicable

Other

Test Result
Ensure the CLI help is working. Use node scripts/generate-api-data.js 🟢
Ensure the API data is generated and saved to files using the package script. Removes the files stored in common/api-info and runs the package script yarn:generate-api. New files with the API data should be created in the common/api-info path 🟢
Use the stdout output. Use node scripts/genrate-api-data.js --spec and the information should be displayed in the console 🟢

Details

🟢 Ensure the CLI help is working. Use node scripts/generate-api-data.js

image

🟢 Ensure the API data is generated and saved to files using the package script. Removes the files stored in common/api-info and runs the package script yarn:generate-api. New files with the API data should be created in the common/api-info path

image

🟢 Use the stdout output. Use node scripts/genrate-api-data.js --spec and the information should be displayed in the console

image

yenienserrano
yenienserrano previously approved these changes Jun 7, 2023
Copy link
Member

@yenienserrano yenienserrano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@github-actions
Copy link
Contributor

Code coverage (Jest) % values
Statements 9.52% ( 3503 / 36786 )
Branches 5.02% ( 1433 / 28503 )
Functions 8.19% ( 747 / 9114 )
Lines 9.6% ( 3383 / 35235 )

@AlexRuiz7 AlexRuiz7 merged commit 92f9b91 into 4.5 Jun 12, 2023
@AlexRuiz7 AlexRuiz7 deleted the feat/5036-extract-api-data-from-api-spec branch June 12, 2023 11:04
@github-actions
Copy link
Contributor

The backport to 4.5-7.10 failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-4.5-7.10 4.5-7.10
# Navigate to the new working tree
cd .worktrees/backport-4.5-7.10
# Create a new branch
git switch --create backport-5519-to-4.5-7.10
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 92f9b91ad1d72abce1d672fa06a7fb81c553cefa
# Push it to GitHub
git push --set-upstream origin backport-5519-to-4.5-7.10
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-4.5-7.10

Then, create a pull request where the base branch is 4.5-7.10 and the compare/head branch is backport-5519-to-4.5-7.10.

@github-actions
Copy link
Contributor

The backport to 4.5-7.16 failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-4.5-7.16 4.5-7.16
# Navigate to the new working tree
cd .worktrees/backport-4.5-7.16
# Create a new branch
git switch --create backport-5519-to-4.5-7.16
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 92f9b91ad1d72abce1d672fa06a7fb81c553cefa
# Push it to GitHub
git push --set-upstream origin backport-5519-to-4.5-7.16
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-4.5-7.16

Then, create a pull request where the base branch is 4.5-7.16 and the compare/head branch is backport-5519-to-4.5-7.16.

Desvelao added a commit that referenced this pull request Jun 12, 2023
* feat: create CLI to get the API data from the API spec file

- Create a new CLI to get the API data from the API specification file
- Add a new package script to get the data from the development major.minor
  version of API
- Remove the previous scripts and package script

* update: update API data

* changelog: add pull request entry

Changed version of swagger-client development dependency
---------

Co-authored-by: Álex Ruiz <alejandro.ruiz.becerra@wazuh.com>
(cherry picked from commit 92f9b91)
Desvelao added a commit that referenced this pull request Jun 12, 2023
* feat: create CLI to get the API data from the API spec file

- Create a new CLI to get the API data from the API specification file
- Add a new package script to get the data from the development major.minor
  version of API
- Remove the previous scripts and package script

* update: update API data

* changelog: add pull request entry

---------

Co-authored-by: Álex Ruiz <alejandro.ruiz.becerra@wazuh.com>
(cherry picked from commit 92f9b91)
AlexRuiz7 pushed a commit that referenced this pull request Jun 14, 2023
… file (#5553)

Create CLI to extract API data from specification file (#5519)

* feat: create CLI to get the API data from the API spec file

- Create a new CLI to get the API data from the API specification file
- Add a new package script to get the data from the development major.minor
  version of API
- Remove the previous scripts and package script

* update: update API data

* changelog: add pull request entry

---------

Co-authored-by: Álex Ruiz <alejandro.ruiz.becerra@wazuh.com>
(cherry picked from commit 92f9b91)
AlexRuiz7 pushed a commit that referenced this pull request Jun 14, 2023
… file (#5552)

Create CLI to extract API data from specification file (#5519)

* feat: create CLI to get the API data from the API spec file

- Create a new CLI to get the API data from the API specification file
- Add a new package script to get the data from the development major.minor
  version of API
- Remove the previous scripts and package script

* update: update API data

* changelog: add pull request entry

Changed version of swagger-client development dependency
---------

Co-authored-by: Álex Ruiz <alejandro.ruiz.becerra@wazuh.com>
(cherry picked from commit 92f9b91)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor scripts/generate-api-4.0-info/generate-api-4.0-info.js to use OpenAPI spec
3 participants