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

Add frontend http client #7000

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

Desvelao
Copy link
Member

@Desvelao Desvelao commented Sep 19, 2024

Description

This pull request adds a http client to the wazuh-core plugin and expose it to manage the API requests that is a composition of old services:

  • WzRequest
  • GenericRequest
  • ApiCheck
  • WzAuthentication

Moreover,

  • Components
    • TableData (generic table component based on a implementation of wazuh plugin)
    • ServerTable (based on TableWzAPI of wazuh plugin)
  • Hooks
    • useStateStorage: uses the localStorage and sessionStorage to persist the runtime data

Issues Resolved

#6959

Evidence

Test

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

- Create HTTP client based on old services
- Create HTTP client request interceptor: request
- Create HTTP client generic: GenericRequest
- Create HTTP client server: WzRequest, ApiCheck and WzAuthentication
- Enhance server API backend client
  See #6995
- Rename ILogger type to Logger
@Desvelao Desvelao self-assigned this Sep 19, 2024
warn: console.warn,
};
// No operation logger
const noopLogger = {
Copy link
Contributor

Choose a reason for hiding this comment

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

You can create a new file for each Logger inside the new folder called logger.

Comment on lines +23 to +45
interface WzRequestServices {
request: HTTPClientRequestInterceptor['request'];
getURL(path: string): string;
getTimeout(): Promise<number>;
getServerAPI(): string;
}

interface ServerAPIResponseItems<T> {
affected_items: Array<T>;
failed_items: Array<any>;
total_affected_items: number;
total_failed_items: number;
}

interface ServerAPIResponseItemsData<T> {
data: ServerAPIResponseItems<T>;
message: string;
error: number;
}

export interface ServerAPIResponseItemsDataHTTPClient<T> {
data: ServerAPIResponseItemsData<T>;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

You can move this interfaces to the types.ts file.

@Desvelao Desvelao changed the title Added frontend http client Add frontend http client Sep 27, 2024
- Add TableData component (based on TableData of main plugin)
- Add ServerTable component (based on TableWzAPI of main plugin)
  - Add SearchBar (copied from main plugin)
  - Add FileSaver (copied from main plugin)
Copy link
Contributor

github-actions bot commented Oct 2, 2024

Wazuh Check Updates plugin code coverage (Jest) test % values
Statements 76.44% ( 172 / 225 )
Branches 58.65% ( 61 / 104 )
Functions 61.7% ( 29 / 47 )
Lines 76.44% ( 172 / 225 )

Copy link
Contributor

github-actions bot commented Oct 2, 2024

Wazuh Core plugin code coverage (Jest) test % values
Statements 41.69% ( 710 / 1703 )
Branches 41.32% ( 417 / 1009 )
Functions 43.21% ( 239 / 553 )
Lines 42.05% ( 704 / 1674 )

Copy link
Contributor

github-actions bot commented Oct 2, 2024

Main plugin code coverage (Jest) test % values
Statements 13.44% ( 4024 / 29938 )
Branches 8.97% ( 1749 / 19494 )
Functions 13% ( 944 / 7260 )
Lines 13.61% ( 3922 / 28815 )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants