Skip to content

Commit

Permalink
[Backport 5485 to 4.5 7.16] Remove deprecated code and request in Man…
Browse files Browse the repository at this point in the history
…agement (#5549)

Remove deprecated code and request in Management (#5485)

* Remove deprecated code and request

* Add changelog

* Update snapshot

* remove: remove clusterStatus unused variable

* Remove clusterStatus property in groups-main.test.tsx

---------

Co-authored-by: Antonio David Gutiérrez <antonio.gutierrez@wazuh.com>
Co-authored-by: Federico Rodriguez <federico.rodriguez@wazuh.com>
(cherry picked from commit 1398452)
  • Loading branch information
yenienserrano authored Jun 13, 2023
1 parent 295eaf5 commit 2c316e9
Show file tree
Hide file tree
Showing 20 changed files with 27 additions and 155 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ All notable changes to the Wazuh app project will be documented in this file.
- Changed the title of step 3 of the deploy a new agent section. [#5429](https://github.com/wazuh/wazuh-kibana-app/pull/5429)
- Changed the description of step 3 of the deploy a new agent section. [#5429](https://github.com/wazuh/wazuh-kibana-app/pull/5429)
- Changed the placeholder of the agent name input of the deploy a new agent section. [#5429](https://github.com/wazuh/wazuh-kibana-app/pull/5429)
- Changed the query to search for an agent in `management/configuration`. [#5485](https://github.com/wazuh/wazuh-kibana-app/pull/5485)
- Changed the search bar in management/log to the one used in the rest of the app. [#5476](https://github.com/wazuh/wazuh-kibana-app/pull/5476)

### Fixed
Expand All @@ -47,6 +48,7 @@ All notable changes to the Wazuh app project will be documented in this file.
- Removed repeated and unnecessary requests in security section. [#5500](https://github.com/wazuh/wazuh-kibana-app/pull/5500)
- Removed pretty parameter from cron job requests. [#5532](https://github.com/wazuh/wazuh-kibana-app/pull/5532)
- Removed unnecessary requests in `Management/Status` section. [#5528](https://github.com/wazuh/wazuh-kibana-app/pull/5528)
- Removed obsolete code that caused duplicate requests to the api in `Management`. [#5485](https://github.com/wazuh/wazuh-kibana-app/pull/5485)

## Wazuh v4.4.3 - Kibana 7.10.2, 7.16.x, 7.17.x - Revision 01

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ function CDBListsTable(props) {
<UploadFilesButton
section={SECTION_CDBLIST_SECTION}
showingFiles={showingFiles}
clusterStatus={props.clusterStatus}
onSuccess={() => { updateRestartClusterManager && updateRestartClusterManager() }}
/>,
];
Expand Down Expand Up @@ -188,4 +187,4 @@ function CDBListsTable(props) {

export default compose(
withUserPermissions
)(CDBListsTable);
)(CDBListsTable);
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import WzReduxProvider from '../../../../../redux/wz-redux-provider';
import WzCDBListsOverview from './views/cdblists-overview';
import WzListEditor from './views/list-editor';

export default function WzCDBList({ clusterStatus }) {
export default function WzCDBList() {
const [listContent, setListContent] = useState(false);

return (
Expand All @@ -24,13 +24,11 @@ export default function WzCDBList({ clusterStatus }) {
(listContent && (
<WzListEditor
listContent={listContent}
clusterStatus={clusterStatus}
clearContent={() => { setListContent(false) }}
updateListContent={(listContent) => { setListContent(listContent) }}
/>
)) || (
<WzCDBListsOverview
clusterStatus={clusterStatus}
updateListContent={(listContent) => { setListContent(listContent) }}
/>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ function WzCDBListsOverview(props) {
setShowWarningRestart(showWarningRestart);
}

const { clusterStatus } = props;
return <EuiPage style={{ background: 'transparent' }}>
<EuiPanel>
{showWarningRestart && (
Expand All @@ -45,7 +44,6 @@ function WzCDBListsOverview(props) {
<EuiFlexItem>
<CDBListsTable
{...props}
clusterStatus={clusterStatus}
updateRestartClusterManager={(showWarningRestart) => updateRestartManagers(showWarningRestart)}
/>
</EuiFlexItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,6 @@ async function uploadFiles(files, resource, overwrite) {
}
}

const getReadPermissionsFiles = (section) => {
const { permissionResource } = resourceDictionary[section];
return [
{
action: `${section}:read`,
resource: permissionResource('*'),
},
];
};

const getUpdatePermissionsFiles = (section) => {
const { permissionResource } = resourceDictionary[section];
return [
Expand Down Expand Up @@ -125,7 +115,7 @@ export const AddNewCdbListButton = (({ section, updateListContent }) => {

// Manage files
export const ManageFiles = (({ section, showingFiles, ...props }) => {

/**
* Toggle between files and rules or decoders
*/
Expand Down Expand Up @@ -171,11 +161,10 @@ const uploadFile = async (files, resource, overwrite) => {
}
};

export const UploadFilesButton = (({ clusterStatus, section, showingFiles, onSuccess, ...props }) => {
export const UploadFilesButton = (({ section, showingFiles, onSuccess, ...props }) => {

return (
<UploadFiles
clusterStatus={clusterStatus}
resource={section}
path={`etc/${section}`}
upload={uploadFile}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,17 @@ class WzConfigurationSwitch extends Component {
try {
// try if it is a cluster
const clusterStatus = await clusterReq();
if (
const isCluster =
clusterStatus.data.data.enabled === 'yes' &&
clusterStatus.data.data.running === 'yes'
) {
clusterStatus.data.data.running === 'yes';
if (isCluster) {
const nodes = await clusterNodes();
// set cluster nodes in Redux Store
this.props.updateClusterNodes(nodes.data.data.affected_items);
// set cluster node selected in Redux Store
this.props.updateClusterNodeSelected(
nodes.data.data.affected_items.find((node) => node.type === 'master').name
nodes.data.data.affected_items.find(node => node.type === 'master')
.name,
);
} else {
// do nothing if it isn't a cluster
Expand All @@ -156,9 +157,7 @@ class WzConfigurationSwitch extends Component {
// If manager/cluster require agent platform info to filter sections in overview. It isn't coming from props for Management/Configuration
try {
this.setState({ loadingOverview: true });
const masterNodeInfo = await WzRequest.apiReq('GET', '/agents', {
params: { q: 'id=000' },
});
const masterNodeInfo = await WzRequest.apiReq('GET', '/agents?agents_list=000', {});
this.setState({
masterNodeInfo: masterNodeInfo.data.data.affected_items[0]
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ exports[`Ruleset component renders correctly to match the snapshot 1`] = `
}
>
<Component
clusterStatus=""
setShowingFiles={[Function]}
showingFiles={false}
updateAddingFile={[Function]}
updateFileContent={[Function]}
>
<Component
clusterStatus=""
setShowingFiles={[Function]}
showingFiles={false}
updateAddingFile={[Function]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
import apiSuggestsItems from './decoders-suggestions';

/***************************************
* Render tables
* Render tables
*/
const FilesTable = ({
actionButtons,
Expand Down Expand Up @@ -238,7 +238,6 @@ export default compose(
buttons.push(<UploadFilesButton
section={SECTION_DECODERS_SECTION}
showingFiles={showingFiles}
clusterStatus={props.clusterStatus}
onSuccess={() => { updateRestartClusterManager && updateRestartClusterManager() }}
/>);
return buttons;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import WzDecodersOverview from './views/decoders-overview';
import WzFileEditor from '../common/file-editor';
import { SECTION_DECODERS_SECTION } from '../common/constants';

export default function WzDecoder({ clusterStatus, logtestProps }) {
export default function WzDecoder({ logtestProps }) {

const [fileContent, setFileContent] = useState(false);
const [addingFile, setAddingFile] = useState(false);
Expand All @@ -36,13 +36,11 @@ export default function WzDecoder({ clusterStatus, logtestProps }) {
fileContent={fileContent}
addingFile={addingFile}
logtestProps={logtestProps}
clusterStatus={clusterStatus}
updateFileContent={(fileContent) => { setFileContent(fileContent) }}
cleanEditState={() => cleanEditState()}
/>
)) || (
<WzDecodersOverview
clusterStatus={clusterStatus}
updateFileContent={(fileContent) => { setFileContent(fileContent) }}
updateAddingFile={(addingFile) => { setAddingFile(addingFile) }}
setShowingFiles={() => { setShowingFiles(!showingFiles) }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ function WzDecodersOverview(props) {
const updateRestartManagers = (showWarningRestart) => {
setShowWarningRestart(showWarningRestart);
}


const { clusterStatus } = props;

return <EuiPage style={{ background: 'transparent' }}>
<EuiPanel>
{showWarningRestart && (
Expand All @@ -42,12 +41,11 @@ function WzDecodersOverview(props) {
<EuiSpacer size='s' />
</>
)}

<EuiFlexGroup>
<EuiFlexItem>
<DecodersTable
{...props}
clusterStatus={clusterStatus}
updateRestartClusterManager={(showWarningRestart) => updateRestartManagers(showWarningRestart)}
/>
</EuiFlexItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ exports[`Group main component renders correctly to match the snapshot 1`] = `
}
>
<Connect(WzGroups)
clusterStatus={
Object {
"contextConfigServer": "cluster",
"status": true,
}
}
configurationProps={
Object {
"agent": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jest.mock('../../../../../kibana-services', () => ({
getAngularModule: jest.fn(),
getHttp: () => ({
basePath: {
prepend: (str) => str,
prepend: str => str,
},
}),
}));
Expand Down Expand Up @@ -55,10 +55,6 @@ const mockProps = {
state: {
section: '',
},
clusterStatus: {
status: true,
contextConfigServer: 'cluster',
},
};
const mockStore = configureMockStore();
const store = mockStore({});
Expand All @@ -68,7 +64,7 @@ describe('Group main component', () => {
const wrapper = shallow(
<Provider store={store}>
<WzGroups {...mockProps} />
</Provider>
</Provider>,
);

expect(wrapper).toMatchSnapshot();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import WzReporting from './reporting/reporting-main';
import WzConfiguration from './configuration/configuration-main';
import WzStatistics from './statistics/statistics-main';
import { connect } from 'react-redux';
import { clusterReq } from './configuration/utils/wz-fetch';
import { updateClusterStatus } from '../../../../redux/actions/appStateActions';
import {
SECTION_CDBLIST_SECTION,
SECTION_DECODERS_SECTION,
Expand All @@ -46,33 +44,6 @@ class WzManagementMain extends Component {
store.dispatch(updateManagementSection(''));
}

componentDidMount() {
this.isClusterOrManager();
}

isClusterOrManager = async () => {
try {
const clusterStatus = await clusterReq();
if (clusterStatus.data.data.enabled === 'yes' && clusterStatus.data.data.running === 'yes') {
this.props.updateClusterStatus({
status: true,
contextConfigServer: 'cluster',
});
} else {
this.props.updateClusterStatus({
status: false,
contextConfigServer: 'manager',
});
}
} catch (error) {
console.warn(`Error when try to get cluster status`, error);
this.props.updateClusterStatus({
status: false,
contextConfigServer: 'manager',
});
}
};

render() {
const { section } = this.props;
return (
Expand All @@ -85,16 +56,13 @@ class WzManagementMain extends Component {
(section === 'configuration' && <WzConfiguration {...this.props.configurationProps} />) ||
(section === SECTION_DECODERS_SECTION && <WzDecoders
logtestProps={this.props.logtestProps}
clusterStatus={this.props.clusterStatus}
/>) ||
(section === SECTION_CDBLIST_SECTION && <WzCDBLists
logtestProps={this.props.logtestProps}
clusterStatus={this.props.clusterStatus}
/>) ||
(['ruleset', SECTION_RULES_SECTION].includes(section) && (
<WzRuleset
logtestProps={this.props.logtestProps}
clusterStatus={this.props.clusterStatus}
/>
))}
</Fragment>
Expand All @@ -105,14 +73,12 @@ class WzManagementMain extends Component {
function mapStateToProps(state) {
return {
state: state.managementReducers,
clusterStatus: state.appStateReducers.clusterStatus,
};
}

const mapDispatchToProps = (dispatch) => {
return {
updateManagementSection: (section) => dispatch(updateManagementSection(section)),
updateClusterStatus: (clusterStatus) => dispatch(updateClusterStatus(clusterStatus)),
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ exports[`Ruleset component renders correctly to match the snapshot 1`] = `
}
>
<Component
clusterStatus=""
setShowingFiles={[Function]}
showingFiles={false}
updateAddingFile={[Function]}
updateFileContent={[Function]}
>
<Component
clusterStatus=""
setShowingFiles={[Function]}
showingFiles={false}
updateAddingFile={[Function]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
import apiSuggestsItems from './ruleset-suggestions';

/***************************************
* Render tables
* Render tables
*/
const FilesTable = ({
actionButtons,
Expand Down Expand Up @@ -115,7 +115,7 @@ function RulesetTable({ setShowingFiles, showingFiles, ...props }) {
const [filters, setFilters] = useState([]);
const [isFlyoutVisible, setIsFlyoutVisible] = useState(false);
const [currentItem, setCurrentItem] = useState(null);

const [tableFootprint, setTableFootprint] = useState(0);

const resourcesHandler = new ResourcesHandler(ResourcesConstants.RULES);
Expand Down Expand Up @@ -248,7 +248,6 @@ function RulesetTable({ setShowingFiles, showingFiles, ...props }) {
buttons.push(<UploadFilesButton
section={SECTION_RULES_SECTION}
showingFiles={showingFiles}
clusterStatus={props.clusterStatus}
onSuccess={() => { updateRestartClusterManager && updateRestartClusterManager() }}
/>);
return buttons;
Expand Down Expand Up @@ -292,4 +291,4 @@ function RulesetTable({ setShowingFiles, showingFiles, ...props }) {

export default compose(
withUserPermissions
)(RulesetTable);
)(RulesetTable);
Loading

0 comments on commit 2c316e9

Please sign in to comment.