-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* finishes TS conversion for the Spaces plugin
- Loading branch information
Showing
64 changed files
with
1,566 additions
and
1,114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { resolve } from 'path'; | ||
// @ts-ignore | ||
import { AuditLogger } from '../../server/lib/audit_logger'; | ||
// @ts-ignore | ||
import { watchStatusAndLicenseToInitialize } from '../../server/lib/watch_status_and_license_to_initialize'; | ||
import { registerUserProfileCapabilityFactory } from '../xpack_main/server/lib/user_profile_registry'; | ||
import mappings from './mappings.json'; | ||
import { SpacesAuditLogger } from './server/lib/audit_logger'; | ||
import { checkLicense } from './server/lib/check_license'; | ||
import { createDefaultSpace } from './server/lib/create_default_space'; | ||
import { createSpacesService } from './server/lib/create_spaces_service'; | ||
import { wrapError } from './server/lib/errors'; | ||
import { getActiveSpace } from './server/lib/get_active_space'; | ||
import { getSpacesUsageCollector } from './server/lib/get_spaces_usage_collector'; | ||
import { spacesSavedObjectsClientWrapperFactory } from './server/lib/saved_objects_client/saved_objects_client_wrapper_factory'; | ||
import { initSpacesRequestInterceptors } from './server/lib/space_request_interceptors'; | ||
import { SpacesClient } from './server/lib/spaces_client'; | ||
import { createSpacesTutorialContextFactory } from './server/lib/spaces_tutorial_context_factory'; | ||
import { initPublicSpacesApi } from './server/routes/api/public'; | ||
import { initPrivateApis } from './server/routes/api/v1'; | ||
|
||
export const spaces = (kibana: any) => | ||
new kibana.Plugin({ | ||
id: 'spaces', | ||
configPrefix: 'xpack.spaces', | ||
publicDir: resolve(__dirname, 'public'), | ||
require: ['kibana', 'elasticsearch', 'xpack_main'], | ||
|
||
config(Joi: any) { | ||
return Joi.object({ | ||
enabled: Joi.boolean().default(true), | ||
}).default(); | ||
}, | ||
|
||
uiExports: { | ||
chromeNavControls: ['plugins/spaces/views/nav_control'], | ||
managementSections: ['plugins/spaces/views/management'], | ||
apps: [ | ||
{ | ||
id: 'space_selector', | ||
title: 'Spaces', | ||
main: 'plugins/spaces/views/space_selector', | ||
url: 'space_selector', | ||
hidden: true, | ||
}, | ||
], | ||
hacks: [], | ||
mappings, | ||
savedObjectsSchema: { | ||
space: { | ||
isNamespaceAgnostic: true, | ||
}, | ||
}, | ||
home: ['plugins/spaces/register_feature'], | ||
injectDefaultVars(server: any) { | ||
return { | ||
spaces: [], | ||
activeSpace: null, | ||
spaceSelectorURL: server.config().get('server.basePath') || '/', | ||
}; | ||
}, | ||
async replaceInjectedVars(vars: any, request: any, server: any) { | ||
const spacesClient = server.plugins.spaces.spacesClient.getScopedClient(request); | ||
try { | ||
vars.activeSpace = { | ||
valid: true, | ||
space: await getActiveSpace( | ||
spacesClient, | ||
request.getBasePath(), | ||
server.config().get('server.basePath') | ||
), | ||
}; | ||
} catch (e) { | ||
vars.activeSpace = { | ||
valid: false, | ||
error: wrapError(e).output.payload, | ||
}; | ||
} | ||
return vars; | ||
}, | ||
}, | ||
|
||
async init(server: any) { | ||
const thisPlugin = this; | ||
const xpackMainPlugin = server.plugins.xpack_main; | ||
|
||
watchStatusAndLicenseToInitialize(xpackMainPlugin, thisPlugin, async () => { | ||
await createDefaultSpace(server); | ||
}); | ||
|
||
// Register a function that is called whenever the xpack info changes, | ||
// to re-compute the license check results for this plugin | ||
xpackMainPlugin.info | ||
.feature(thisPlugin.id) | ||
.registerLicenseCheckResultsGenerator(checkLicense); | ||
|
||
const spacesService = createSpacesService(server); | ||
server.expose('getSpaceId', (request: any) => spacesService.getSpaceId(request)); | ||
|
||
const config = server.config(); | ||
|
||
const spacesAuditLogger = new SpacesAuditLogger(config, new AuditLogger(server, 'spaces')); | ||
|
||
server.expose('spacesClient', { | ||
getScopedClient: (request: any) => { | ||
const adminCluster = server.plugins.elasticsearch.getCluster('admin'); | ||
const { callWithRequest, callWithInternalUser } = adminCluster; | ||
const callCluster = (...args: any[]) => callWithRequest(request, ...args); | ||
const { savedObjects } = server; | ||
const internalRepository = savedObjects.getSavedObjectsRepository(callWithInternalUser); | ||
const callWithRequestRepository = savedObjects.getSavedObjectsRepository(callCluster); | ||
const authorization = server.plugins.security | ||
? server.plugins.security.authorization | ||
: null; | ||
return new SpacesClient( | ||
spacesAuditLogger, | ||
authorization, | ||
callWithRequestRepository, | ||
internalRepository, | ||
request | ||
); | ||
}, | ||
}); | ||
|
||
const { addScopedSavedObjectsClientWrapperFactory, types } = server.savedObjects; | ||
addScopedSavedObjectsClientWrapperFactory( | ||
Number.MAX_VALUE, | ||
spacesSavedObjectsClientWrapperFactory(spacesService, types) | ||
); | ||
|
||
server.addScopedTutorialContextFactory(createSpacesTutorialContextFactory(spacesService)); | ||
|
||
initPrivateApis(server); | ||
initPublicSpacesApi(server); | ||
|
||
initSpacesRequestInterceptors(server); | ||
|
||
registerUserProfileCapabilityFactory(async request => { | ||
const spacesClient = server.plugins.spaces.spacesClient.getScopedClient(request); | ||
|
||
return { | ||
manageSpaces: await spacesClient.canEnumerateSpaces(), | ||
}; | ||
}); | ||
|
||
// Register a function with server to manage the collection of usage stats | ||
server.usage.collectorSet.register(getSpacesUsageCollector(server)); | ||
}, | ||
}); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.