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

Spaces - server-side to NP plugin #46181

Merged
merged 34 commits into from
Oct 15, 2019
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
0b219db
Moving spaces server-side to NP plugin
legrego Sep 19, 2019
8f42087
allow unknown configs
legrego Sep 19, 2019
c2ee236
fixing tests
legrego Sep 19, 2019
500e406
support multiple paths per plugin for i18n messages
legrego Sep 20, 2019
4ed9fab
moving tags => options.tags
legrego Sep 20, 2019
64225a0
Merge branch 'master' of github.com:elastic/kibana into np/spaces-ser…
legrego Sep 20, 2019
3d5c4b9
fixing integrate_locale_files
legrego Sep 20, 2019
ef4abd3
removing more unused code
legrego Sep 20, 2019
3fafe74
Merge branch 'master' of github.com:elastic/kibana into np/spaces-ser…
legrego Sep 25, 2019
ba38076
remove more unused code
legrego Sep 25, 2019
aaf79da
Merge branch 'master' of github.com:elastic/kibana into np/spaces-ser…
legrego Sep 25, 2019
c0ba021
improving space schema validation
legrego Sep 25, 2019
04f218d
Merge branch 'master' of github.com:elastic/kibana into np/spaces-ser…
legrego Sep 26, 2019
22016be
Merge branch 'master' of github.com:elastic/kibana into np/spaces-ser…
legrego Sep 30, 2019
a1c75f0
implement license check for public api routes
legrego Sep 30, 2019
4350817
remove unused import
legrego Sep 30, 2019
7c5f400
Merge branch 'master' of github.com:elastic/kibana into np/spaces-ser…
legrego Oct 1, 2019
266c922
fixes from merge
legrego Oct 1, 2019
409a2d1
using NP serverBasePath property
legrego Oct 1, 2019
c705175
fix legacy config set up
legrego Oct 1, 2019
2b4db4c
trigger default space creation from the legacy platform
legrego Oct 1, 2019
745c1a7
Merge branch 'master' of github.com:elastic/kibana into np/spaces-ser…
legrego Oct 2, 2019
42c6e16
move snapshot to NP
legrego Oct 2, 2019
fb08872
Merge branch 'master' of github.com:elastic/kibana into np/spaces-ser…
legrego Oct 8, 2019
2dccfcc
additional cleanup
legrego Oct 8, 2019
d510310
removing unused type
legrego Oct 8, 2019
8ea8541
remove unused spaces_url_parser
legrego Oct 8, 2019
6c06e9e
addressing PR feedback
legrego Oct 11, 2019
f1174dd
Merge branch 'master' of github.com:elastic/kibana into np/spaces-ser…
legrego Oct 11, 2019
87fd27b
additional cleanup
legrego Oct 11, 2019
705f63a
fixing import from NP
legrego Oct 11, 2019
1048229
adding 'enabled' property to NP plugin config
legrego Oct 11, 2019
8aa701b
SpacesService/SpacesClient should still support legacy/fake requests …
legrego Oct 11, 2019
ec4cb0f
Merge branch 'master' of github.com:elastic/kibana into np/spaces-ser…
legrego Oct 15, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion x-pack/.i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"xpack.security": "legacy/plugins/security",
"xpack.server": "legacy/server",
"xpack.snapshotRestore": "legacy/plugins/snapshot_restore",
"xpack.spaces": "legacy/plugins/spaces",
"xpack.spaces": ["legacy/plugins/spaces", "plugins/spaces"],
"xpack.transform": "legacy/plugins/transform",
"xpack.upgradeAssistant": "legacy/plugins/upgrade_assistant",
"xpack.uptime": "legacy/plugins/uptime",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import Hapi from 'hapi';
import { EncryptedSavedObjectsStartContract } from '../shim';
import { SpacesPlugin as SpacesPluginStartContract } from '../../../spaces';
import { LegacySpacesPlugin as SpacesPluginStartContract } from '../../../spaces';
import { Logger } from '../../../../../../src/core/server';
import { validateParams, validateConfig, validateSecrets } from './validate_with_schema';
import {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/actions/server/shim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { ActionsConfigType } from './types';
import { TaskManager } from '../../task_manager';
import { XPackMainPlugin } from '../../xpack_main/xpack_main';
import KbnServer from '../../../../../src/legacy/server/kbn_server';
import { SpacesPlugin as SpacesPluginStartContract } from '../../spaces';
import { LegacySpacesPlugin as SpacesPluginStartContract } from '../../spaces';
import { EncryptedSavedObjectsPlugin } from '../../encrypted_saved_objects';
import { PluginSetupContract as SecurityPlugin } from '../../../../plugins/security/server';
import {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/alerting/server/shim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import Hapi from 'hapi';
import { Legacy } from 'kibana';
import { SpacesPlugin as SpacesPluginStartContract } from '../../spaces';
import { LegacySpacesPlugin as SpacesPluginStartContract } from '../../spaces';
import { TaskManager } from '../../task_manager';
import { XPackMainPlugin } from '../../xpack_main/xpack_main';
import KbnServer from '../../../../../src/legacy/server/kbn_server';
Expand Down
4 changes: 2 additions & 2 deletions x-pack/legacy/plugins/ml/server/lib/spaces_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
*/

import { Request } from 'hapi';
import { SpacesPlugin } from '../../../spaces';
import { LegacySpacesPlugin } from '../../../spaces';
import { Space } from '../../../spaces/common/model/space';

interface GetActiveSpaceResponse {
valid: boolean;
space?: Space;
}

export function spacesUtilsProvider(spacesPlugin: SpacesPlugin, request: Request) {
export function spacesUtilsProvider(spacesPlugin: LegacySpacesPlugin, request: Request) {
async function activeSpace(): Promise<GetActiveSpaceResponse> {
try {
return {
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 { SpacesPlugin } from '../../../../spaces';
import { LegacySpacesPlugin } from '../../../../spaces';
import { OptionalPlugin } from '../../../../../server/lib/optional_plugin';
import { checkPrivilegesDynamicallyWithRequestFactory } from './check_privileges_dynamically';

Expand All @@ -23,7 +23,7 @@ test(`checkPrivileges.atSpace when spaces is enabled`, async () => {
getBasePath: jest.fn(),
getScopedSpacesClient: jest.fn(),
getActiveSpace: jest.fn(),
} as OptionalPlugin<SpacesPlugin>;
} as OptionalPlugin<LegacySpacesPlugin>;
const request = Symbol();
const privilegeOrPrivileges = ['foo', 'bar'];
const checkPrivilegesDynamically = checkPrivilegesDynamicallyWithRequestFactory(
Expand All @@ -45,7 +45,7 @@ test(`checkPrivileges.globally when spaces is disabled`, async () => {
const mockCheckPrivilegesWithRequest = jest.fn().mockReturnValue(mockCheckPrivileges);
const mockSpaces = {
isEnabled: false,
} as OptionalPlugin<SpacesPlugin>;
} as OptionalPlugin<LegacySpacesPlugin>;
const request = Symbol();
const privilegeOrPrivileges = ['foo', 'bar'];
const checkPrivilegesDynamically = checkPrivilegesDynamicallyWithRequestFactory(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { CheckPrivilegesAtResourceResponse, CheckPrivilegesWithRequest } from '.
* you may not use this file except in compliance with the Elastic License.
*/

import { SpacesPlugin } from '../../../../spaces';
import { LegacySpacesPlugin } from '../../../../spaces';
import { OptionalPlugin } from '../../../../../server/lib/optional_plugin';

export type CheckPrivilegesDynamically = (
Expand All @@ -26,7 +26,7 @@ export type CheckPrivilegesDynamicallyWithRequest = (

export function checkPrivilegesDynamicallyWithRequestFactory(
checkPrivilegesWithRequest: CheckPrivilegesWithRequest,
spaces: OptionalPlugin<SpacesPlugin>
spaces: OptionalPlugin<LegacySpacesPlugin>
): CheckPrivilegesDynamicallyWithRequest {
return function checkPrivilegesDynamicallyWithRequest(request: Legacy.Request) {
const checkPrivileges = checkPrivilegesWithRequest(request);
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 { SpacesPlugin } from '../../../../spaces';
import { LegacySpacesPlugin } from '../../../../spaces';
import { OptionalPlugin } from '../../../../../server/lib/optional_plugin';
import { checkSavedObjectsPrivilegesWithRequestFactory } from './check_saved_objects_privileges';

Expand All @@ -19,7 +19,7 @@ test(`checkPrivileges.atSpace when spaces is enabled`, async () => {
const mockSpaces = ({
isEnabled: true,
namespaceToSpaceId: jest.fn().mockReturnValue(spaceId),
} as unknown) as OptionalPlugin<SpacesPlugin>;
} as unknown) as OptionalPlugin<LegacySpacesPlugin>;
const request = Symbol();

const privilegeOrPrivileges = ['foo', 'bar'];
Expand Down Expand Up @@ -50,7 +50,7 @@ test(`checkPrivileges.globally when spaces is disabled`, async () => {
namespaceToSpaceId: jest.fn().mockImplementation(() => {
throw new Error('should not be called');
}),
} as unknown) as OptionalPlugin<SpacesPlugin>;
} as unknown) as OptionalPlugin<LegacySpacesPlugin>;

const request = Symbol();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { Legacy } from 'kibana';
import { SpacesPlugin } from '../../../../spaces';
import { LegacySpacesPlugin } from '../../../../spaces';
import { OptionalPlugin } from '../../../../../server/lib/optional_plugin';
import { CheckPrivilegesAtResourceResponse, CheckPrivilegesWithRequest } from './check_privileges';

Expand All @@ -19,7 +19,7 @@ export type CheckSavedObjectsPrivileges = (

export const checkSavedObjectsPrivilegesWithRequestFactory = (
checkPrivilegesWithRequest: CheckPrivilegesWithRequest,
spaces: OptionalPlugin<SpacesPlugin>
spaces: OptionalPlugin<LegacySpacesPlugin>
): CheckSavedObjectsPrivilegesWithRequest => {
return function checkSavedObjectsPrivilegesWithRequest(request: Legacy.Request) {
return async function checkSavedObjectsPrivileges(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { Server } from 'hapi';

import { getClient } from '../../../../../server/lib/get_client_shield';
import { SpacesPlugin } from '../../../../spaces';
import { LegacySpacesPlugin } from '../../../../spaces';
import { XPackFeature, XPackMainPlugin } from '../../../../xpack_main/xpack_main';
import { APPLICATION_PREFIX } from '../../../common/constants';
import { OptionalPlugin } from '../../../../../server/lib/optional_plugin';
Expand Down Expand Up @@ -38,7 +38,7 @@ export function createAuthorizationService(
server: Server,
securityXPackFeature: XPackFeature,
xpackMainPlugin: XPackMainPlugin,
spaces: OptionalPlugin<SpacesPlugin>
spaces: OptionalPlugin<LegacySpacesPlugin>
): AuthorizationService {
const shieldClient = getClient(server);
const config = server.config();
Expand Down
2 changes: 0 additions & 2 deletions x-pack/legacy/plugins/spaces/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,3 @@

export { isReservedSpace } from './is_reserved_space';
export { MAX_SPACE_INITIALS } from './constants';

export { getSpaceIdFromPath, addSpaceIdToPath } from './lib/spaces_url_parser';
113 changes: 44 additions & 69 deletions x-pack/legacy/plugins/spaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,29 @@
* you may not use this file except in compliance with the Elastic License.
*/

import * as Rx from 'rxjs';
import { resolve } from 'path';
import KbnServer, { Server } from 'src/legacy/server/kbn_server';
import { CoreSetup, PluginInitializerContext } from 'src/core/server';
import { Legacy } from 'kibana';
import { KibanaRequest } from 'src/core/server';
import { SpacesServiceSetup } from '../../../plugins/spaces/server/spaces_service/spaces_service';
import { SpacesPluginSetup } from '../../../plugins/spaces/server';
import { createOptionalPlugin } from '../../server/lib/optional_plugin';
// @ts-ignore
import { AuditLogger } from '../../server/lib/audit_logger';
import mappings from './mappings.json';
import { wrapError } from './server/lib/errors';
import { getActiveSpace } from './server/lib/get_active_space';
import { migrateToKibana660 } from './server/lib/migrations';
import { plugin } from './server/new_platform';
import { SecurityPlugin } from '../security';
import { SpacesServiceSetup } from './server/new_platform/spaces_service/spaces_service';
// @ts-ignore
import { watchStatusAndLicenseToInitialize } from '../../server/lib/watch_status_and_license_to_initialize';
import { initSpaceSelectorView, initEnterSpaceView } from './server/routes/views';

export interface SpacesPlugin {
getSpaceId: SpacesServiceSetup['getSpaceId'];
getActiveSpace: SpacesServiceSetup['getActiveSpace'];
export interface LegacySpacesPlugin {
getSpaceId: (request: Legacy.Request) => ReturnType<SpacesServiceSetup['getSpaceId']>;
getActiveSpace: (request: Legacy.Request) => ReturnType<SpacesServiceSetup['getActiveSpace']>;
spaceIdToNamespace: SpacesServiceSetup['spaceIdToNamespace'];
namespaceToSpaceId: SpacesServiceSetup['namespaceToSpaceId'];
getBasePath: SpacesServiceSetup['getBasePath'];
getScopedSpacesClient: SpacesServiceSetup['scopedClient'];
}

export const spaces = (kibana: Record<string, any>) =>
Expand All @@ -36,13 +36,6 @@ export const spaces = (kibana: Record<string, any>) =>
publicDir: resolve(__dirname, 'public'),
require: ['kibana', 'elasticsearch', 'xpack_main'],

config(Joi: any) {
return Joi.object({
enabled: Joi.boolean().default(true),
maxSpaces: Joi.number().default(1000),
}).default();
},

uiCapabilities() {
return {
spaces: {
Expand Down Expand Up @@ -92,18 +85,20 @@ export const spaces = (kibana: Record<string, any>) =>
},
async replaceInjectedVars(
vars: Record<string, any>,
request: Record<string, any>,
request: Legacy.Request,
server: Record<string, any>
) {
const spacesClient = await server.plugins.spaces.getScopedSpacesClient(request);
const spacesPlugin = server.newPlatform.setup.plugins.spaces as SpacesPluginSetup;
if (!spacesPlugin) {
throw new Error('New Platform XPack Spaces plugin is not available.');
}
const kibanaRequest = KibanaRequest.from(request);
const spaceId = spacesPlugin.spacesService.getSpaceId(kibanaRequest);
const spacesClient = await spacesPlugin.spacesService.scopedClient(kibanaRequest);
try {
vars.activeSpace = {
valid: true,
space: await getActiveSpace(
spacesClient,
request.getBasePath(),
server.config().get('server.basePath')
),
space: await spacesClient.get(spaceId),
};
} catch (e) {
vars.activeSpace = {
Expand All @@ -118,52 +113,18 @@ export const spaces = (kibana: Record<string, any>) =>

async init(server: Server) {
const kbnServer = (server as unknown) as KbnServer;
const initializerContext = {
config: {
create: () => {
return Rx.of({
maxSpaces: server.config().get('xpack.spaces.maxSpaces'),
});
},
},
logger: {
get(...contextParts: string[]) {
return kbnServer.newPlatform.coreContext.logger.get(
'plugins',
'spaces',
...contextParts
);
},
},
} as PluginInitializerContext;

const core = (kbnServer.newPlatform.setup.core as unknown) as CoreSetup;

const plugins = {
xpackMain: server.plugins.xpack_main,
// TODO: Spaces has a circular dependency with Security right now.
// Security is not yet available when init runs, so this is wrapped in an optional function for the time being.
security: createOptionalPlugin<SecurityPlugin>(
server.config(),
'xpack.security',
server.plugins,
'security'
),
spaces: this,
};

const { spacesService, registerLegacyAPI } = await plugin(initializerContext).setup(
core,
plugins
);
const spacesPlugin = kbnServer.newPlatform.setup.plugins.spaces as SpacesPluginSetup;
if (!spacesPlugin) {
throw new Error('New Platform XPack Spaces plugin is not available.');
}

const config = server.config();

const { registerLegacyAPI, createDefaultSpace } = spacesPlugin.__legacyCompat;

registerLegacyAPI({
router: server.route.bind(server),
legacyConfig: {
serverBasePath: config.get('server.basePath'),
serverDefaultRoute: config.get('server.defaultRoute'),
kibanaIndex: config.get('kibana.index'),
},
savedObjects: server.savedObjects,
Expand All @@ -178,16 +139,30 @@ export const spaces = (kibana: Record<string, any>) =>
create: (pluginId: string) =>
new AuditLogger(server, pluginId, server.config(), server.plugins.xpack_main.info),
},
security: createOptionalPlugin<SecurityPlugin>(
server.config(),
'xpack.security',
server.plugins,
'security'
),
xpackMain: server.plugins.xpack_main,
});

initEnterSpaceView(server);
initSpaceSelectorView(server);

server.expose('getSpaceId', (request: any) => spacesService.getSpaceId(request));
server.expose('getActiveSpace', spacesService.getActiveSpace);
server.expose('spaceIdToNamespace', spacesService.spaceIdToNamespace);
server.expose('namespaceToSpaceId', spacesService.namespaceToSpaceId);
server.expose('getBasePath', spacesService.getBasePath);
server.expose('getScopedSpacesClient', spacesService.scopedClient);
watchStatusAndLicenseToInitialize(server.plugins.xpack_main, this, async () => {
await createDefaultSpace();
});

server.expose('getSpaceId', (request: Legacy.Request) =>
spacesPlugin.spacesService.getSpaceId(KibanaRequest.from(request))
);
server.expose('getActiveSpace', (request: Legacy.Request) =>
spacesPlugin.spacesService.getActiveSpace(KibanaRequest.from(request))
);
server.expose('spaceIdToNamespace', spacesPlugin.spacesService.spaceIdToNamespace);
server.expose('namespaceToSpaceId', spacesPlugin.spacesService.namespaceToSpaceId);
server.expose('getBasePath', spacesPlugin.spacesService.getBasePath);
},
});
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/spaces/public/lib/spaces_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Space } from '../../common/model/space';
import { GetSpacePurpose } from '../../common/model/types';
import { CopySavedObjectsToSpaceResponse } from './copy_saved_objects_to_space/types';
import { ENTER_SPACE_PATH } from '../../common/constants';
import { addSpaceIdToPath } from '../../common';
import { addSpaceIdToPath } from '../../../../../plugins/spaces/common';

export class SpacesManager extends EventEmitter {
constructor(private readonly serverBasePath: string) {
Expand Down
41 changes: 0 additions & 41 deletions x-pack/legacy/plugins/spaces/server/lib/check_license.ts

This file was deleted.

Loading