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

Prevents importing of public code into server #67149

Merged
merged 13 commits into from
Jun 10, 2020
9 changes: 6 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,12 @@ module.exports = {
errorMessage: `Plugins may only import from src/core/server and src/core/public.`,
},
{
target: ['(src|x-pack)/plugins/*/public/**/*'],
from: ['(src|x-pack)/plugins/*/server/**/*'],
errorMessage: `Public code can not import from server, use a common directory.`,
target: [
'(src|x-pack)/plugins/*/server/**/*',
'!x-pack/plugins/apm/**/*', // https://github.com/elastic/kibana/issues/67210
],
from: ['(src|x-pack)/plugins/*/public/**/*'],
errorMessage: `Server code can not import from public, use a common directory.`,
},
{
target: ['(src|x-pack)/plugins/*/common/**/*'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ export function getCurrentMethodAndTokenPaths(
}

// eslint-disable-next-line
export default function({ coreEditor: editor, parser }: { coreEditor: CoreEditor; parser: any }) {
export default function ({ coreEditor: editor, parser }: { coreEditor: CoreEditor; parser: any }) {
function isUrlPathToken(token: Token | null) {
switch ((token || ({} as any)).type) {
case 'url.slash':
Expand Down
20 changes: 20 additions & 0 deletions src/plugins/es_ui_shared/common/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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 { Privileges, MissingPrivileges } from '../__packages_do_not_import__/authorization';
12 changes: 11 additions & 1 deletion src/plugins/es_ui_shared/public/authorization/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,14 @@
* under the License.
*/

export * from '../../__packages_do_not_import__/authorization';
export {
AuthorizationContext,
AuthorizationProvider,
Error,
MissingPrivileges,
NotAuthorizedSection,
Privileges,
SectionError,
useAuthorizationContext,
WithPrivileges,
} from '../../__packages_do_not_import__/authorization';
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import { savedObjectsRepositoryMock } from '../../../../core/server/mocks';
import { storeReport } from './store_report';
import { ReportSchemaType } from './schema';
import { METRIC_TYPE } from '../../public';
import { METRIC_TYPE } from '@kbn/analytics';

describe('store_report', () => {
test('stores report for all types of data', async () => {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/alerts/server/alerts_client_factory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { taskManagerMock } from '../../task_manager/server/task_manager.mock';
import { KibanaRequest } from '../../../../src/core/server';
import { loggingServiceMock, savedObjectsClientMock } from '../../../../src/core/server/mocks';
import { encryptedSavedObjectsMock } from '../../encrypted_saved_objects/server/mocks';
import { AuthenticatedUser } from '../../security/public';
import { AuthenticatedUser } from '../../../plugins/security/common/model';
import { securityMock } from '../../security/server/mocks';
import { actionsMock } from '../../actions/server/mocks';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { SavedObjectsErrorHelpers } from '../../../../../../src/core/server';
import { apmIndexPattern } from '../../../../../../src/plugins/apm_oss/server';
import { APM_STATIC_INDEX_PATTERN_ID } from '../../../../../../src/plugins/apm_oss/server';
import {
apmIndexPattern,
APM_STATIC_INDEX_PATTERN_ID,
} from '../../../../../../src/plugins/apm_oss/server';
import { hasHistoricalAgentData } from '../services/get_services/has_historical_agent_data';
import { Setup } from '../helpers/setup_request';
import { APMRequestHandlerContext } from '../../routes/typings';
Expand Down
14 changes: 8 additions & 6 deletions x-pack/plugins/embeddable_enhanced/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,19 @@ export class EmbeddableEnhancedPlugin
});

dynamicActions.start().catch((error) => {
/* eslint-disable */
console.log('Failed to start embeddable dynamic actions', embeddable);
console.error(error);
/* eslint-disable */

console.log('Failed to start embeddable dynamic actions', embeddable);
console.error(error);
/* eslint-enable */
});

const stop = () => {
dynamicActions.stop().catch((error) => {
/* eslint-disable */
console.log('Failed to stop embeddable dynamic actions', embeddable);
console.error(error);
/* eslint-disable */

console.log('Failed to stop embeddable dynamic actions', embeddable);
console.error(error);
/* eslint-enable */
});
};
Expand Down
21 changes: 9 additions & 12 deletions x-pack/plugins/ingest_pipelines/public/shared_imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@ import { useKibana as _useKibana } from '../../../../src/plugins/kibana_react/pu
import { AppServices } from './application';

export {
AuthorizationProvider,
Error,
NotAuthorizedSection,
SectionError,
SectionLoading,
sendRequest,
SendRequestConfig,
SendRequestResponse,
UseRequestConfig,
sendRequest,
useAuthorizationContext,
useRequest,
UseRequestConfig,
WithPrivileges,
} from '../../../../src/plugins/es_ui_shared/public/';

export {
Expand Down Expand Up @@ -41,14 +48,4 @@ export {
isEmptyString,
} from '../../../../src/plugins/es_ui_shared/static/validators/string';

export {
SectionLoading,
WithPrivileges,
AuthorizationProvider,
SectionError,
Error,
useAuthorizationContext,
NotAuthorizedSection,
} from '../../../../src/plugins/es_ui_shared/public';

export const useKibana = () => _useKibana<AppServices>();
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
import { RouteDependencies } from '../../types';
import { API_BASE_PATH, APP_CLUSTER_REQUIRED_PRIVILEGES } from '../../../common/constants';
import { Privileges } from '../../../../../../src/plugins/es_ui_shared/public';
import { Privileges } from '../../../../../../src/plugins/es_ui_shared/common';

const extractMissingPrivileges = (privilegesObject: { [key: string]: boolean } = {}): string[] =>
Object.keys(privilegesObject).reduce((privileges: string[], privilegeName: string): string[] => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ export const startBasicLicense = (currentLicenseType, ack) => async (
'xpack.licenseMgmt.replacingCurrentLicenseWithBasicLicenseWarningMessage',
{
//eslint-disable-next-line
defaultMessage: 'Some functionality will be lost if you replace your {currentLicenseType} license with a BASIC license. Review the list of features below.',
defaultMessage:
'Some functionality will be lost if you replace your {currentLicenseType} license with a BASIC license. Review the list of features below.',
values: {
currentLicenseType: currentLicenseType.toUpperCase(),
},
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/maps/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import { UsageCollectionSetup } from '../../../../src/plugins/usage_collection/s
import { emsBoundariesSpecProvider } from './tutorials/ems';
// @ts-ignore
import { initRoutes } from './routes';
import { ILicense, LicensingPluginSetup } from '../../licensing/public';
import { ILicense } from '../../licensing/common/types';
import { LicensingPluginSetup } from '../../licensing/server';
import { HomeServerPluginSetup } from '../../../../src/plugins/home/server';

interface SetupDeps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ export const queryTimelineById = <TCache>({
variables: { id: timelineId },
})
// eslint-disable-next-line
.then(result => {
.then((result) => {
const timelineToOpen: TimelineResult = omitTypenameInTimeline(
getOr({}, 'data.getOneTimeline', result)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { SearchResponse } from 'elasticsearch';
import { IScopedClusterClient } from 'kibana/server';
import { AlertEvent } from '../../../../../common/endpoint/types';
import { JsonObject } from '../../../../../../../../src/plugins/kibana_utils/public';
import { JsonObject } from '../../../../../../../../src/plugins/kibana_utils/common';
import { esQuery } from '../../../../../../../../src/plugins/data/server';
import {
AlertAPIOrdering,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { SearchResponse } from 'elasticsearch';
import { IScopedClusterClient } from 'kibana/server';
import { ResolverEvent } from '../../../../../common/endpoint/types';
import { JsonObject } from '../../../../../../../../src/plugins/kibana_utils/public';
import { JsonObject } from '../../../../../../../../src/plugins/kibana_utils/common';
import { legacyEventIndexPattern } from './legacy_event_index_pattern';
import { MSearchQuery } from './multi_searcher';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { SearchResponse } from 'elasticsearch';
import { ResolverEvent } from '../../../../../common/endpoint/types';
import { ResolverQuery } from './base';
import { PaginationBuilder, PaginatedResults } from '../utils/pagination';
import { JsonObject } from '../../../../../../../../src/plugins/kibana_utils/public';
import { JsonObject } from '../../../../../../../../src/plugins/kibana_utils/common';

/**
* Builds a query for retrieving descendants of a node.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { SearchResponse } from 'elasticsearch';
import { ResolverEvent } from '../../../../../common/endpoint/types';
import { ResolverQuery } from './base';
import { PaginationBuilder, PaginatedResults } from '../utils/pagination';
import { JsonObject } from '../../../../../../../../src/plugins/kibana_utils/public';
import { JsonObject } from '../../../../../../../../src/plugins/kibana_utils/common';

/**
* Builds a query for retrieving related events for a node.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
import { SearchResponse } from 'elasticsearch';
import { ResolverQuery } from './base';
import { JsonObject } from '../../../../../../../../src/plugins/kibana_utils/public';
import { JsonObject } from '../../../../../../../../src/plugins/kibana_utils/common';
import { ResolverEvent } from '../../../../../common/endpoint/types';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { IScopedClusterClient } from 'kibana/server';
import { MSearchResponse } from 'elasticsearch';
import { ResolverEvent } from '../../../../../common/endpoint/types';
import { JsonObject } from '../../../../../../../../src/plugins/kibana_utils/public';
import { JsonObject } from '../../../../../../../../src/plugins/kibana_utils/common';

/**
* Contract for queries to be compatible with ES multi search api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { SearchResponse } from 'elasticsearch';
import { ResolverQuery } from './base';
import { ResolverEvent, EventStats } from '../../../../../common/endpoint/types';
import { JsonObject } from '../../../../../../../../src/plugins/kibana_utils/public';
import { JsonObject } from '../../../../../../../../src/plugins/kibana_utils/common';
import { AggBucket } from '../utils/pagination';

export interface StatsResult {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { ResolverEvent } from '../../../../../common/endpoint/types';
import { eventId } from '../../../../../common/endpoint/models/event';
import { JsonObject } from '../../../../../../../../src/plugins/kibana_utils/public';
import { JsonObject } from '../../../../../../../../src/plugins/kibana_utils/common';

/**
* Represents a single result bucket of an aggregation
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/security_solution/server/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { AuthenticatedUser } from '../../../security/public';
import { AuthenticatedUser } from '../../../security/common/model';
import { RequestHandlerContext } from '../../../../../src/core/server';
export { ConfigType as Configuration } from '../config';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { UserInputError } from 'apollo-server-errors';
import { isEmpty, isPlainObject, isString } from 'lodash/fp';

import { JsonObject } from '../../../../../src/plugins/kibana_utils/public';
import { JsonObject } from '../../../../../src/plugins/kibana_utils/common';

export const parseFilterQuery = (filterQuery: string): JsonObject => {
try {
Expand Down
18 changes: 9 additions & 9 deletions x-pack/plugins/snapshot_restore/public/shared_imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
*/

export {
SendRequestConfig,
SendRequestResponse,
UseRequestConfig,
sendRequest,
useRequest,
AuthorizationProvider,
CronEditor,
DAY,
SectionError,
Error,
WithPrivileges,
useAuthorizationContext,
NotAuthorizedSection,
AuthorizationProvider,
SectionError,
sendRequest,
SendRequestConfig,
SendRequestResponse,
useAuthorizationContext,
useRequest,
UseRequestConfig,
WithPrivileges,
} from '../../../../src/plugins/es_ui_shared/public';
2 changes: 1 addition & 1 deletion x-pack/plugins/snapshot_restore/server/routes/api/app.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 { Privileges } from '../../../../../../src/plugins/es_ui_shared/public';
import { Privileges } from '../../../../../../src/plugins/es_ui_shared/common';

import {
APP_REQUIRED_CLUSTER_PRIVILEGES,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ import { mount } from 'enzyme';
import { TimeRangeEmbeddable, TimeRangeContainer, TIME_RANGE_EMBEDDABLE } from './test_helpers';
import { CustomTimeRangeAction } from './custom_time_range_action';
/* eslint-disable */
import {
HelloWorldContainer,
} from '../../../../src/plugins/embeddable/public/lib/test_samples';
import { HelloWorldContainer } from '../../../../src/plugins/embeddable/public/lib/test_samples';
/* eslint-enable */

import {
Expand Down