Added missing copyright header

This commit is contained in:
Jesús Ángel 2019-09-02 17:48:56 +02:00
parent 7f599a7974
commit 525b3614d2
35 changed files with 859 additions and 13 deletions

View File

@ -1,3 +1,14 @@
/*
* Wazuh app - React component for exporting the configuration of a group.
* Copyright (C) 2015-2019 Wazuh, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Find more information about this on the LICENSE file.
*/
import React, { Component } from 'react'; import React, { Component } from 'react';
import { import {

View File

@ -1,3 +1,14 @@
/*
* Wazuh app - React component for registering agents.
* Copyright (C) 2015-2019 Wazuh, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Find more information about this on the LICENSE file.
*/
import React, { Component, Fragment } from 'react'; import React, { Component, Fragment } from 'react';
import { import {

View File

@ -1,3 +1,16 @@
/*
* Wazuh app - React component for showing agent fields such as IP, ID, name,
* version, OS, registration date, last keep alive.
*
* Copyright (C) 2015-2019 Wazuh, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Find more information about this on the LICENSE file.
*/
import React, { Component } from 'react'; import React, { Component } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { EuiStat, EuiFlexItem, EuiFlexGroup, EuiPanel } from '@elastic/eui'; import { EuiStat, EuiFlexItem, EuiFlexGroup, EuiPanel } from '@elastic/eui';

View File

@ -1,3 +1,16 @@
/*
* Wazuh app - React component building the welcome screen of an agent.
* version, OS, registration date, last keep alive.
*
* Copyright (C) 2015-2019 Wazuh, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Find more information about this on the LICENSE file.
*/
import React, { Component } from 'react'; import React, { Component } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { import {

View File

@ -1,5 +1,5 @@
/* /*
* Wazuh app - File for app requirements and set up * Wazuh app - Load the Agent controllers and React components.
* Copyright (C) 2015-2019 Wazuh, Inc. * Copyright (C) 2015-2019 Wazuh, Inc.
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify

View File

@ -1,5 +1,5 @@
/* /*
* Wazuh app - File for app requirements and set up * Wazuh app - Load the Dev Tools controller.
* Copyright (C) 2015-2019 Wazuh, Inc. * Copyright (C) 2015-2019 Wazuh, Inc.
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify

View File

@ -1,5 +1,5 @@
/* /*
* Wazuh app - File for app requirements and set up * Wazuh app - Load all the controllers.
* Copyright (C) 2015-2019 Wazuh, Inc. * Copyright (C) 2015-2019 Wazuh, Inc.
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify

View File

@ -1,3 +1,15 @@
/*
* Wazuh app - React component for building the reports table.
*
* Copyright (C) 2015-2019 Wazuh, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Find more information about this on the LICENSE file.
*/
import React, { Component } from 'react'; import React, { Component } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { EuiBasicTable, EuiButtonIcon } from '@elastic/eui'; import { EuiBasicTable, EuiButtonIcon } from '@elastic/eui';

View File

@ -1,3 +1,15 @@
/*
* Wazuh app - React component for building the management welcome screen.
*
* Copyright (C) 2015-2019 Wazuh, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Find more information about this on the LICENSE file.
*/
import React, { Component } from 'react'; import React, { Component } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { import {

View File

@ -1,5 +1,5 @@
/* /*
* Wazuh app - File for app requirements and set up * Wazuh app - Load all the Management controllers and related React components.
* Copyright (C) 2015-2019 Wazuh, Inc. * Copyright (C) 2015-2019 Wazuh, Inc.
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify

View File

@ -1,5 +1,5 @@
/* /*
* Wazuh app - File for app requirements and set up * Wazuh app - Load all the Misc controllers.
* Copyright (C) 2015-2019 Wazuh, Inc. * Copyright (C) 2015-2019 Wazuh, Inc.
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify

View File

@ -1,3 +1,15 @@
/*
* Wazuh app - React component for alerts stats.
*
* Copyright (C) 2015-2019 Wazuh, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Find more information about this on the LICENSE file.
*/
import React, { Component } from 'react'; import React, { Component } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { EuiStat, EuiFlexItem, EuiFlexGroup } from '@elastic/eui'; import { EuiStat, EuiFlexItem, EuiFlexGroup } from '@elastic/eui';

View File

@ -1,3 +1,15 @@
/*
* Wazuh app - React component for building a card to be used for showing compliance requirements.
*
* Copyright (C) 2015-2019 Wazuh, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Find more information about this on the LICENSE file.
*/
import React, { Component } from 'react'; import React, { Component } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { import {

View File

@ -1,3 +1,15 @@
/*
* Wazuh app - React component for showing stats about agents.
*
* Copyright (C) 2015-2019 Wazuh, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Find more information about this on the LICENSE file.
*/
import React, { Component } from 'react'; import React, { Component } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { EuiStat, EuiFlexItem, EuiFlexGroup } from '@elastic/eui'; import { EuiStat, EuiFlexItem, EuiFlexGroup } from '@elastic/eui';

View File

@ -1,3 +1,15 @@
/*
* Wazuh app - React component for building the Overview welcome screen.
*
* Copyright (C) 2015-2019 Wazuh, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Find more information about this on the LICENSE file.
*/
import React, { Component } from 'react'; import React, { Component } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { import {

View File

@ -1,5 +1,5 @@
/* /*
* Wazuh app - File for app requirements and set up * Wazuh app - Load all the Overview controllers and related React components.
* Copyright (C) 2015-2019 Wazuh, Inc. * Copyright (C) 2015-2019 Wazuh, Inc.
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify

View File

@ -1,3 +1,15 @@
/*
* Wazuh app - React component for the adding an API entry form.
*
* Copyright (C) 2015-2019 Wazuh, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Find more information about this on the LICENSE file.
*/
import React, { Component } from 'react'; import React, { Component } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { import {

View File

@ -1,3 +1,15 @@
/*
* Wazuh app - React component building the API entries table.
*
* Copyright (C) 2015-2019 Wazuh, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Find more information about this on the LICENSE file.
*/
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import React, { Component } from 'react'; import React, { Component } from 'react';
import { RIGHT_ALIGNMENT } from '@elastic/eui/lib/services'; import { RIGHT_ALIGNMENT } from '@elastic/eui/lib/services';

View File

@ -1,5 +1,5 @@
/* /*
* Wazuh app - File for app requirements and set up * Wazuh app - Load the Settings React components.
* Copyright (C) 2015-2019 Wazuh, Inc. * Copyright (C) 2015-2019 Wazuh, Inc.
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify

View File

@ -1,5 +1,5 @@
/* /*
* Wazuh app - File for app requirements and set up * Wazuh app - Load all the directives.
* Copyright (C) 2015-2019 Wazuh, Inc. * Copyright (C) 2015-2019 Wazuh, Inc.
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify

View File

@ -1,3 +1,14 @@
/*
* Wazuh app - React base component for building tables.
* Copyright (C) 2015-2019 Wazuh, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Find more information about this on the LICENSE file.
*/
import React, { Component } from 'react'; import React, { Component } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { EuiBasicTable } from '@elastic/eui'; import { EuiBasicTable } from '@elastic/eui';

View File

@ -1,3 +1,14 @@
/*
* Wazuh app - React component for section tabs.
* Copyright (C) 2015-2019 Wazuh, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Find more information about this on the LICENSE file.
*/
import React, { Component, Fragment } from 'react'; import React, { Component, Fragment } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { EuiTabs, EuiTab } from '@elastic/eui'; import { EuiTabs, EuiTab } from '@elastic/eui';

View File

@ -1,5 +1,5 @@
/* /*
* Wazuh app - File for app requirements and set up * Wazuh app - Load all the Angular.js factories.
* Copyright (C) 2015-2019 Wazuh, Inc. * Copyright (C) 2015-2019 Wazuh, Inc.
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify

View File

@ -0,0 +1,73 @@
/*
* Author: Elasticsearch B.V.
* Updated by Wazuh, Inc.
*
* Copyright (C) 2015-2019 Wazuh, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Find more information about this on the LICENSE file.
*/
import _ from 'lodash';
import { uiModules } from 'ui/modules';
// Debounce service, angularized version of lodash debounce
// borrowed heavily from https://github.com/shahata/angular-debounce
const module = uiModules.get('app/wazuh');
module.service('debounce', [
'$timeout',
function($timeout) {
return function(func, wait, options) {
let timeout;
let args;
let self;
let result;
options = _.defaults(options || {}, {
leading: false,
trailing: true,
invokeApply: true
});
function debounce() {
self = this;
args = arguments;
const later = function() {
timeout = null;
if (!options.leading || options.trailing) {
result = func.apply(self, args);
}
};
const callNow = options.leading && !timeout;
if (timeout) {
$timeout.cancel(timeout);
}
timeout = $timeout(later, wait, options.invokeApply);
if (callNow) {
result = func.apply(self, args);
}
return result;
}
debounce.cancel = function() {
$timeout.cancel(timeout);
timeout = null;
};
return debounce;
};
}
]);
export function DebounceProvider(debounce) {
return debounce;
}

View File

@ -0,0 +1,46 @@
/*
* Author: Elasticsearch B.V.
* Updated by Wazuh, Inc.
*
* Copyright (C) 2015-2019 Wazuh, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Find more information about this on the LICENSE file.
*/
import { i18n } from '@kbn/i18n';
import { get } from 'lodash';
export function getPainlessError(error: Error) {
const rootCause: Array<{ lang: string; script: string }> | undefined = get(
error,
'resp.error.root_cause'
);
if (!rootCause) {
return;
}
const [{ lang, script }] = rootCause;
if (lang !== 'painless') {
return;
}
return {
lang,
script,
message: i18n.translate(
'kbn.discover.painlessError.painlessScriptedFieldErrorMessage',
{
defaultMessage: "Error with Painless scripted field '{script}'.",
values: { script }
}
),
error: error.message
};
}

View File

@ -159,7 +159,7 @@ export class EmbeddedVisualizeHandler {
timefilter.on('autoRefreshFetch', this.reload); timefilter.on('autoRefreshFetch', this.reload);
} }
// This is a hack to give maps visualizations access to data in the // This is a workaround to give maps visualizations access to data in the
// globalState, since they can no longer access it via searchSource. // globalState, since they can no longer access it via searchSource.
// TODO: Remove this as a part of elastic/kibana#30593 // TODO: Remove this as a part of elastic/kibana#30593
this.vis.API.getGeohashBounds = () => { this.vis.API.getGeohashBounds = () => {

View File

@ -0,0 +1,93 @@
/*
* Author: Elasticsearch B.V.
* Updated by Wazuh, Inc.
*
* Copyright (C) 2015-2019 Wazuh, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Find more information about this on the LICENSE file.
*/
import _ from 'lodash';
import { getPhraseScript } from '@kbn/es-query';
// Adds a filter to a passed state
export function getFilterGenerator(queryFilter) {
const filterGen = {};
filterGen.generate = (field, values, operation, index) => {
values = Array.isArray(values) ? values : [values];
const fieldName = _.isObject(field) ? field.name : field;
const filters = _.flatten([queryFilter.getAppFilters()]);
const newFilters = [];
const negate = (operation === '-');
// TODO: On array fields, negating does not negate the combination, rather all terms
_.each(values, function (value) {
let filter;
const existing = _.find(filters, function (filter) {
if (!filter) return;
if (fieldName === '_exists_' && filter.exists) {
return filter.exists.field === value;
}
if (_.has(filter, 'query.match')) {
return filter.query.match[fieldName] && filter.query.match[fieldName].query === value;
}
if (filter.script) {
return filter.meta.field === fieldName && filter.script.script.params.value === value;
}
});
if (existing) {
existing.meta.disabled = false;
if (existing.meta.negate !== negate) {
existing.meta.negate = !existing.meta.negate;
}
newFilters.push(existing);
return;
}
switch (fieldName) {
case '_exists_':
filter = {
meta: { negate, index },
exists: {
field: value
}
};
break;
default:
if (field.scripted) {
filter = {
meta: { negate, index, field: fieldName },
script: getPhraseScript(field, value)
};
} else {
filter = { meta: { negate, index }, query: { match: {} } };
filter.query.match[fieldName] = { query: value, type: 'phrase' };
}
break;
}
newFilters.push(filter);
});
return newFilters;
};
filterGen.add = function (field, values, operation, index) {
const newFilters = this.generate(field, values, operation, index);
return queryFilter.addFilters(newFilters);
};
return filterGen;
}

View File

@ -0,0 +1,200 @@
/*
* Author: Elasticsearch B.V.
* Updated by Wazuh, Inc.
*
* Copyright (C) 2015-2019 Wazuh, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Find more information about this on the LICENSE file.
*/
import { Filter, isFilterPinned, FilterStateStore } from '@kbn/es-query';
import _ from 'lodash';
import { Subject } from 'rxjs';
import { npSetup } from 'ui/new_platform';
// @ts-ignore
import { compareFilters } from 'plugins/data/filter/filter_manager/lib/compare_filters';
// @ts-ignore
import { mapAndFlattenFilters } from 'plugins/data/filter/filter_manager/lib/map_and_flatten_filters';
// @ts-ignore
import { uniqFilters } from 'plugins/data/filter/filter_manager/lib/uniq_filters';
// @ts-ignore
import { extractTimeFilter } from 'plugins/data/filter/filter_manager/lib/extract_time_filter';
// @ts-ignore
import { changeTimeFilter } from 'plugins/data/filter/filter_manager/lib/change_time_filter';
import { onlyDisabledFiltersChanged } from './only_disabled';
import { PartitionedFilters } from 'plugins/data/filter/filter_manager/partitioned_filters';
import { IndexPatterns } from 'plugins/data/index_patterns';
export class FilterManager {
private indexPatterns: IndexPatterns;
private filters: Filter[] = [];
private updated$: Subject<void> = new Subject();
private fetch$: Subject<void> = new Subject();
constructor(indexPatterns: IndexPatterns) {
this.indexPatterns = indexPatterns;
}
private mergeIncomingFilters(partitionedFilters: PartitionedFilters): Filter[] {
const globalFilters = partitionedFilters.globalFilters;
const appFilters = partitionedFilters.appFilters;
// existing globalFilters should be mutated by appFilters
_.each(appFilters, function (filter, i) {
const match = _.find(globalFilters, function (globalFilter) {
return compareFilters(globalFilter, filter);
});
// no match, do nothing
if (!match) return;
// matching filter in globalState, update global and remove from appState
_.assign(match.meta, filter.meta);
appFilters.splice(i, 1);
});
return FilterManager.mergeFilters(appFilters, globalFilters);
}
private static mergeFilters(appFilters: Filter[], globalFilters: Filter[]): Filter[] {
return uniqFilters(appFilters.reverse().concat(globalFilters.reverse())).reverse();
}
private static partitionFilters(filters: Filter[]): PartitionedFilters {
const [globalFilters, appFilters] = _.partition(filters, isFilterPinned);
return {
globalFilters,
appFilters,
};
}
private handleStateUpdate(newFilters: Filter[]) {
// global filters should always be first
newFilters.sort(({ $state: a }: Filter, { $state: b }: Filter): number => {
return a!.store === FilterStateStore.GLOBAL_STATE &&
b!.store !== FilterStateStore.GLOBAL_STATE
? -1
: 1;
});
const filtersUpdated = !_.isEqual(this.filters, newFilters);
const updatedOnlyDisabledFilters = onlyDisabledFiltersChanged(newFilters, this.filters);
this.filters = newFilters;
if (filtersUpdated) {
this.updated$.next();
if (!updatedOnlyDisabledFilters) {
this.fetch$.next();
}
}
}
/* Getters */
public getFilters() {
return _.cloneDeep(this.filters);
}
public getAppFilters() {
const { appFilters } = this.getPartitionedFilters();
return appFilters;
}
public getGlobalFilters() {
const { globalFilters } = this.getPartitionedFilters();
return globalFilters;
}
public getPartitionedFilters(): PartitionedFilters {
return FilterManager.partitionFilters(this.getFilters());
}
public getUpdates$() {
return this.updated$.asObservable();
}
public getFetches$() {
return this.fetch$.asObservable();
}
/* Setters */
public async addFilters(filters: Filter[] | Filter, pinFilterStatus?: boolean) {
if (!Array.isArray(filters)) {
filters = [filters];
}
if (filters.length === 0) {
return;
}
const { uiSettings } = npSetup.core;
if (pinFilterStatus === undefined) {
pinFilterStatus = uiSettings.get('filters:pinnedByDefault');
}
// Set the store of all filters. For now.
// In the future, all filters should come in with filter state store already set.
const store = pinFilterStatus ? FilterStateStore.GLOBAL_STATE : FilterStateStore.APP_STATE;
FilterManager.setFiltersStore(filters, store);
const mappedFilters = await mapAndFlattenFilters(this.indexPatterns, filters);
// This is where we add new filters to the correct place (app \ global)
const newPartitionedFilters = FilterManager.partitionFilters(mappedFilters);
const currentFilters = this.getPartitionedFilters();
currentFilters.appFilters.push(...newPartitionedFilters.appFilters);
currentFilters.globalFilters.push(...newPartitionedFilters.globalFilters);
const newFilters = this.mergeIncomingFilters(currentFilters);
this.handleStateUpdate(newFilters);
}
public async setFilters(newFilters: Filter[]) {
const mappedFilters = await mapAndFlattenFilters(this.indexPatterns, newFilters);
const newPartitionedFilters = FilterManager.partitionFilters(mappedFilters);
const mergedFilters = this.mergeIncomingFilters(newPartitionedFilters);
this.handleStateUpdate(mergedFilters);
}
public removeFilter(filter: Filter) {
const filterIndex = _.findIndex(this.filters, item => {
return _.isEqual(item.meta, filter.meta) && _.isEqual(item.query, filter.query);
});
if (filterIndex >= 0) {
const newFilters = _.cloneDeep(this.filters);
newFilters.splice(filterIndex, 1);
this.handleStateUpdate(newFilters);
}
}
public async removeAll() {
await this.setFilters([]);
}
public async addFiltersAndChangeTimeFilter(filters: Filter[]) {
const timeFilter = await extractTimeFilter(this.indexPatterns, filters);
if (timeFilter) changeTimeFilter(timeFilter);
return this.addFilters(filters.filter(filter => filter !== timeFilter));
}
public static setFiltersStore(filters: Filter[], store: FilterStateStore) {
_.map(filters, (filter: Filter) => {
// Override status only for filters that didn't have state in the first place.
if (filter.$state === undefined) {
filter.$state = { store };
}
});
}
}

View File

@ -0,0 +1,94 @@
/*
* Author: Elasticsearch B.V.
* Updated by Wazuh, Inc.
*
* Copyright (C) 2015-2019 Wazuh, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Find more information about this on the LICENSE file.
*/
import { FilterStateStore } from '@kbn/es-query';
import _ from 'lodash';
import { State } from 'ui/state_management/state';
import { FilterManager } from './filter-manager';
type GetAppStateFunc = () => State | undefined | null;
/**
* FilterStateManager is responsible for watching for filter changes
* and syncing with FilterManager, as well as syncing FilterManager changes
* back to the URL.
**/
export class FilterStateManager {
filterManager: FilterManager;
globalState: State;
getAppState: GetAppStateFunc;
interval: NodeJS.Timeout | undefined;
constructor(globalState: State, getAppState: GetAppStateFunc, filterManager: FilterManager) {
this.getAppState = getAppState;
this.globalState = globalState;
this.filterManager = filterManager;
this.watchFilterState();
this.filterManager.getUpdates$().subscribe(() => {
this.updateAppState();
});
}
destroy() {
if (this.interval) {
clearInterval(this.interval);
}
}
private watchFilterState() {
// This is a temporary solution to remove rootscope.
// Moving forward, state should provide observable subscriptions.
this.interval = setInterval(() => {
const appState = this.getAppState();
const stateUndefined = !appState || !this.globalState;
if (stateUndefined) return;
const globalFilters = this.globalState.filters || [];
const appFilters = (appState && appState.filters) || [];
const globalFilterChanged = !_.isEqual(this.filterManager.getGlobalFilters(), globalFilters);
const appFilterChanged = !_.isEqual(this.filterManager.getAppFilters(), appFilters);
const filterStateChanged = globalFilterChanged || appFilterChanged;
if (!filterStateChanged) return;
const newGlobalFilters = _.cloneDeep(globalFilters);
const newAppFilters = _.cloneDeep(appFilters);
FilterManager.setFiltersStore(newAppFilters, FilterStateStore.APP_STATE);
FilterManager.setFiltersStore(newGlobalFilters, FilterStateStore.GLOBAL_STATE);
this.filterManager.setFilters(newGlobalFilters.concat(newAppFilters));
}, 10);
}
private saveState() {
const appState = this.getAppState();
if (appState) appState.save();
this.globalState.save();
}
private updateAppState() {
// Update Angular state before saving State objects (which save it to URL)
const partitionedFilters = this.filterManager.getPartitionedFilters();
const appState = this.getAppState();
if (appState) {
appState.filters = partitionedFilters.appFilters;
}
this.globalState.filters = partitionedFilters.globalFilters;
this.saveState();
}
}

View File

@ -0,0 +1,31 @@
/*
* Author: Elasticsearch B.V.
* Updated by Wazuh, Inc.
*
* Copyright (C) 2015-2019 Wazuh, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Find more information about this on the LICENSE file.
*/
import _ from 'lodash';
import { Filter } from '@kbn/es-query';
const isEnabled = function(filter: Filter) {
return filter && filter.meta && !filter.meta.disabled;
};
/**
* Checks to see if only disabled filters have been changed
* @returns {bool} Only disabled filters
*/
export function onlyDisabledFiltersChanged(newFilters: Filter[], oldFilters: Filter[]) {
// If it's the same - compare only enabled filters
const newEnabledFilters = _.filter(newFilters, isEnabled);
const oldEnabledFilters = _.filter(oldFilters, isEnabled);
return _.isEqual(oldEnabledFilters, newEnabledFilters);
}

View File

@ -0,0 +1,44 @@
/*
* Author: Elasticsearch B.V.
* Updated by Wazuh, Inc.
*
* Copyright (C) 2015-2019 Wazuh, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Find more information about this on the LICENSE file.
*/
import { FilterStateManager } from './filter-state-manager';
import { DataPlugin } from './setup';
export function FilterBarQueryFilterProvider(getAppState, globalState) {
// TODO: this is imported here to avoid circular imports.
// eslint-disable-next-line @typescript-eslint/no-var-requires
const data = new DataPlugin().setup();
const filterManager = data.filter.filterManager;
const filterStateManager = new FilterStateManager(globalState, getAppState, filterManager);
const queryFilter = {};
queryFilter.getUpdates$ = filterManager.getUpdates$.bind(filterManager);
queryFilter.getFetches$ = filterManager.getFetches$.bind(filterManager);
queryFilter.getFilters = filterManager.getFilters.bind(filterManager);
queryFilter.getAppFilters = filterManager.getAppFilters.bind(filterManager);
queryFilter.getGlobalFilters = filterManager.getGlobalFilters.bind(filterManager);
queryFilter.removeFilter = filterManager.removeFilter.bind(filterManager);
queryFilter.addFilters = filterManager.addFilters.bind(filterManager);
queryFilter.setFilters = filterManager.setFilters.bind(filterManager);
queryFilter.addFiltersAndChangeTimeFilter = filterManager.addFiltersAndChangeTimeFilter.bind(filterManager);
queryFilter.removeAll = filterManager.removeAll.bind(filterManager);
queryFilter.destroy = () => {
filterManager.destroy();
filterStateManager.destroy();
};
return queryFilter;
}

View File

@ -0,0 +1,99 @@
/*
* Author: Elasticsearch B.V.
* Updated by Wazuh, Inc.
*
* Copyright (C) 2015-2019 Wazuh, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Find more information about this on the LICENSE file.
*/
// TODO these are imports from the old plugin world.
// Once the new platform is ready, they can get removed
// and handled by the platform itself in the setup method
// of the ExpressionExectorService
// @ts-ignore
import { renderersRegistry } from 'plugins/interpreter/registries';
import { ExpressionsService, ExpressionsSetup } from 'plugins/data/expressions';
import { QueryService, QuerySetup } from 'plugins/data/query';
import { FilterService, FilterSetup } from 'plugins/data/filter';
import { IndexPatternsService, IndexPatternsSetup } from 'plugins/data/index_patterns';
export class DataPlugin {
// Exposed services, sorted alphabetically
private readonly expressions: ExpressionsService;
private readonly filter: FilterService;
private readonly indexPatterns: IndexPatternsService;
private readonly query: QueryService;
constructor() {
this.indexPatterns = new IndexPatternsService();
this.filter = new FilterService();
this.query = new QueryService();
this.expressions = new ExpressionsService();
}
public setup(): DataSetup {
// TODO: this is imported here to avoid circular imports.
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { getInterpreter } = require('plugins/interpreter/interpreter');
const indexPatternsService = this.indexPatterns.setup();
return {
expressions: this.expressions.setup({
interpreter: {
getInterpreter,
renderersRegistry,
},
}),
indexPatterns: indexPatternsService,
filter: this.filter.setup({
indexPatterns: indexPatternsService.indexPatterns,
}),
query: this.query.setup(),
};
}
public stop() {
this.expressions.stop();
this.indexPatterns.stop();
this.filter.stop();
this.query.stop();
}
}
/** @public */
export interface DataSetup {
expressions: ExpressionsSetup;
indexPatterns: IndexPatternsSetup;
filter: FilterSetup;
query: QuerySetup;
}
/** @public types */
export { ExpressionRenderer, ExpressionRendererProps, ExpressionRunner } from 'plugins/data/expressions';
/** @public types */
export { IndexPattern, StaticIndexPattern, StaticIndexPatternField, Field } from 'plugins/data/index_patterns';
export { Query, QueryBar } from 'plugins/data/query';
export { FilterBar } from 'plugins/data/filter';
export {
FilterManager,
FilterStateManager,
uniqFilters,
onlyDisabledFiltersChanged,
} from './filter-manager';
/** @public static code */
export { dateHistogramInterval } from 'plugins/data/filter/../../common/date_histogram_interval';
/** @public static code */
export {
isValidEsInterval,
InvalidEsCalendarIntervalError,
InvalidEsIntervalFormatError,
parseEsInterval,
ParsedInterval,
} from 'plugins/data/filter/../../common/parse_es_interval';

View File

@ -1,5 +1,5 @@
/* /*
* Wazuh app - File for app requirements and set up * Wazuh app - Load all the Angular.js services.
* Copyright (C) 2015-2019 Wazuh, Inc. * Copyright (C) 2015-2019 Wazuh, Inc.
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify

View File

@ -1,5 +1,5 @@
/* /*
* Wazuh app - Makes null the region maps (temporary hack in order to make it work) * Wazuh app - Makes null the region maps (temporary fix in order to make it work)
* Copyright (C) 2015-2019 Wazuh, Inc. * Copyright (C) 2015-2019 Wazuh, Inc.
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify

View File

@ -1,5 +1,5 @@
/* /*
* Wazuh app - File for app requirements and set up * Wazuh app - Load all the "resolve" functions.
* Copyright (C) 2015-2019 Wazuh, Inc. * Copyright (C) 2015-2019 Wazuh, Inc.
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify