Skip to content

Commit d99ee26

Browse files
committed
Add featureUsage API to licensing context provider
1 parent 94321cc commit d99ee26

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

x-pack/plugins/licensing/server/licensing_route_handler_context.test.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ import { BehaviorSubject } from 'rxjs';
88
import { licenseMock } from '../common/licensing.mock';
99

1010
import { createRouteHandlerContext } from './licensing_route_handler_context';
11+
import { featureUsageMock } from './services/feature_usage_service.mock';
1112

1213
describe('createRouteHandlerContext', () => {
1314
it('returns a function providing the last license value', async () => {
1415
const firstLicense = licenseMock.createLicense();
1516
const secondLicense = licenseMock.createLicense();
1617
const license$ = new BehaviorSubject(firstLicense);
1718

18-
const routeHandler = createRouteHandlerContext(license$);
19+
const routeHandler = createRouteHandlerContext(license$, featureUsageMock.createStart());
1920

2021
const firstCtx = await routeHandler({} as any, {} as any, {} as any);
2122
license$.next(secondLicense);
@@ -24,4 +25,14 @@ describe('createRouteHandlerContext', () => {
2425
expect(firstCtx.license).toBe(firstLicense);
2526
expect(secondCtx.license).toBe(secondLicense);
2627
});
28+
29+
it('returns a the feature usage API', async () => {
30+
const license$ = new BehaviorSubject(licenseMock.createLicense());
31+
const featureUsage = featureUsageMock.createStart();
32+
33+
const routeHandler = createRouteHandlerContext(license$, featureUsage);
34+
const ctx = await routeHandler({} as any, {} as any, {} as any);
35+
36+
expect(ctx.featureUsage).toBe(featureUsage);
37+
});
2738
});

x-pack/plugins/licensing/server/licensing_route_handler_context.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,21 @@ import { Observable } from 'rxjs';
99
import { take } from 'rxjs/operators';
1010

1111
import { ILicense } from '../common/types';
12+
import { FeatureUsageServiceStart } from './services';
1213

1314
/**
1415
* Create a route handler context for access to Kibana license information.
1516
* @param license$ An observable of a License instance.
1617
* @public
1718
*/
1819
export function createRouteHandlerContext(
19-
license$: Observable<ILicense>
20+
license$: Observable<ILicense>,
21+
featureUsage: FeatureUsageServiceStart
2022
): IContextProvider<RequestHandler<any, any, any>, 'licensing'> {
2123
return async function licensingRouteHandlerContext() {
22-
return { license: await license$.pipe(take(1)).toPromise() };
24+
return {
25+
license: await license$.pipe(take(1)).toPromise(),
26+
featureUsage,
27+
};
2328
};
2429
}

x-pack/plugins/licensing/server/plugin.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,10 @@ export class LicensingPlugin implements Plugin<LicensingPluginSetup, LicensingPl
128128
pollingFrequency.asMilliseconds()
129129
);
130130

131-
core.http.registerRouteHandlerContext('licensing', createRouteHandlerContext(license$));
131+
core.http.registerRouteHandlerContext(
132+
'licensing',
133+
createRouteHandlerContext(license$, this.featureUsage.start())
134+
);
132135

133136
registerRoutes(core.http.createRouter(), core.getStartServices);
134137
core.http.registerOnPreResponse(createOnPreResponseHandler(refresh, license$));

x-pack/plugins/licensing/server/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export interface RawLicense {
4242

4343
declare module 'src/core/server' {
4444
interface RequestHandlerContext {
45+
featureUsage: FeatureUsageServiceStart;
4546
licensing: {
4647
license: ILicense;
4748
};

0 commit comments

Comments
 (0)