Skip to content

Commit

Permalink
[SIEM] Adds ability to infer the newsfeed.enabled setting (#56236) (#…
Browse files Browse the repository at this point in the history
…56266)

* Always return a contract from the newsfeed plugin

Without a contract, dependent plugins have no way of knowing whether the
plugin is enabled or not as the contract will always be undefined.

* Export newsfeed contract types from public index

So that dependent plugins can use them.

* Declare newsfeed as an optional dependency of SIEM

We're going to use the availability of the newsfeed plugin as part of our
determination for whether or not to show the security newsfeed. If users
set `newsfeed.enabled: false`, the plugin will be unavailable and the
security feed will not be shown.

* Respect global newsfeed.enabled config in Security newsfeed

The presence of the newsfeed plugin means that newsfeed.enabled is true.
If both that and our local setting are true, we will show the Security
feed.

* Prefer object type over empty interface

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
rylnd and elasticmachine authored Jan 29, 2020
1 parent 50cd4e2 commit 5ec64d5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/plugins/newsfeed/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
*/

import { PluginInitializerContext } from 'src/core/public';
import { NewsfeedPublicPlugin } from './plugin';
import { Setup, Start, NewsfeedPublicPlugin } from './plugin';

export { Setup, Start };

export function plugin(initializerContext: PluginInitializerContext) {
return new NewsfeedPublicPlugin(initializerContext);
Expand Down
10 changes: 7 additions & 3 deletions src/plugins/newsfeed/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import { NewsfeedPluginInjectedConfig } from '../types';
import { NewsfeedNavButton, NewsfeedApiFetchResult } from './components/newsfeed_header_nav_button';
import { getApi } from './lib/api';

export type Setup = void;
export type Start = void;
export type Setup = object;
export type Start = object;

export class NewsfeedPublicPlugin implements Plugin<Setup, Start> {
private readonly kibanaVersion: string;
Expand All @@ -38,14 +38,18 @@ export class NewsfeedPublicPlugin implements Plugin<Setup, Start> {
this.kibanaVersion = initializerContext.env.packageInfo.version;
}

public setup(core: CoreSetup): Setup {}
public setup(core: CoreSetup): Setup {
return {};
}

public start(core: CoreStart): Start {
const api$ = this.fetchNewsfeed(core);
core.chrome.navControls.registerRight({
order: 1000,
mount: target => this.mount(api$, target),
});

return {};
}

public stop() {
Expand Down
12 changes: 8 additions & 4 deletions x-pack/legacy/plugins/siem/public/components/news_feed/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,22 @@ import React, { useEffect, useState } from 'react';
import chrome from 'ui/chrome';

import { fetchNews, getNewsFeedUrl, getNewsItemsFromApiResponse } from './helpers';
import { useUiSetting$ } from '../../lib/kibana';
import { useKibana, useUiSetting$ } from '../../lib/kibana';
import { NewsFeed } from './news_feed';
import { NewsItem } from './types';

export const StatefulNewsFeed = React.memo<{
enableNewsFeedSetting: string;
newsFeedSetting: string;
}>(({ enableNewsFeedSetting, newsFeedSetting }) => {
const kibanaNewsfeedEnabled = useKibana().services.newsfeed;
const [enableNewsFeed] = useUiSetting$<boolean>(enableNewsFeedSetting);
const [newsFeedUrlSetting] = useUiSetting$<string>(newsFeedSetting);
const [news, setNews] = useState<NewsItem[] | null>(null);

// respect kibana's global newsfeed.enabled setting
const newsfeedEnabled = kibanaNewsfeedEnabled && enableNewsFeed;

const newsFeedUrl = getNewsFeedUrl({
newsFeedUrlSetting,
getKibanaVersion: chrome.getKibanaVersion,
Expand All @@ -42,16 +46,16 @@ export const StatefulNewsFeed = React.memo<{
}
};

if (enableNewsFeed) {
if (newsfeedEnabled) {
fetchData();
}

return () => {
canceled = true;
};
}, [enableNewsFeed, newsFeedUrl]);
}, [newsfeedEnabled, newsFeedUrl]);

return <>{enableNewsFeed ? <NewsFeed news={news} /> : null}</>;
return <>{newsfeedEnabled ? <NewsFeed news={news} /> : null}</>;
});

StatefulNewsFeed.displayName = 'StatefulNewsFeed';
2 changes: 2 additions & 0 deletions x-pack/legacy/plugins/siem/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import { HomePublicPluginSetup } from '../../../../../src/plugins/home/public';
import { DataPublicPluginStart } from '../../../../../src/plugins/data/public';
import { IEmbeddableStart } from '../../../../../src/plugins/embeddable/public';
import { Start as NewsfeedStart } from '../../../../../src/plugins/newsfeed/public';
import { Start as InspectorStart } from '../../../../../src/plugins/inspector/public';
import { IUiActionsStart } from '../../../../../src/plugins/ui_actions/public';
import { UsageCollectionSetup } from '../../../../../src/plugins/usage_collection/public';
Expand All @@ -29,6 +30,7 @@ export interface StartPlugins {
data: DataPublicPluginStart;
embeddable: IEmbeddableStart;
inspector: InspectorStart;
newsfeed?: NewsfeedStart;
uiActions: IUiActionsStart;
}
export type StartServices = CoreStart & StartPlugins;
Expand Down

0 comments on commit 5ec64d5

Please sign in to comment.