Skip to content

Commit

Permalink
poc
Browse files Browse the repository at this point in the history
  • Loading branch information
legrego committed Jun 1, 2020
1 parent d9ac048 commit 460d24e
Show file tree
Hide file tree
Showing 41 changed files with 921 additions and 248 deletions.
7 changes: 6 additions & 1 deletion src/core/server/capabilities/merge_capabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { merge } from 'lodash';
import { Capabilities } from './types';

export const mergeCapabilities = (...sources: Array<Partial<Capabilities>>): Capabilities =>
merge({}, ...sources, (a: any, b: any) => {
merge({}, ...sources, (a: any, b: any, key: any) => {
if (
(typeof a === 'boolean' && typeof b === 'object') ||
(typeof a === 'object' && typeof b === 'boolean')
Expand All @@ -32,4 +32,9 @@ export const mergeCapabilities = (...sources: Array<Partial<Capabilities>>): Cap
if (typeof a === 'boolean' && typeof b === 'boolean' && a !== b) {
throw new Error(`conflict trying to merge booleans with different values`);
}

// if (typeof a === 'object' && typeof b === 'object' && key === 'management') {
// console.log('INSIDE MANAGEMENT FOR MERGING');
// return merge({}, a, b);
// }
});
2 changes: 1 addition & 1 deletion x-pack/plugins/apm/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export class APMPlugin implements Plugin<APMPluginSetup> {
elasticCloud: createElasticCloudInstructions(plugins.cloud),
};
});
plugins.features.registerFeature(APM_FEATURE);
plugins.features.registerKibanaFeature(APM_FEATURE);

createApmApi().init(core, {
config$: mergedConfig$,
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/beats_management/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"requiredPlugins": [
"data",
"licensing",
"management"
"management",
"features"
],
"optionalPlugins": [
"security"
Expand Down
37 changes: 36 additions & 1 deletion x-pack/plugins/beats_management/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { CoreSetup } from 'kibana/server';
import { beatsManagementConfigSchema } from '../common';
import { PluginSetupContract as FeaturesPluginSetup } from '../../features/server';

export const config = {
schema: beatsManagementConfigSchema,
Expand All @@ -16,8 +18,41 @@ export const config = {
},
};

interface SetupDeps {
features: FeaturesPluginSetup;
}

export const plugin = () => ({
setup() {},
setup(core: CoreSetup, { features }: SetupDeps) {
features.registerElasticsearchFeature({
id: 'beats_management',
management: {
ingest: ['beats_management'],
},
privileges: {
all: {
ui: [],
management: {
ingest: ['beats_management'],
},
requiredClusterPrivileges: [],
requiredIndexPrivileges: {
['.management-beats']: ['all'],
},
},
read: {
ui: [],
management: {
ingest: ['beats_management'],
},
requiredClusterPrivileges: [],
requiredIndexPrivileges: {
['.management-beats']: ['all'],
},
},
},
});
},
start() {},
stop() {},
});
2 changes: 1 addition & 1 deletion x-pack/plugins/canvas/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class CanvasPlugin implements Plugin {
coreSetup.savedObjects.registerType(customElementType);
coreSetup.savedObjects.registerType(workpadType);

plugins.features.registerFeature({
plugins.features.registerKibanaFeature({
id: 'canvas',
name: 'Canvas',
order: 400,
Expand Down
98 changes: 98 additions & 0 deletions x-pack/plugins/features/common/es_feature.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* 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 { RecursiveReadonly } from '@kbn/utility-types';
import { FeatureKibanaPrivileges } from './feature_kibana_privileges';
import { FeatureElasticsearchPrivileges } from './feature_elasticsearch_privileges';

/**
* Interface for registering an Elasticsearch feature.
* Feature registration allows plugins to hide their applications based
* on configured cluster privileges.
*/
export interface ElasticsearchFeatureConfig {
/**
* Unique identifier for this feature.
* This identifier is also used when generating UI Capabilities.
*
* @see UICapabilities
*/
id: string;

/**
* Optional array of supported licenses.
* If omitted, all licenses are allowed.
* This does not restrict access to your feature based on license.
* Its only purpose is to inform the space and roles UIs on which features to display.
*/
validLicenses?: Array<'basic' | 'standard' | 'gold' | 'platinum' | 'enterprise' | 'trial'>;

/**
* Management sections associated with this feature.
*
* @example
* ```ts
* // Enables access to the "Advanced Settings" management page within the Kibana section
* management: {
* kibana: ['settings']
* }
* ```
*/
management?: {
[sectionId: string]: string[];
};

/**
* If this feature includes a catalogue entry, you can specify them here to control visibility based on the current space.
*
*/
catalogue?: string[];

/**
* Feature privilege definition.
*
* @example
* ```ts
* {
* all: {...},
* read: {...}
* }
* ```
* @see FeatureElasticsearchPrivileges
*/
privileges: {
all: FeatureElasticsearchPrivileges;
read: FeatureElasticsearchPrivileges;
};
}

export class ElasticsearchFeature {
constructor(protected readonly config: RecursiveReadonly<ElasticsearchFeatureConfig>) {}

public get id() {
return this.config.id;
}

public get catalogue() {
return this.config.catalogue;
}

public get management() {
return this.config.management;
}

public get validLicenses() {
return this.config.validLicenses;
}

public get privileges() {
return this.config.privileges;
}

public toRaw() {
return { ...this.config } as ElasticsearchFeatureConfig;
}
}
41 changes: 41 additions & 0 deletions x-pack/plugins/features/common/feature_elasticsearch_privileges.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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.
*/

/**
* Elasticsearch Feature privilege definition
*/
export interface FeatureElasticsearchPrivileges {
requiredClusterPrivileges: string[];
requiredIndexPrivileges?: {
[indexName: string]: string[];
};

/**
* A list of UI Capabilities that should be granted to users with this privilege.
* These capabilities will automatically be namespaces within your feature id.
*
* @example
* ```ts
* {
* ui: ['show', 'save']
* }
*
* This translates in the UI to the following (assuming a feature id of "foo"):
* import { uiCapabilities } from 'ui/capabilities';
*
* const canShowApp = uiCapabilities.foo.show;
* const canSave = uiCapabilities.foo.save;
* ```
* Note: Since these are automatically namespaced, you are free to use generic names like "show" and "save".
*
* @see UICapabilities
*/
ui: string[];

management?: {
[sectionId: string]: string[];
};
}
2 changes: 2 additions & 0 deletions x-pack/plugins/features/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

export { FeatureElasticsearchPrivileges } from './feature_elasticsearch_privileges';
export { FeatureKibanaPrivileges } from './feature_kibana_privileges';
export { ElasticsearchFeature, ElasticsearchFeatureConfig } from './es_feature';
export { Feature, FeatureConfig } from './feature';
export {
SubFeature,
Expand Down
Loading

0 comments on commit 460d24e

Please sign in to comment.