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

Pinned agent management refactor #6644

Closed
5 tasks done
Tracked by #6120
jbiset opened this issue May 7, 2024 · 6 comments · Fixed by #6663
Closed
5 tasks done
Tracked by #6120

Pinned agent management refactor #6644

jbiset opened this issue May 7, 2024 · 6 comments · Fixed by #6663
Assignees
Labels
level/subtask Subtask issue type/enhancement Enhancement issue

Comments

@jbiset
Copy link
Member

jbiset commented May 7, 2024

Description

A service needs to be created to manage the pinned agent that replaces the current mechanism. This service should update the application state and URL with respect to the pinned agent. Additionally, this service must provide the methods to get whether an agent is pinned, get pinned agent data, and pin an agent.
Finally, the corresponding behavior must be added to DataSource to update the filters when changing the pinned agent through the pinned agent management service.

Parent issue

Related issue

Tasks

The steps that have to be completed in order to close the issue.

  • Create a new service to manage the pinned agent
  • Add the corresponding behavior to the DataSource to update the filters when changing the pinned agent through the pinned agent management service.
  • Migrate WzAgentSelector to a functional component
  • Replace where appropriate the interaction with the pinned agent.
  • Fix error when I have an agent selected and environment change (Related with Console error when I have an agent selected and environment change #5745 )
@jbiset jbiset added type/enhancement Enhancement issue level/task Task issue labels May 7, 2024
@jbiset jbiset self-assigned this May 7, 2024
@wazuhci wazuhci moved this to In progress in Release 4.9.0 May 7, 2024
@asteriscos asteriscos mentioned this issue May 7, 2024
74 tasks
@asteriscos asteriscos added level/subtask Subtask issue and removed level/task Task issue labels May 7, 2024
@jbiset
Copy link
Member Author

jbiset commented May 7, 2024

Update 07/05/2024

Research

Principal files:

  • plugins/main/public/components/wz-agent-selector/wz-agent-selector-wrapper.js
  • plugins/main/public/components/wz-agent-selector/wz-agent-selector.js

Related files:

  • plugins/main/public/components/agents/prompts/prompt_module_not_for_agent.tsx
  • plugins/main/public/components/common/welcome/agents-welcome.js
  • plugins/main/public/components/overview/vulnerabilities/common/vulnerability_detector_adapters.tsx
  • plugins/main/public/components/wz-menu/wz-menu.js
  • plugins/main/public/controllers/overview/components/overview-actions/overview-actions.js

WzAgentSelector component
This component renders a modal with a list of agents to pin an agent or unpin it. It is located at the root of the application in the app template. Its rendering depends on the showExploreAgentModalGlobal value saved in the application store.

  • componentDidMount => Provides access to route and location through the Angular module. This is necessary to be able to update the URL in the other methods.
  • closeAgentModal => Trigger showExploreAgentModalGlobal in the store to close the agent selection modal.
  • agentTableSearch(agentIdList) => Given a list of agents agentIdList, updates the URL based on the first element in that list, also taking into account whether this is done from an agent page ("/agents"). This also updates the filterManager according to the current index pattern. Finally, it also closes the agent selection modal.
  • removeAgentsFilter => Updates the URL by deleting the selected agent and removes the pinned agent from the filterManager. It also calls the method to close the modal.
  • getSelectedAgents => This method returns the data of the pinned agent, if there is a pinned agent.

To update the state of the pinned agent it is necessary to use the updateCurrentAgentData action of the reducer with the action type UPDATE_SELECTED_AGENT_DATA.
To update the state to show or not the modal it is necessary to use the showExploreAgentModalGlobal action of the reducer with the action type SHOW_EXPLORE_AGENT_MODAL_GLOBAL.

The initial state of appStateReducers is as follows:

const initialState = {
  ...
  currentAgentData: JSON.parse(
    window.sessionStorage.getItem('wz-shared-selected-agent') || '{}',
  ),
  ...
};

With which, currentAgentData can be initialized with the wz-shared-selected-agent key of the sessionStorage.

It is proposed to begin implementing the PinnedAgentManager class that provides the following methods:

export class PinnedAgentManager {
  public static NO_AGENT_DATA = {};
  private store: any;

  constructor(inputStore: any) {
    this.store = inputStore ?? store;
  }

  pinAgent(agentData: any): void

  unPinAgent(): void 

  isPinnedAgent(): boolean 

  getPinnedAgent(): any
}

@jbiset
Copy link
Member Author

jbiset commented May 8, 2024

Update 08/05/2024

Added the corresponding behavior to the DataSource to update the filters when changing the pinned agent through the pinned agent management service.
It starts with replacing the pinned agent management in the main and related files:

Principal files:

  • plugins/main/public/components/wz-agent-selector/wz-agent-selector-wrapper.js
  • plugins/main/public/components/wz-agent-selector/wz-agent-selector.js

Related files:

  • plugins/main/public/controllers/overview/components/overview-actions/agents-selection-table.js
  • plugins/main/public/components/agents/prompts/prompt_module_not_for_agent.tsx
  • plugins/main/public/components/common/welcome/agents-welcome.js
  • plugins/main/public/components/overview/vulnerabilities/common/vulnerability_detector_adapters.tsx
  • plugins/main/public/components/wz-menu/wz-menu.js
  • plugins/main/public/controllers/overview/components/overview-actions/overview-actions.js

@jbiset
Copy link
Member Author

jbiset commented May 9, 2024

Update 09/05/2024

Progress is made with the replacement of the administration of the pinned agent.

The list of files that interact with this functionality is renewed:

Places where the status of the pinned agent was updated:

  • plugins/main/public/controllers/overview/components/overview-actions/agents-selection-table.js
  • plugins/main/public/components/overview/overview.tsx
  • plugins/main/public/components/wz-agent-selector/wz-agent-selector.js
  • plugins/main/public/controllers/overview/components/overview-actions/overview-actions.js
  • plugins/main/public/components/common/welcome/agents-welcome.js
  • plugins/main/public/components/endpoints-summary/agent/index.tsx
  • plugins/main/public/services/common-data.js

Related files that use props.agent which depends on the store's currentAgentData value:

  • plugins/main/public/components/common/modules/main.tsx
  • plugins/main/public/components/common/modules/main-agent.tsx
  • plugins/main/public/components/common/modules/main-overview.tsx

It would be desirable to change the currentAgentData in the different files so that it does not depend on the store directly but on PinnedAgentManager:

  • plugins/main/public/components/agents/fim/main.tsx
  • plugins/main/public/components/agents/sca/main.tsx
  • plugins/main/public/components/agents/vuls/main.tsx
  • plugins/main/public/components/common/hocs/with_module_not_for_agent.tsx
  • plugins/main/public/components/common/hocs/withAgentSupportModule.tsx
  • plugins/main/public/components/common/modules/main-agent.tsx
  • plugins/main/public/components/common/modules/main-overview.tsx
  • plugins/main/public/components/common/modules/overview-current-section.tsx
  • plugins/main/public/components/common/modules/discover/discover.tsx
  • plugins/main/public/components/common/modules/panel/components/module_configuration.tsx
  • plugins/main/public/components/common/welcome/agents-welcome.js
  • plugins/main/public/components/common/welcome/components/menu-agent.js
  • plugins/main/public/components/overview/compliance-table/components/requirement-flyout/requirement-flyout.tsx
  • plugins/main/public/components/overview/mitre/framework/components/techniques/components/flyout-technique/flyout-technique.tsx
  • plugins/main/public/utils/applications.ts

@jbiset
Copy link
Member Author

jbiset commented May 10, 2024

Update 10/05/2024

  • Migrated WzAgentSelector to a functional component
  • Replaced where appropriate the interaction with the pinned agent.
  • Fixed error when I have an agent selected and environment change. Functionality is added so that when the API is changed, the pinned agent is unpinned, if a pinned agent exists.
  • ShareAgent is a class that is not currently associated with deprecated functionality. With which it is proposed to remove this class. This also involves removing the checkLocationAgentId method from common-data.
  • It was decided to eliminate plugins/main/public/components/visualize/visualize-top-menu.js which, although it had interaction with the functionality of pinning an agent, is a component that is not used.

TO DO:

Check if the currentAgentData was left unchanged in the following files so that it does not depend directly on the store but on the methods of the PinnedAgentManager

  • plugins/main/public/components/agents/fim/main.tsx
  • plugins/main/public/components/agents/sca/main.tsx
  • plugins/main/public/components/agents/vuls/main.tsx
  • plugins/main/public/components/common/hocs/with_module_not_for_agent.tsx
  • plugins/main/public/components/common/hocs/withAgentSupportModule.tsx
  • plugins/main/public/components/common/modules/main-agent.tsx
  • plugins/main/public/components/common/modules/main-overview.tsx
  • plugins/main/public/components/common/modules/overview-current-section.tsx
  • plugins/main/public/components/common/modules/discover/discover.tsx
  • plugins/main/public/components/common/modules/panel/components/module_configuration.tsx
  • plugins/main/public/components/common/welcome/agents-welcome.js
  • plugins/main/public/components/common/welcome/components/menu-agent.js
  • plugins/main/public/components/overview/compliance-table/components/requirement-flyout/requirement-flyout.tsx
  • plugins/main/public/components/overview/mitre/framework/components/techniques/components/flyout-technique/flyout-technique.tsx
  • plugins/main/public/utils/applications.ts

Generate PR with tests of the different use cases when an agent is pinned. Among them:

  • Pin an agent and check that it updates the store, URL and filters.
  • Unpin an agent and check that the store, URL and filters are updated.
  • Without having a pinned agent, change the URL by adding &agentId=XXX, where XXX is the id of an existing agent, and check that it adds the pinned agent. This is useful when passing a pinned agent URL.

@jbiset jbiset linked a pull request May 13, 2024 that will close this issue
6 tasks
@wazuhci wazuhci moved this from In progress to Blocked in Release 4.9.0 May 13, 2024
@wazuhci wazuhci moved this from Blocked to In progress in Release 4.9.0 May 14, 2024
@wazuhci wazuhci moved this from In progress to Pending review in Release 4.9.0 May 14, 2024
@jbiset
Copy link
Member Author

jbiset commented May 14, 2024

Update 14/05/2024

  • The use of the redux updateCurrentAgentData action is eliminated in all components. In some cases because it is no longer necessary and in others it is replaced by the pinAgent method of the PinnedAgentManager.
  • Corner cases specified in the reviews are resolved.
  • Corner case is analyzed when the query param &agentId=asdjfkdsa or &agentId=undefined is entered in the URL. In previous versions this case also generates an error.

Error when entering the query param &agentId=asdjfkdsa or &agentId=undefined in previous versions in the URL
image

In the version of the branch of this Issue, in the module screens the query params &agentId=asdjfkdsa or &agentId=undefined generates a loop in the rendering. While in agent view it removes the URL parameter and no pinned agent appears, accepted behavior.
It would be necessary to analyze this difference between overview and agent view to determine if it can be solved.

@wazuhci wazuhci moved this from Pending review to On hold in Release 4.9.0 May 15, 2024
@wazuhci wazuhci moved this from On hold to In progress in Release 4.9.0 May 15, 2024
@wazuhci wazuhci moved this from In progress to Pending review in Release 4.9.0 May 15, 2024
@jbiset
Copy link
Member Author

jbiset commented May 15, 2024

Update 15/05/2024

  • Fixed loop when wrong value is entered in agentId in URL and changed setIsLoadingAgent in agent view of Endpoints summary
  • Fixed change the agent id in the URL
  • Fixed removal of unset filters when pinning an agent

@wazuhci wazuhci moved this from Pending review to Done in Release 4.9.0 May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
level/subtask Subtask issue type/enhancement Enhancement issue
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants