Skip to content

Commit

Permalink
[7.8] chore(NA): avoids imports of server or public code into common (#…
Browse files Browse the repository at this point in the history
…67231) (#68175)

* chore(NA): avoids imports of server or public code into common (#67231)

* chore(NA): avoids imports of server or public code into common

* chore(NA): fix imports from public or server into common

* chore(NA): fix typechecking for data plugin stubs

* chore(NA): fix types and tests related with licensing plugin

* chore(NA): fix problems on infra plugin

* chore(NA): fix typo on .eslintrc.js

Co-authored-by: Ryland Herrick <ryalnd@gmail.com>

* chore(NA): migrate to license mock usage on security plugin licensing module

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Co-authored-by: Ryland Herrick <ryalnd@gmail.com>
# Conflicts:
#	x-pack/plugins/infra/common/inventory_models/shared/components/metrics_and_groupby_toolbar_items.tsx
#	x-pack/plugins/maps/common/descriptor_types/data_request_descriptor_types.d.ts
#	x-pack/plugins/security/common/licensing/license_service.test.ts
#	x-pack/plugins/spaces/common/licensing/license_service.test.ts

* chore(NA): fix eslint problems
  • Loading branch information
mistic authored Jun 3, 2020
1 parent c96408d commit 289e1c8
Show file tree
Hide file tree
Showing 17 changed files with 49 additions and 24 deletions.
5 changes: 5 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ module.exports = {
from: ['(src|x-pack)/plugins/*/server/**/*'],
errorMessage: `Public code can not import from server, use a common directory.`,
},
{
target: ['(src|x-pack)/plugins/*/common/**/*'],
from: ['(src|x-pack)/plugins/*/(server|public)/**/*'],
errorMessage: `Common code can not import from server or public, use a common directory.`,
},
{
target: [
'(src|x-pack)/legacy/**/*',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import { buildFilter, FilterStateStore, FILTERS } from '.';
import { stubIndexPattern, stubFields } from '../../../public/stubs';
import { stubIndexPattern, stubFields } from '../../../common/stubs';

describe('buildFilter', () => {
it('should build phrase filters', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { stubIndexPattern, phraseFilter } from 'src/plugins/data/public/stubs';
import { stubIndexPattern, phraseFilter } from 'src/plugins/data/common/stubs';
import { getIndexPatternFromFilter } from './get_index_pattern_from_filter';

describe('getIndexPatternFromFilter', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/common/es_query/kuery/ast/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { IIndexPattern } from '../../../index_patterns/types';

// @ts-ignore
import { parse as parseKuery } from './_generated_/kuery';
import { JsonObject } from '../../../../../kibana_utils/public';
import { JsonObject } from '../../../../../kibana_utils/common';

const fromExpression = (
expression: string | DslQuery,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import _ from 'lodash';
import * as ast from '../ast';
import { nodeTypes } from '../node_types';
import { NamedArgTypeBuildNode } from './types';
import { JsonObject } from '../../../../../kibana_utils/public';
import { JsonObject } from '../../../../../kibana_utils/common';

export function buildNode(name: string, value: any): NamedArgTypeBuildNode {
const argumentNode =
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/common/es_query/kuery/node_types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/

import { IIndexPattern } from '../../../index_patterns';
import { JsonValue } from '../../../../../kibana_utils/public';
import { JsonValue } from '../../../../../kibana_utils/common';
import { KueryNode } from '..';

export type FunctionName =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { IFieldType } from '../../../../plugins/data/public';
import { IFieldType } from '.';

export const stubFields: IFieldType[] = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { IIndexPattern } from '../../common';
import { IIndexPattern } from '.';
import { stubFields } from './field.stub';

export const stubIndexPattern: IIndexPattern = {
Expand Down
22 changes: 22 additions & 0 deletions src/plugins/data/common/stubs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export { stubIndexPattern, stubIndexPatternWithFields } from './index_patterns/index_pattern.stub';
export { stubFields } from './index_patterns/field.stub';
export * from './es_query/filters/stubs';
4 changes: 1 addition & 3 deletions src/plugins/data/public/stubs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,4 @@
* under the License.
*/

export { stubIndexPattern, stubIndexPatternWithFields } from './index_patterns/index_pattern.stub';
export { stubFields } from './index_patterns/field.stub';
export * from '../common/es_query/filters/stubs';
export * from '../common/stubs';
2 changes: 1 addition & 1 deletion src/plugins/expressions/common/ast/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import { ExpressionValue, ExpressionValueError } from '../expression_types';
import { ExpressionFunction } from '../../public';
import { ExpressionFunction } from '../../common';

export type ExpressionAstNode =
| ExpressionAstExpression
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/expressions/common/execution/execution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import { Execution } from './execution';
import { parseExpression, ExpressionAstExpression } from '../ast';
import { createUnitTestExecutor } from '../test_helpers';
import { ExpressionFunctionDefinition } from '../../public';
import { ExpressionFunctionDefinition } from '../../common';
import { ExecutionContract } from './execution_contract';

beforeAll(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/expressions/common/util/create_error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { ExpressionValueError } from '../../public';
import { ExpressionValueError } from '../../common';

type ErrorLike = Partial<Pick<Error, 'name' | 'message' | 'stack'>>;

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/apm/common/service_map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { i18n } from '@kbn/i18n';
import cytoscape from 'cytoscape';
import { ILicense } from '../../licensing/public';
import { ILicense } from '../../licensing/common/types';
import {
AGENT_NAME,
SERVICE_ENVIRONMENT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
/* eslint-disable @typescript-eslint/consistent-type-definitions */

import { Query } from '../../../../../src/plugins/data/public';
import { Query } from '../../../../../src/plugins/data/common';
import { DRAW_TYPE, ES_GEO_FIELD_TYPE, ES_SPATIAL_RELATIONS } from '../constants';

export type MapExtent = {
Expand Down
16 changes: 8 additions & 8 deletions x-pack/plugins/security/common/licensing/license_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { of, BehaviorSubject } from 'rxjs';
import { licensingMock } from '../../../licensing/public/mocks';
import { licenseMock } from '../../../licensing/common/licensing.mock';
import { SecurityLicenseService } from './license_service';

describe('license features', function () {
Expand All @@ -28,7 +28,7 @@ describe('license features', function () {
});

it('should display error when X-Pack is unavailable', () => {
const rawLicenseMock = licensingMock.createLicenseMock();
const rawLicenseMock = licenseMock.createLicenseMock();
rawLicenseMock.isAvailable = false;
const serviceSetup = new SecurityLicenseService().setup({
license$: of(rawLicenseMock),
Expand All @@ -48,7 +48,7 @@ describe('license features', function () {
});

it('should notify consumers of licensed feature changes', () => {
const rawLicenseMock = licensingMock.createLicenseMock();
const rawLicenseMock = licenseMock.createLicenseMock();
rawLicenseMock.isAvailable = false;
const rawLicense$ = new BehaviorSubject(rawLicenseMock);
const serviceSetup = new SecurityLicenseService().setup({
Expand Down Expand Up @@ -76,7 +76,7 @@ describe('license features', function () {
]
`);

rawLicense$.next(licensingMock.createLicenseMock());
rawLicense$.next(licenseMock.createLicenseMock());
expect(subscriptionHandler).toHaveBeenCalledTimes(2);
expect(subscriptionHandler.mock.calls[1]).toMatchInlineSnapshot(`
Array [
Expand All @@ -99,7 +99,7 @@ describe('license features', function () {
});

it('should show login page and other security elements, allow RBAC but forbid paid features if license is basic.', () => {
const mockRawLicense = licensingMock.createLicense({
const mockRawLicense = licenseMock.createLicense({
features: { security: { isEnabled: true, isAvailable: true } },
});

Expand All @@ -124,7 +124,7 @@ describe('license features', function () {
});

it('should not show login page or other security elements if security is disabled in Elasticsearch.', () => {
const mockRawLicense = licensingMock.createLicense({
const mockRawLicense = licenseMock.createLicense({
features: { security: { isEnabled: false, isAvailable: true } },
});

Expand All @@ -145,7 +145,7 @@ describe('license features', function () {
});

it('should allow role mappings, access agreement and sub-feature privileges, but not DLS/FLS if license = gold', () => {
const mockRawLicense = licensingMock.createLicense({
const mockRawLicense = licenseMock.createLicense({
license: { mode: 'gold', type: 'gold' },
features: { security: { isEnabled: true, isAvailable: true } },
});
Expand All @@ -167,7 +167,7 @@ describe('license features', function () {
});

it('should allow to login, allow RBAC, role mappings, access agreement, sub-feature privileges, and DLS if license >= platinum', () => {
const mockRawLicense = licensingMock.createLicense({
const mockRawLicense = licenseMock.createLicense({
license: { mode: 'platinum', type: 'platinum' },
features: { security: { isEnabled: true, isAvailable: true } },
});
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/siem/common/typed_json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { JsonObject } from '../../../../src/plugins/kibana_utils/public';
import { JsonObject } from '../../../../src/plugins/kibana_utils/common';

export type ESQuery = ESRangeQuery | ESQueryStringQuery | ESMatchQuery | ESTermQuery | JsonObject;

Expand Down

0 comments on commit 289e1c8

Please sign in to comment.