-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add platinum licensing check to Meta Engines table/call #11
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* 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 { licensingMock } from '../../../../licensing/public/mocks'; | ||
|
||
export const mockLicenseContext = { | ||
license: licensingMock.createLicense(), | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,38 +9,49 @@ import ReactDOM from 'react-dom'; | |
import { BrowserRouter, Route, Redirect } from 'react-router-dom'; | ||
|
||
import { CoreStart, AppMountParams, HttpHandler } from 'src/core/public'; | ||
import { ClientConfigType } from '../plugin'; | ||
import { ClientConfigType, PluginsSetup } from '../plugin'; | ||
import { TSetBreadcrumbs } from './shared/kibana_breadcrumbs'; | ||
import { ILicense } from '../../../../licensing/public'; | ||
import { LicenseProvider } from './shared/licensing'; | ||
|
||
import { AppSearch } from './app_search'; | ||
|
||
export interface IKibanaContext { | ||
enterpriseSearchUrl?: string; | ||
http(): HttpHandler; | ||
setBreadCrumbs(): TSetBreadcrumbs; | ||
license$: Observable<ILicense>; | ||
} | ||
|
||
export const KibanaContext = React.createContext(); | ||
|
||
export const renderApp = (core: CoreStart, params: AppMountParams, config: ClientConfigType) => { | ||
export const renderApp = ( | ||
core: CoreStart, | ||
params: AppMountParams, | ||
config: ClientConfigType, | ||
plugins: PluginsSetup | ||
) => { | ||
ReactDOM.render( | ||
<KibanaContext.Provider | ||
value={{ | ||
http: core.http, | ||
enterpriseSearchUrl: config.host, | ||
setBreadcrumbs: core.chrome.setBreadcrumbs, | ||
license$: plugins.licensing.license$, | ||
}} | ||
> | ||
<BrowserRouter basename={params.appBasePath}> | ||
<Route exact path="/"> | ||
{/* This will eventually contain an Enterprise Search landing page, | ||
and we'll also actually have a /workplace_search route */} | ||
<Redirect to="/app_search" /> | ||
</Route> | ||
<Route path="/app_search"> | ||
<AppSearch /> | ||
</Route> | ||
</BrowserRouter> | ||
<LicenseProvider> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that the approach I used was heavily borrowed from the APM plugin's approach - I looked at 2-3 other plugins and how they handled licensing but ended up liking theirs as the most simple/cleanest/easiest to test. I also did briefly play around with munging LicenseProvider into a single KibanaProvider declared within this file, but eventually opted to copy their setup - a separate context file is easier to test and notice the observable subscription in, and it's additionally very possible we might just continue to add contexts over time (although it would also be nice if we could handle that w/ Kea...) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice, I like that you followed the approach the other plugin's use. That seems to make the most sense to me as well. We don't have Kea yet, right? This could definitely be ported over at some point whenever we get there. It would probably be cleaner than mixing Contexts + Kea stores. |
||
<BrowserRouter basename={params.appBasePath}> | ||
<Route exact path="/"> | ||
{/* This will eventually contain an Enterprise Search landing page, | ||
and we'll also actually have a /workplace_search route */} | ||
<Redirect to="/app_search" /> | ||
</Route> | ||
<Route path="/app_search"> | ||
<AppSearch /> | ||
</Route> | ||
</BrowserRouter> | ||
</LicenseProvider> | ||
</KibanaContext.Provider>, | ||
params.element | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export { LicenseContext, LicenseProvider, ILicenseContext } from './license_context'; | ||
export { hasPlatinumLicense } from './license_checks'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* 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 { hasPlatinumLicense } from './license_checks'; | ||
|
||
describe('hasPlatinumLicense', () => { | ||
it('is true for platinum licenses', () => { | ||
expect(hasPlatinumLicense({ isActive: true, type: 'platinum' })).toEqual(true); | ||
}); | ||
|
||
it('is true for enterprise licenses', () => { | ||
expect(hasPlatinumLicense({ isActive: true, type: 'enterprise' })).toEqual(true); | ||
}); | ||
|
||
it('is true for trial licenses', () => { | ||
expect(hasPlatinumLicense({ isActive: true, type: 'platinum' })).toEqual(true); | ||
}); | ||
|
||
it('is false if the current license is expired', () => { | ||
expect(hasPlatinumLicense({ isActive: false, type: 'platinum' })).toEqual(false); | ||
expect(hasPlatinumLicense({ isActive: false, type: 'enterprise' })).toEqual(false); | ||
expect(hasPlatinumLicense({ isActive: false, type: 'trial' })).toEqual(false); | ||
}); | ||
|
||
it('is false for licenses below platinum', () => { | ||
expect(hasPlatinumLicense({ isActive: true, type: 'basic' })).toEqual(false); | ||
expect(hasPlatinumLicense({ isActive: false, type: 'standard' })).toEqual(false); | ||
expect(hasPlatinumLicense({ isActive: true, type: 'gold' })).toEqual(false); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* 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 { ILicense } from '../../../../../../licensing/public'; | ||
|
||
export const hasPlatinumLicense = (license: ILicenseContext) => { | ||
return license?.isActive && ['platinum', 'enterprise', 'trial'].includes(license?.type); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* 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 React, { useContext } from 'react'; | ||
|
||
import { mountWithKibanaContext } from '../../__mocks__'; | ||
import { LicenseContext, ILicenseContext } from './'; | ||
|
||
describe('LicenseProvider', () => { | ||
const MockComponent: React.FC<> = () => { | ||
const { license } = useContext(LicenseContext) as ILicenseContext; | ||
return <div className="license-test">{license.type}</div>; | ||
}; | ||
|
||
it('renders children', () => { | ||
const wrapper = mountWithKibanaContext( | ||
<LicenseContext.Provider value={{ license: { type: 'basic' } }}> | ||
<MockComponent /> | ||
</LicenseContext.Provider> | ||
); | ||
|
||
expect(wrapper.find('.license-test')).toHaveLength(1); | ||
expect(wrapper.text()).toEqual('basic'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would have liked to potentially add a test that mocks the observable changing data and the basic text changing to 'trial' or some such, but I'm not sure how to do so. Open to ideas if anyone has them! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No ideas off of the top of my head. |
||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* 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 React, { useContext } from 'react'; | ||
import useObservable from 'react-use/lib/useObservable'; | ||
|
||
import { KibanaContext, IKibanaContext } from '../../'; | ||
|
||
import { ILicense } from '../../../../licensing/public'; | ||
|
||
export interface ILicenseContext { | ||
license?: ILicense; | ||
} | ||
|
||
export const LicenseContext = React.createContext(); | ||
|
||
export const LicenseProvider: React.FC<> = ({ children }) => { | ||
// Listen for changes to license subscription | ||
const { license$ } = useContext(KibanaContext) as IKibanaContext; | ||
const license = useObservable(license$); | ||
|
||
// Render rest of application and pass down license via context | ||
return <LicenseContext.Provider value={{ license }} children={children} />; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Depending on how often we use licensing context in the future, I might as a tech debt for some day just rename
mountWithKibanaContext
tomountWithContext
and nest a<LicenseContext.Provider>
in there by default, so we don't have to do it by handThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point.