Skip to content

Commit

Permalink
Move base feature controls functionality from XPack Main plugin to a …
Browse files Browse the repository at this point in the history
…dedicated XPack Features plugin (#44664)
  • Loading branch information
azasypkin authored Sep 9, 2019
1 parent b7aeaf5 commit 9d69b72
Show file tree
Hide file tree
Showing 83 changed files with 1,190 additions and 976 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
/src/legacy/server/saved_objects/ @elastic/kibana-platform
/src/legacy/ui/public/saved_objects @elastic/kibana-platform
/config/kibana.yml @elastic/kibana-platform
/x-pack/plugins/features/ @elastic/kibana-platform

# Security
/x-pack/legacy/plugins/security/ @elastic/kibana-security
Expand Down
2 changes: 1 addition & 1 deletion docs/api/features/get.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ experimental[This API is *experimental* and may be changed or removed completely
[[features-api-get-request]]
==== Request

`GET /api/features/v1`
`GET /api/features`

[[features-api-get-codes]]
==== Response code
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ init(server) {
-----------

===== Feature details
Registering a feature consists of the following fields. For more information, consult the {repo}blob/{branch}/x-pack/legacy/plugins/xpack_main/server/lib/feature_registry/feature_registry.ts[feature registry interface].
Registering a feature consists of the following fields. For more information, consult the {repo}blob/{branch}/x-pack/plugins/features/server/feature_registry.ts[feature registry interface].


[cols="1a, 1a, 1a, 1a"]
Expand All @@ -45,7 +45,7 @@ Registering a feature consists of the following fields. For more information, co
|An array of applications this feature enables. Typically, all of your plugin's apps (from `uiExports`) will be included here.

|`privileges` (required)
|{repo}blob/{branch}/x-pack/legacy/plugins/xpack_main/server/lib/feature_registry/feature_registry.ts[`FeatureWithAllOrReadPrivileges`].
|{repo}blob/{branch}/x-pack/plugins/features/server/feature.ts[`FeatureWithAllOrReadPrivileges`].
|see examples below
|The set of privileges this feature requires to function.

Expand All @@ -63,7 +63,7 @@ Registering a feature consists of the following fields. For more information, co
===== Privilege definition
The `privileges` section of feature registration allows plugins to implement read/write and read-only modes for their applications.

For a full explanation of fields and options, consult the {repo}blob/{branch}/x-pack/legacy/plugins/xpack_main/server/lib/feature_registry/feature_registry.ts[feature registry interface].
For a full explanation of fields and options, consult the {repo}blob/{branch}/x-pack/plugins/features/server/feature_registry.ts[feature registry interface].

==== Using UI Capabilities

Expand Down Expand Up @@ -142,7 +142,7 @@ init(server) {
const xpackMainPlugin = server.plugins.xpack_main;
xpackMainPlugin.registerFeature({
id: 'dev_tools',
name: i18n.translate('xpack.main.featureRegistry.devToolsFeatureName', {
name: i18n.translate('xpack.features.devToolsFeatureName', {
defaultMessage: 'Dev Tools',
}),
icon: 'devToolsApp',
Expand All @@ -167,7 +167,7 @@ init(server) {
ui: ['show'],
},
},
privilegesTooltip: i18n.translate('xpack.main.featureRegistry.devToolsPrivilegesTooltip', {
privilegesTooltip: i18n.translate('xpack.features.devToolsPrivilegesTooltip', {
defaultMessage:
'User should also be granted the appropriate Elasticsearch cluster and index privileges',
}),
Expand Down
1 change: 1 addition & 0 deletions src/core/server/http/http_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,5 @@ export const httpServiceMock = {
createSetupContract: createSetupContractMock,
createOnPreAuthToolkit: createOnPreAuthToolkitMock,
createAuthToolkit: createAuthToolkitMock,
createRouter: createRouterMock,
};
8 changes: 8 additions & 0 deletions src/plugins/timelion/kibana.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"id": "timelion",
"version": "8.0.0",
"kibanaVersion": "kibana",
"configPath": ["timelion"],
"server": true,
"ui": false
}
28 changes: 28 additions & 0 deletions src/plugins/timelion/server/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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.
*/

import { schema } from '@kbn/config-schema';

export const ConfigSchema = schema.object(
{
ui: schema.object({ enabled: schema.boolean({ defaultValue: false }) }),
},
// This option should be removed as soon as we entirely migrate config from legacy Timelion plugin.
{ allowUnknowns: true }
);
28 changes: 28 additions & 0 deletions src/plugins/timelion/server/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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.
*/

import { PluginInitializerContext } from '../../../../src/core/server';
import { ConfigSchema } from './config';
import { Plugin } from './plugin';

export { PluginSetupContract } from './plugin';

export const config = { schema: ConfigSchema };
export const plugin = (initializerContext: PluginInitializerContext) =>
new Plugin(initializerContext);
55 changes: 55 additions & 0 deletions src/plugins/timelion/server/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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.
*/

import { first } from 'rxjs/operators';
import { TypeOf } from '@kbn/config-schema';
import { PluginInitializerContext, RecursiveReadonly } from '../../../../src/core/server';
import { deepFreeze } from '../../../../src/core/utils';
import { ConfigSchema } from './config';

/**
* Describes public Timelion plugin contract returned at the `setup` stage.
*/
export interface PluginSetupContract {
uiEnabled: boolean;
}

/**
* Represents Timelion Plugin instance that will be managed by the Kibana plugin system.
*/
export class Plugin {
constructor(private readonly initializerContext: PluginInitializerContext) {}

public async setup(): Promise<RecursiveReadonly<PluginSetupContract>> {
const config = await this.initializerContext.config
.create<TypeOf<typeof ConfigSchema>>()
.pipe(first())
.toPromise();

return deepFreeze({ uiEnabled: config.ui.enabled });
}

public start() {
this.initializerContext.logger.get().debug('Starting plugin');
}

public stop() {
this.initializerContext.logger.get().debug('Stopping plugin');
}
}
1 change: 1 addition & 0 deletions x-pack/.i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"xpack.code": "legacy/plugins/code",
"xpack.crossClusterReplication": "legacy/plugins/cross_cluster_replication",
"xpack.dashboardMode": "legacy/plugins/dashboard_mode",
"xpack.features": "plugins/features",
"xpack.fileUpload": "legacy/plugins/file_upload",
"xpack.graph": "legacy/plugins/graph",
"xpack.grokDebugger": "legacy/plugins/grokdebugger",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import React from 'react';
import { mountWithIntl } from 'test_utils/enzyme_helpers';
import { UICapabilities } from 'ui/capabilities';
import { Space } from '../../../../../../spaces/common/model/space';
import { Feature } from '../../../../../../xpack_main/types';
import { Feature } from '../../../../../../../../plugins/features/server';
import { RawKibanaPrivileges, Role } from '../../../../../common/model';
import { actionsFactory } from '../../../../../server/lib/authorization/actions';
import { privilegesFactory } from '../../../../../server/lib/authorization/privileges';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import React, { ChangeEvent, Component, Fragment, HTMLProps } from 'react';
import { UICapabilities } from 'ui/capabilities';
import { toastNotifications } from 'ui/notify';
import { Space } from '../../../../../../spaces/common/model/space';
import { Feature } from '../../../../../../xpack_main/types';
import { Feature } from '../../../../../../../../plugins/features/server';
import {
KibanaPrivileges,
RawKibanaPrivileges,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
import { FormattedMessage, InjectedIntl } from '@kbn/i18n/react';
import _ from 'lodash';
import React, { Component } from 'react';
import { Feature } from '../../../../../../../../../xpack_main/types';
import { Feature } from '../../../../../../../../../../../plugins/features/server';
import { FeaturesPrivileges, KibanaPrivileges, Role } from '../../../../../../../../common/model';
import {
AllowedPrivilege,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { InjectedIntl } from '@kbn/i18n/react';
import React, { Component } from 'react';
import { UICapabilities } from 'ui/capabilities';
import { Space } from '../../../../../../../../spaces/common/model/space';
import { Feature } from '../../../../../../../../xpack_main/types';
import { Feature } from '../../../../../../../../../../plugins/features/server';
import { KibanaPrivileges, Role } from '../../../../../../../common/model';
import { KibanaPrivilegeCalculatorFactory } from '../../../../../../lib/kibana_privilege_calculator';
import { RoleValidator } from '../../../lib/validate_role';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { EuiButtonGroup, EuiButtonGroupProps, EuiComboBox, EuiSuperSelect } from '@elastic/eui';
import React from 'react';
import { mountWithIntl, shallowWithIntl } from 'test_utils/enzyme_helpers';
import { Feature } from '../../../../../../../../../xpack_main/types';
import { Feature } from '../../../../../../../../../../../plugins/features/server';
import { KibanaPrivileges, Role } from '../../../../../../../../common/model';
import { KibanaPrivilegeCalculatorFactory } from '../../../../../../../lib/kibana_privilege_calculator';
import { SimplePrivilegeSection } from './simple_privilege_section';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import { FormattedMessage, InjectedIntl } from '@kbn/i18n/react';
import React, { Component, Fragment } from 'react';

import { Feature } from '../../../../../../../../../xpack_main/types';
import { Feature } from '../../../../../../../../../../../plugins/features/server';
import { KibanaPrivileges, Role, RoleKibanaPrivilege } from '../../../../../../../../common/model';
import { KibanaPrivilegeCalculatorFactory } from '../../../../../../../lib/kibana_privilege_calculator';
import { isGlobalPrivilegeDefinition } from '../../../../../../../lib/privilege_utils';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { EuiButtonEmpty, EuiInMemoryTable } from '@elastic/eui';
import React from 'react';
import { mountWithIntl } from 'test_utils/enzyme_helpers';
import { Space } from '../../../../../../../../../spaces/common/model/space';
import { Feature } from '../../../../../../../../../xpack_main/types';
import { Feature } from '../../../../../../../../../../../plugins/features/server';
import { KibanaPrivileges, Role } from '../../../../../../../../common/model';
import { KibanaPrivilegeCalculatorFactory } from '../../../../../../..//lib/kibana_privilege_calculator';
import { PrivilegeMatrix } from './privilege_matrix';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { FormattedMessage, InjectedIntl } from '@kbn/i18n/react';
import React, { Component, Fragment } from 'react';
import { Space } from '../../../../../../../../../spaces/common/model/space';
import { SpaceAvatar } from '../../../../../../../../../spaces/public/components';
import { Feature } from '../../../../../../../../../xpack_main/types';
import { Feature } from '../../../../../../../../../../../plugins/features/server';
import { FeaturesPrivileges, Role } from '../../../../../../../../common/model';
import { CalculatedPrivilege } from '../../../../../../../lib/kibana_privilege_calculator';
import { isGlobalPrivilegeDefinition } from '../../../../../../../lib/privilege_utils';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
import { FormattedMessage, InjectedIntl } from '@kbn/i18n/react';
import React, { Component, Fragment } from 'react';
import { Space } from '../../../../../../../../../spaces/common/model/space';
import { Feature } from '../../../../../../../../../xpack_main/types';
import { Feature } from '../../../../../../../../../../../plugins/features/server';
import { KibanaPrivileges, Role } from '../../../../../../../../common/model';
import {
AllowedPrivilege,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import _ from 'lodash';
import React, { Component, Fragment } from 'react';
import { UICapabilities } from 'ui/capabilities';
import { Space } from '../../../../../../../../../spaces/common/model/space';
import { Feature } from '../../../../../../../../../xpack_main/types';
import { Feature } from '../../../../../../../../../../../plugins/features/server';
import { KibanaPrivileges, Role } from '../../../../../../../../common/model';
import { KibanaPrivilegeCalculatorFactory } from '../../../../../../../lib/kibana_privilege_calculator';
import { isReservedRole } from '../../../../../../../lib/role_utils';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const routeDefinition = (action) => ({
return kfetch({ method: 'get', pathname: '/api/security/v1/esPrivileges/builtin' });
},
features() {
return kfetch({ method: 'get', pathname: '/api/features/v1' }).catch(e => {
return kfetch({ method: 'get', pathname: '/api/features' }).catch(e => {
// TODO: This check can be removed once all of these `resolve` entries are moved out of Angular and into the React app.
const unauthorizedForFeatures = _.get(e, 'body.statusCode') === 404;
if (unauthorizedForFeatures) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
import { isString } from 'lodash';
import { UICapabilities } from 'ui/capabilities';
import { uiCapabilitiesRegex } from '../../../../../xpack_main/types';
import { uiCapabilitiesRegex } from '../../../../../../../plugins/features/server';

export class UIActions {
private readonly prefix: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { Server } from 'hapi';
import { AuthorizationService } from './service';

import { Feature } from '../../../../xpack_main/types';
import { Feature } from '../../../../../../plugins/features/server';
import { XPackMainPlugin } from '../../../../xpack_main/xpack_main';
import { actionsFactory } from './actions';
import { initAppAuthorization } from './app_authorization';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { Actions } from '.';
import { Feature } from '../../../../xpack_main/types';
import { Feature } from '../../../../../../plugins/features/server';
import { disableUICapabilitesFactory } from './disable_ui_capabilities';

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

import { flatten, isObject, mapValues } from 'lodash';
import { UICapabilities } from 'ui/capabilities';
import { Feature } from '../../../../xpack_main/types';
import { Feature } from '../../../../../../plugins/features/server';
import { Actions } from './actions';
import { CheckPrivilegesAtResourceResponse } from './check_privileges';
import { CheckPrivilegesDynamically } from './check_privileges_dynamically';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import {
Feature,
FeatureKibanaPrivileges,
} from '../../../../../../xpack_main/server/lib/feature_registry/feature_registry';
import { Feature, FeatureKibanaPrivileges } from '../../../../../../../../plugins/features/server';
import { BaseFeaturePrivilegeBuilder } from './feature_privilege_builder';

export class FeaturePrivilegeApiBuilder extends BaseFeaturePrivilegeBuilder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import {
Feature,
FeatureKibanaPrivileges,
} from '../../../../../../xpack_main/server/lib/feature_registry/feature_registry';
import { Feature, FeatureKibanaPrivileges } from '../../../../../../../../plugins/features/server';
import { BaseFeaturePrivilegeBuilder } from './feature_privilege_builder';

export class FeaturePrivilegeAppBuilder extends BaseFeaturePrivilegeBuilder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import {
Feature,
FeatureKibanaPrivileges,
} from '../../../../../../xpack_main/server/lib/feature_registry/feature_registry';
import { Feature, FeatureKibanaPrivileges } from '../../../../../../../../plugins/features/server';
import { BaseFeaturePrivilegeBuilder } from './feature_privilege_builder';

export class FeaturePrivilegeCatalogueBuilder extends BaseFeaturePrivilegeBuilder {
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 { Feature, FeatureKibanaPrivileges } from '../../../../../../xpack_main/types';
import { Feature, FeatureKibanaPrivileges } from '../../../../../../../../plugins/features/server';
import { Actions } from '../../actions';

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

import { flatten } from 'lodash';
import { Feature, FeatureKibanaPrivileges } from '../../../../../../xpack_main/types';
import { Feature, FeatureKibanaPrivileges } from '../../../../../../../../plugins/features/server';
import { Actions } from '../../actions';
import { FeaturePrivilegeApiBuilder } from './api';
import { FeaturePrivilegeAppBuilder } from './app';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import {
Feature,
FeatureKibanaPrivileges,
} from '../../../../../../xpack_main/server/lib/feature_registry/feature_registry';
import { Feature, FeatureKibanaPrivileges } from '../../../../../../../../plugins/features/server';
import { BaseFeaturePrivilegeBuilder } from './feature_privilege_builder';

export class FeaturePrivilegeManagementBuilder extends BaseFeaturePrivilegeBuilder {
Expand Down
Loading

0 comments on commit 9d69b72

Please sign in to comment.