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
5 changes: 5 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ module.exports = {
from: ['src/core/utils/**/*'],
errorMessage: `Plugins may only import from src/core/server and src/core/public.`,
},
{
target: ['(src|x-pack)/plugins/*/server/**/*', '!x-pack/plugins/apm/**/*'],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

APM is a less than straightforward update and I would rather not make assumptions for their desired organization. I will follow-up with an issue for the team to resolve.

Copy link
Member

@sorenlouv sorenlouv May 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what you are hitting is caused by the server side types consumed by the client.
Types are inferred from server-side routes and can therefore not be moved to common.

I expect we can resolve this when typescript is updated to 3.8 and we can use type only imports.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from: ['(src|x-pack)/plugins/*/public/**/*'],
errorMessage: `Server code can not import from public, use a common directory.`,
},
{
target: [
'(src|x-pack)/legacy/**/*',
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/apm_oss/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export { APMOSSPluginSetup } from './plugin';

export { apmIndexPattern };

export { APM_STATIC_INDEX_PATTERN_ID } from '../common/index_pattern_constants';

export {
createNodeAgentInstructions,
createDjangoAgentInstructions,
Expand Down
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,
NotAuthorizedSection,
WithPrivileges,
Privileges,
MissingPrivileges,
SectionError,
Error,
useAuthorizationContext,
} from './authorization';
12 changes: 0 additions & 12 deletions src/plugins/es_ui_shared/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,6 @@ export {
expandLiteralStrings,
} from './console_lang';

export {
AuthorizationContext,
AuthorizationProvider,
NotAuthorizedSection,
WithPrivileges,
Privileges,
MissingPrivileges,
SectionError,
Error,
useAuthorizationContext,
} from './authorization';

/** dummy plugin, we just want esUiShared to have its own bundle */
export function plugin() {
return new (class EsUiSharedPlugin {
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { taskManagerMock } from '../../../plugins/task_manager/server/task_manag
import { KibanaRequest } from '../../../../src/core/server';
import { loggingServiceMock, savedObjectsClientMock } from '../../../../src/core/server/mocks';
import { encryptedSavedObjectsMock } from '../../../plugins/encrypted_saved_objects/server/mocks';
import { AuthenticatedUser } from '../../../plugins/security/public';
import { AuthenticatedUser } from '../../../plugins/security/common/model';
import { securityMock } from '../../../plugins/security/server/mocks';

jest.mock('./alerts_client');
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/public';
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
5 changes: 3 additions & 2 deletions x-pack/plugins/ingest_pipelines/public/shared_imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ export {
} from '../../../../src/plugins/es_ui_shared/static/validators/string';

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

export { SectionLoading } 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 @@ -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 @@ -13,7 +13,7 @@ import {
PaginationParams,
PaginatedResults,
} from '../utils/pagination';
import { JsonObject } from '../../../../../../../../src/plugins/kibana_utils/public';
import { JsonObject } from '../../../../../../../../src/plugins/kibana_utils/common';
import { legacyEventIndexPattern } from './legacy_event_index_pattern';

export abstract class ResolverQuery {
Expand Down
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 { ResolverQuery } from './base';
import { JsonObject } from '../../../../../../../../src/plugins/kibana_utils/public';
import { JsonObject } from '../../../../../../../../src/plugins/kibana_utils/common';

export class EventsQuery extends ResolverQuery {
protected legacyQuery(endpointID: string, uniquePIDs: string[], index: string): JsonObject {
Expand Down
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 { ResolverQuery } from './base';
import { JsonObject } from '../../../../../../../../src/plugins/kibana_utils/public';
import { JsonObject } from '../../../../../../../../src/plugins/kibana_utils/common';

export class LifecycleQuery extends ResolverQuery {
protected legacyQuery(endpointID: string, uniquePIDs: string[], index: string): JsonObject {
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 } from '../../../../../common/endpoint/types';
import { JsonObject } from '../../../../../../../../src/plugins/kibana_utils/public';
import { JsonObject } from '../../../../../../../../src/plugins/kibana_utils/common';
import { PaginatedResults } from '../utils/pagination';

export class StatsQuery extends ResolverQuery {
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 { entityId } from '../../../../../common/endpoint/models/event';
import { JsonObject } from '../../../../../../../../src/plugins/kibana_utils/public';
import { JsonObject } from '../../../../../../../../src/plugins/kibana_utils/common';

export interface PaginationParams {
size: number;
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/siem/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
2 changes: 1 addition & 1 deletion x-pack/plugins/siem/server/utils/serialized_query.ts
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
21 changes: 12 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,20 @@
*/

export {
CronEditor,
DAY,
sendRequest,
SendRequestConfig,
SendRequestResponse,
UseRequestConfig,
sendRequest,
useRequest,
CronEditor,
DAY,
SectionError,
UseRequestConfig,
} from '../../../../src/plugins/es_ui_shared/public';

export {
AuthorizationProvider,
Error,
WithPrivileges,
useAuthorizationContext,
NotAuthorizedSection,
AuthorizationProvider,
} from '../../../../src/plugins/es_ui_shared/public';
SectionError,
useAuthorizationContext,
WithPrivileges,
} from '../../../../src/plugins/es_ui_shared/common';
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