Skip to content

Commit

Permalink
add eslint rule banning the core to import plugin code (elastic#51563) (
Browse files Browse the repository at this point in the history
elastic#51895)

* add eslint rule banning the core to import plugin code

* Ban importing legacy plugin code in the сore

* fix eslint errors

* core cannot import xpack rule

* regen docs
  • Loading branch information
mshustov authored Nov 29, 2019
1 parent 51947b0 commit 61f5787
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 13 deletions.
15 changes: 15 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,21 @@ module.exports = {
],
allowSameFolder: true,
},
{
target: ['src/core/**/*'],
from: ['x-pack/**/*'],
errorMessage: 'OSS cannot import x-pack files.',
},
{
target: ['src/core/**/*'],
from: [
'plugins/**/*',
'src/plugins/**/*',
'src/legacy/core_plugins/**/*',
'src/legacy/ui/**/*',
],
errorMessage: 'The core cannot depend on any plugins.',
},
{
from: ['src/legacy/ui/**/*', 'ui/**/*'],
target: [
Expand Down
1 change: 1 addition & 0 deletions src/core/public/saved_objects/saved_objects_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
import {
isAutoCreateIndexError,
showAutoCreateIndexErrorPage,
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
} from '../../../legacy/ui/public/error_auto_create_index/error_auto_create_index';
import { SimpleSavedObject } from './simple_saved_object';
import { HttpFetchOptions, HttpServiceBase } from '../http';
Expand Down
1 change: 1 addition & 0 deletions src/core/server/legacy/plugins/find_legacy_plugin_specs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
// @ts-ignore
} from '../../../../legacy/plugin_discovery/find_plugin_specs.js';
import { LoggerFactory } from '../../logging';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { collectUiExports as collectLegacyUiExports } from '../../../../legacy/ui/ui_exports/collect_ui_exports';
import { Config } from '../../config';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/

// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { esKuery } from '../../../../../plugins/data/server';

import { validateFilterKueryNode, validateConvertFilterToKueryNode } from './filter_utils';
Expand Down
1 change: 1 addition & 0 deletions src/core/server/saved_objects/service/lib/filter_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import { get, set } from 'lodash';
import { SavedObjectsErrorHelpers } from './errors';
import { IndexMapping } from '../../mappings';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { esKuery } from '../../../../../plugins/data/server';

export const validateConvertFilterToKueryNode = (
Expand Down
17 changes: 9 additions & 8 deletions src/core/server/saved_objects/service/lib/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import { omit } from 'lodash';
import { CallCluster } from 'src/legacy/core_plugins/elasticsearch';
import { APICaller } from '../../../elasticsearch/';

import { getRootPropertiesObjects, IndexMapping } from '../../mappings';
import { getSearchDsl } from './search_dsl';
Expand Down Expand Up @@ -77,12 +77,12 @@ export interface SavedObjectsRepositoryOptions {
index: string;
config: Config;
mappings: IndexMapping;
callCluster: CallCluster;
callCluster: APICaller;
schema: SavedObjectsSchema;
serializer: SavedObjectsSerializer;
migrator: KibanaMigrator;
allowedTypes: string[];
onBeforeWrite?: (...args: Parameters<CallCluster>) => Promise<void>;
onBeforeWrite?: (...args: Parameters<APICaller>) => Promise<void>;
}

export interface IncrementCounterOptions extends SavedObjectsBaseOptions {
Expand All @@ -100,8 +100,9 @@ export class SavedObjectsRepository {
private _mappings: IndexMapping;
private _schema: SavedObjectsSchema;
private _allowedTypes: string[];
private _onBeforeWrite: (...args: Parameters<CallCluster>) => Promise<void>;
private _unwrappedCallCluster: CallCluster;

private _onBeforeWrite: (...args: Parameters<APICaller>) => Promise<void>;
private _unwrappedCallCluster: APICaller;
private _serializer: SavedObjectsSerializer;

constructor(options: SavedObjectsRepositoryOptions) {
Expand Down Expand Up @@ -136,7 +137,7 @@ export class SavedObjectsRepository {

this._onBeforeWrite = onBeforeWrite;

this._unwrappedCallCluster = async (...args: Parameters<CallCluster>) => {
this._unwrappedCallCluster = async (...args: Parameters<APICaller>) => {
await migrator.runMigrations();
return callCluster(...args);
};
Expand Down Expand Up @@ -869,7 +870,7 @@ export class SavedObjectsRepository {
};
}

private async _writeToCluster(...args: Parameters<CallCluster>) {
private async _writeToCluster(...args: Parameters<APICaller>) {
try {
await this._onBeforeWrite(...args);
return await this._callCluster(...args);
Expand All @@ -878,7 +879,7 @@ export class SavedObjectsRepository {
}
}

private async _callCluster(...args: Parameters<CallCluster>) {
private async _callCluster(...args: Parameters<APICaller>) {
try {
return await this._unwrappedCallCluster(...args);
} catch (err) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { esKuery } from '../../../../../../plugins/data/server';

import { getRootPropertiesObjects, IndexMapping } from '../../../mappings';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { IndexMapping } from '../../../mappings';
import { SavedObjectsSchema } from '../../../schema';
import { getQueryParams } from './query_params';
import { getSortingParams } from './sorting_params';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { esKuery } from '../../../../../../plugins/data/server';

interface GetSearchDslOptions {
Expand Down
1 change: 0 additions & 1 deletion src/core/server/server.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import Boom from 'boom';
import { BulkIndexDocumentsParams } from 'elasticsearch';
import { CallCluster } from 'src/legacy/core_plugins/elasticsearch';
import { CatAliasesParams } from 'elasticsearch';
import { CatAllocationParams } from 'elasticsearch';
import { CatCommonParams } from 'elasticsearch';
Expand Down
6 changes: 3 additions & 3 deletions src/core/server/ui_settings/integration_tests/lib/servers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
TestKibanaUtils,
TestUtils,
} from '../../../../../test_utils/kbn_server';
import { CallCluster } from '../../../../../legacy/core_plugins/elasticsearch';
import { APICaller } from '../../../elasticsearch/';

let servers: TestUtils;
let esServer: TestElasticsearchUtils;
Expand All @@ -36,7 +36,7 @@ let kbnServer: TestKibanaUtils['kbnServer'];
interface AllServices {
kbnServer: TestKibanaUtils['kbnServer'];
savedObjectsClient: SavedObjectsClientContract;
callCluster: CallCluster;
callCluster: APICaller;
uiSettings: IUiSettingsClient;
deleteKibanaIndex: typeof deleteKibanaIndex;
}
Expand All @@ -61,7 +61,7 @@ export async function startServers() {
kbnServer = kbn.kbnServer;
}

async function deleteKibanaIndex(callCluster: CallCluster) {
async function deleteKibanaIndex(callCluster: APICaller) {
const kibanaIndices = await callCluster('cat.indices', { index: '.kibana*', format: 'json' });
const indexNames = kibanaIndices.map((x: any) => x.index);
if (!indexNames.length) {
Expand Down

0 comments on commit 61f5787

Please sign in to comment.