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

Move APIs from Elasticsearch index to the config.yml file. #1645

Closed
wants to merge 53 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
0e36f34
Fix bump
juankaromo Jul 8, 2019
b6da2be
API host in config.yml
juankaromo Jul 12, 2019
3afbe25
Fix includes https
adri9valle Jul 15, 2019
d7e6833
Fix when accessing to API data from config.yml
adri9valle Jul 16, 2019
d03b4d8
Fix when checking API connection
adri9valle Jul 16, 2019
7adf4bb
Check connection before setting default API
adri9valle Jul 16, 2019
86aea12
Created functions in order to prevent duplicated code
adri9valle Jul 16, 2019
ccf28fd
Fix when checking the stored API
adri9valle Jul 16, 2019
149a418
Fix when making API requests
adri9valle Jul 16, 2019
16c9237
Check API connection on the APIs load
adri9valle Jul 16, 2019
f6aa0ce
Fix filling star when selecting an API
adri9valle Jul 16, 2019
4dbc4da
Removed console.logs
adri9valle Jul 23, 2019
570a3cf
Fix when no API entries
adri9valle Jul 23, 2019
48c588a
Remove index pattern request in settings
adri9valle Jul 24, 2019
51a7676
Fix when checking APIs entries quietly
adri9valle Jul 24, 2019
6562b44
Resolving clonfics, TODO remove fake data
adri9valle Jul 24, 2019
64f15d0
Fix find api in settings-wizard
adri9valle Jul 24, 2019
92b563e
Change the way to check the form
adri9valle Jul 24, 2019
03ad682
Use props instead of state
adri9valle Jul 24, 2019
43f1a17
Set id in the front to the new API
adri9valle Jul 24, 2019
b53b647
Do not encrypt API password
adri9valle Jul 25, 2019
e06fc50
Migrate properly from index to config.yml
adri9valle Jul 25, 2019
bd53245
Fix when trying to get the index of the API in the array
adri9valle Jul 25, 2019
66495e7
Create a function to get the index of an API in the entries
adri9valle Jul 25, 2019
a09a4e7
Prevent add empty id or extensions to the cookies
adri9valle Jul 25, 2019
a9f33d2
Remove extension cookie associated with the API
adri9valle Jul 25, 2019
386109d
Remove fake data
adri9valle Jul 25, 2019
dc72e68
Fix when add a new API and lose credentials
adri9valle Jul 26, 2019
a7f7c75
Change the comparation type, strict by loose
adri9valle Jul 26, 2019
f94ff00
Check apis on renderization
adri9valle Jul 26, 2019
b7a2dbc
Fix APIs entries binding between angularjs and react
adri9valle Jul 26, 2019
fc9e99d
Fix when checking api while edition once
adri9valle Jul 26, 2019
b675bac
Fix when updating an API entry
adri9valle Jul 26, 2019
f86b818
Fix when there are several APIs to migrate in the .wazuh index
adri9valle Jul 29, 2019
5e6e4d6
Fix when checking if array is empty
adri9valle Jul 29, 2019
e1dad8d
Checks if all the APIs were migrated properly
adri9valle Jul 29, 2019
a6f7929
Remove .wazuh documents after migrate APIs
adri9valle Jul 29, 2019
99563d9
Check for duplicated API keys
adri9valle Jul 29, 2019
c24cef7
Change wazuh registry
adri9valle Jul 30, 2019
fec0d5a
Fix typo
adri9valle Jul 30, 2019
a9a65f7
Change wazuh-registry to server directory again
adri9valle Jul 30, 2019
93effbf
Create a service to manipulate the wazuh-registry.json
adri9valle Jul 30, 2019
2173008
Ignore wazuh-registry.json
adri9valle Jul 31, 2019
a500cdc
Update cluster information in the wazuh-registry
adri9valle Jul 31, 2019
5da40ad
Add several logs
adri9valle Jul 31, 2019
596bbbc
Remove the registry entry when an API is deleted
adri9valle Jul 31, 2019
c525de6
Read cluster info from registry
adri9valle Aug 1, 2019
2a57fda
Fill cluster info when API was added in the config.yml directly
adri9valle Aug 1, 2019
8d4ef47
Check when API is removed to delete its cookies
adri9valle Aug 2, 2019
66d0d9e
Remove console.log
adri9valle Aug 2, 2019
ab6ef8e
Clean registry hosts when deleting from config.yml
adri9valle Aug 2, 2019
f0658cf
Fix when change to an API without intenger id
adri9valle Aug 2, 2019
06e94dd
Resolving conflicts
adri9valle Aug 19, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,7 @@ package-lock.json

build/

yarn.lock
yarn.lock

# Wazuh version and cluster info registry
server/wazuh-registry.json
1 change: 0 additions & 1 deletion .yarnignore

This file was deleted.

6 changes: 6 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,9 @@
# Default value: info
# Allowed values: info, debug
logs.level: debug
wazuh.hosts:
- 1562642463569:
url: http://localhost
port: 55000
user: foo
password: bar
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "wazuh",
"version": "3.10.0",
"version": "3.9.0",
"revision": "0530",
"code": "0530-0",
"kibana": {
"version": "7.2.1"
"version": "7.2.0"
},
"description": "Wazuh app",
"main": "index.js",
Expand Down
99 changes: 83 additions & 16 deletions public/controllers/settings/components/api-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,71 @@ export class ApiTable extends Component {
apiEntries: [],
currentDefault: 0
};

this.editionEnabled = false;
}

componentDidMount() {
this.setState({
apiEntries: [...this.props.apiEntries],
currentDefault: this.props.currentDefault
});

async getHostsInconfig() {
try {
const result = await this.props.getApisInRegistry();
return result.data || [];
} catch (error) {
return Promise.reject(error)
}
}

/**
* Binds the cluster info to the API entries
*/
async bindClusterInfo() {
try {
if (this.editionEnabled) return;
const hosts = await this.getHostsInconfig();
await this.checkMissingApisInRegistry(angular.copy(hosts));
hosts.map(h => {
this.setApiEntryInfo(h, h);
});
this.props.digest();
} catch (error) {
this.props.handleError('Cannot get cluster information about API entries');
}
}

/**
* Set in the apiEntries the cluster information for each API
* @param {String} id
* @param {Object} info
*/
setApiEntryInfo(id, info) {
const idx = this.props.getSelectedApiIndex(id);
delete info.id;
this.props.apiEntries[idx].cluster_info = info;
}

/**
* Checks if in the wazuh-registry.json is missing any API entry of the config.yml in order to create it.
* @param {Object} registryHosts
*/
async checkMissingApisInRegistry(registryHosts) {
try {
const registryIds = registryHosts.map(h => {return h.id.toString()});
const entriesIds = this.props.apiEntries.map(e => {return e._id});
const diff = entriesIds.filter(api => !registryIds.includes(api));
if (!diff.length) return;
diff.map(async id => {
const api = await this.props.setHostRegistryInfo(id);
const info = api.data || {};
this.setApiEntryInfo(id, info);
});
} catch (error) {
this.props.handleError('Cannot update registry');
}
}

shouldComponentUpdate() {
this.bindClusterInfo();
return true;
}

onChangeEdit(e, field) {
Expand All @@ -46,6 +104,7 @@ export class ApiTable extends Component {
}

toggleDetails(item) {
this.editionEnabled = true;
const itemIdToExpandedRowMap = { ...this.state.itemIdToExpandedRowMap };
if (itemIdToExpandedRowMap[item._id]) {
delete itemIdToExpandedRowMap[item._id];
Expand Down Expand Up @@ -95,7 +154,10 @@ export class ApiTable extends Component {
onClick={() =>
this.props
.updateSettings({ ...this.state, _id: item._id }, true)
.then(result => result !== -1 && this.toggleDetails(item))
.then(result => {
result !== -1 && this.toggleDetails(item)
this.editionEnabled = false;
})
}
>
Save
Expand All @@ -117,30 +179,30 @@ export class ApiTable extends Component {

render() {
const { itemIdToExpandedRowMap } = this.state;
const items = [...this.state.apiEntries];
const items = [...this.props.apiEntries];
const columns = [
{
field: '_source.cluster_info.cluster',
field: 'cluster_info.cluster',
name: 'Cluster',
align: 'left'
},
{
field: '_source.cluster_info.manager',
field: 'cluster_info.manager',
name: 'Manager',
align: 'left'
},
{
field: '_source.url',
field: 'url',
name: 'Host',
align: 'left'
},
{
field: '_source.api_port',
field: 'api_port',
name: 'Port',
align: 'left'
},
{
field: '_source.api_user',
field: 'api_user',
name: 'User',
align: 'left'
},
Expand All @@ -152,13 +214,13 @@ export class ApiTable extends Component {
<EuiToolTip position="bottom" content={<p>Set as default</p>}>
<EuiButtonIcon
iconType={
item._id === this.state.currentDefault
item._id == this.props.currentDefault
? 'starFilled'
: 'starEmpty'
}
aria-label="Set as default"
onClick={() => {
const currentDefault = this.props.setDefault(item);
onClick={async () => {
const currentDefault = await this.props.setDefault(item);
this.setState({
currentDefault
});
Expand Down Expand Up @@ -251,6 +313,11 @@ ApiTable.propTypes = {
updateSettings: PropTypes.func,
setDefault: PropTypes.func,
checkManager: PropTypes.func,
getApisInRegistry: PropTypes.func,
getSelectedApiIndex: PropTypes.func,
digest: PropTypes.func,
removeManager: PropTypes.func,
switch: PropTypes.func
switch: PropTypes.func,
handleError: PropTypes.func,
setHostRegistryInfo: PropTypes.func,
};
Loading