kibana/x-pack/plugins/features/server/routes/index.ts
Brandon Kobel 4584a8b570
Elastic License 2.0 (#90099)
* Updating everything except the license headers themselves

* Applying ESLint rules

* Manually replacing the stragglers
2021-02-03 18:12:39 -08:00

47 lines
1.4 KiB
TypeScript

/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { schema } from '@kbn/config-schema';
import type { FeaturesPluginRouter } from '../types';
import { FeatureRegistry } from '../feature_registry';
/**
* Describes parameters used to define HTTP routes.
*/
export interface RouteDefinitionParams {
router: FeaturesPluginRouter;
featureRegistry: FeatureRegistry;
}
export function defineRoutes({ router, featureRegistry }: RouteDefinitionParams) {
router.get(
{
path: '/api/features',
options: { tags: ['access:features'] },
validate: {
query: schema.object({ ignoreValidLicenses: schema.boolean({ defaultValue: false }) }),
},
},
(context, request, response) => {
const currentLicense = context.licensing!.license;
const allFeatures = featureRegistry.getAllKibanaFeatures(
currentLicense,
request.query.ignoreValidLicenses
);
return response.ok({
body: allFeatures
.sort(
(f1, f2) =>
(f1.order ?? Number.MAX_SAFE_INTEGER) - (f2.order ?? Number.MAX_SAFE_INTEGER)
)
.map((feature) => feature.toRaw()),
});
}
);
}