Skip to content

Commit

Permalink
chore(NA): avoids imports of server or public code into common (elast…
Browse files Browse the repository at this point in the history
…ic#67231) (elastic#68168)

* 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>

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Co-authored-by: Ryland Herrick <ryalnd@gmail.com>
  • Loading branch information
3 people authored Jun 3, 2020
1 parent 3b3647a commit cd79116
Show file tree
Hide file tree
Showing 20 changed files with 55 additions and 29 deletions.
5 changes: 5 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,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 @@ -8,6 +8,7 @@ import React, { useMemo } from 'react';
import { EuiFlexItem } from '@elastic/eui';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { WaffleSortControls } from '../../../../public/pages/metrics/inventory_view/components/waffle/waffle_sort_controls';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { ToolbarProps } from '../../../../public/pages/metrics/inventory_view/components/toolbars/toolbar';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { WaffleMetricControls } from '../../../../public/pages/metrics/inventory_view/components/waffle/metric_control';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { RENDER_AS, SORT_ORDER, SCALING_TYPES } from '../constants';
import { MapExtent, MapQuery } from './map_descriptor';
import { Filter, TimeRange } from '../../../../../src/plugins/data/public';
import { Filter, TimeRange } from '../../../../../src/plugins/data/common';

// Global map state passed to every layer.
export type MapFilters = {
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
18 changes: 9 additions & 9 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 @@ -29,7 +29,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 @@ -50,7 +50,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 @@ -79,7 +79,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 @@ -103,7 +103,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 @@ -129,7 +129,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 @@ -151,7 +151,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 @@ -174,7 +174,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 All @@ -197,7 +197,7 @@ describe('license features', function () {
});

it('should allow all basic features + audit logging for standard license', () => {
const mockRawLicense = licensingMock.createLicense({
const mockRawLicense = licenseMock.createLicense({
license: { mode: 'standard', type: 'standard' },
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { of } from 'rxjs';
import { licensingMock } from '../../../licensing/public/mocks';
import { licenseMock } from '../../../licensing/common/licensing.mock';
import { SpacesLicenseService } from './license_service';
import { LICENSE_TYPE, LicenseType } from '../../../licensing/common/types';

Expand All @@ -18,7 +18,7 @@ describe('license#isEnabled', function () {
});

it('should indicate that Spaces is disabled when xpack is unavailable', () => {
const rawLicenseMock = licensingMock.createLicenseMock();
const rawLicenseMock = licenseMock.createLicenseMock();
rawLicenseMock.isAvailable = false;
const serviceSetup = new SpacesLicenseService().setup({
license$: of(rawLicenseMock),
Expand All @@ -29,7 +29,7 @@ describe('license#isEnabled', function () {
for (const level in LICENSE_TYPE) {
if (isNaN(level as any)) {
it(`should indicate that Spaces is enabled with a ${level} license`, () => {
const rawLicense = licensingMock.createLicense({
const rawLicense = licenseMock.createLicense({
license: {
status: 'active',
type: level as LicenseType,
Expand Down

0 comments on commit cd79116

Please sign in to comment.