Skip to content

Commit

Permalink
remove static registers
Browse files Browse the repository at this point in the history
  • Loading branch information
mshustov committed Apr 16, 2020
1 parent be8380e commit 9e58fe0
Show file tree
Hide file tree
Showing 19 changed files with 36 additions and 258 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,4 @@ export interface HttpResources
| Property | Type | Description |
| --- | --- | --- |
| [register](./kibana-plugin-core-server.httpresources.register.md) | <code>&lt;P, Q, B&gt;(route: RouteConfig&lt;P, Q, B, 'get'&gt;, handler: HttpResourcesRequestHandler&lt;P, Q, B&gt;) =&gt; void</code> | To register a route handler executing passed function to form response. |
| [registerAnonymousCoreApp](./kibana-plugin-core-server.httpresources.registeranonymouscoreapp.md) | <code>(route: StaticHttpResourcesRenderOptions) =&gt; void</code> | To register a route handler rendering HTML bootstrapping Kibana application without retrieving user-specific information. |
| [registerCoreApp](./kibana-plugin-core-server.httpresources.registercoreapp.md) | <code>(route: StaticHttpResourcesRenderOptions) =&gt; void</code> | To register a route handler rendering HTML bootstrapping Kibana application. |

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion docs/development/core/server/kibana-plugin-core-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
| [SessionStorage](./kibana-plugin-core-server.sessionstorage.md) | Provides an interface to store and retrieve data across requests. |
| [SessionStorageCookieOptions](./kibana-plugin-core-server.sessionstoragecookieoptions.md) | Configuration used to create HTTP session storage based on top of cookie mechanism. |
| [SessionStorageFactory](./kibana-plugin-core-server.sessionstoragefactory.md) | SessionStorage factory to bind one to an incoming request |
| [StaticHttpResourcesRenderOptions](./kibana-plugin-core-server.statichttpresourcesrenderoptions.md) | Options for static HttpResources declaration |
| [StatusServiceSetup](./kibana-plugin-core-server.statusservicesetup.md) | API for accessing status of Core and this plugin's dependencies as well as for customizing this plugin's status. |
| [StringValidationRegex](./kibana-plugin-core-server.stringvalidationregex.md) | StringValidation with regex object |
| [StringValidationRegexString](./kibana-plugin-core-server.stringvalidationregexstring.md) | StringValidation as regex string |
Expand Down

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions src/core/server/http_resources/http_resources_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import { httpServerMock } from '../http/http_server.mocks';
import { HttpResources, HttpResourcesServiceToolkit } from './types';

const createHttpResourcesMock = (): jest.Mocked<HttpResources> => ({
registerCoreApp: jest.fn(),
registerAnonymousCoreApp: jest.fn(),
register: jest.fn(),
});

Expand Down
130 changes: 0 additions & 130 deletions src/core/server/http_resources/http_resources_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,136 +43,6 @@ describe('HttpResources service', () => {
service = new HttpResourcesService(coreContext);
router = httpServiceMock.createRouter();
});
describe('registerCoreApp', () => {
it('registers core app with route config', async () => {
const { createRegistrar } = await service.setup(setupDeps);
const { registerCoreApp } = createRegistrar(router);
registerCoreApp({ path: '/' });

const [[routerConfig]] = router.get.mock.calls;
expect(routerConfig).toEqual({ path: '/', validate: false });
});

it('renders page with user settings and CSP header', async () => {
const { createRegistrar } = await service.setup(setupDeps);
const { registerCoreApp } = createRegistrar(router);
registerCoreApp({ path: '/' });

const [[, routeHandler]] = router.get.mock.calls;

const responseFactory = httpResourcesMock.createResponseFactory();
await routeHandler(context, kibanaRequest, responseFactory);

expect(setupDeps.rendering.render).toHaveBeenCalledWith(
kibanaRequest,
context.core.uiSettings.client,
{
includeUserSettings: true,
}
);

expect(responseFactory.ok).toHaveBeenCalledWith({
body: '<body />',
headers: {
'content-security-policy':
"script-src 'unsafe-eval' 'self'; worker-src blob: 'self'; style-src 'unsafe-inline' 'self'",
},
});
});

it('can attach headers, except the CSP header', async () => {
const { createRegistrar } = await service.setup(setupDeps);
const { registerCoreApp } = createRegistrar(router);
registerCoreApp({
path: '/',
headers: {
'content-security-policy': "script-src 'unsafe-eval'",
'x-kibana': '42',
},
});

const [[, routeHandler]] = router.get.mock.calls;

const responseFactory = httpResourcesMock.createResponseFactory();
await routeHandler(context, kibanaRequest, responseFactory);

expect(responseFactory.ok).toHaveBeenCalledWith({
body: '<body />',
headers: {
'x-kibana': '42',
'content-security-policy':
"script-src 'unsafe-eval' 'self'; worker-src blob: 'self'; style-src 'unsafe-inline' 'self'",
},
});
});
});
describe('registerAnonymousCoreApp', () => {
it('registers core app with route config', async () => {
const { createRegistrar } = await service.setup(setupDeps);
const { registerAnonymousCoreApp } = createRegistrar(router);
registerAnonymousCoreApp({ path: '/' });

const [[routerConfig]] = router.get.mock.calls;
expect(routerConfig).toEqual({
path: '/',
validate: false,
options: { authRequired: false },
});
});

it('renders page with user settings and CSP header', async () => {
const { createRegistrar } = await service.setup(setupDeps);
const { registerAnonymousCoreApp } = createRegistrar(router);
registerAnonymousCoreApp({ path: '/' });

const [[, routeHandler]] = router.get.mock.calls;

const responseFactory = httpResourcesMock.createResponseFactory();
await routeHandler(context, kibanaRequest, responseFactory);

expect(setupDeps.rendering.render).toHaveBeenCalledWith(
kibanaRequest,
context.core.uiSettings.client,
{
includeUserSettings: false,
}
);

expect(responseFactory.ok).toHaveBeenCalledWith({
body: '<body />',
headers: {
'content-security-policy':
"script-src 'unsafe-eval' 'self'; worker-src blob: 'self'; style-src 'unsafe-inline' 'self'",
},
});
});

it('can attach headers, except the CSP header', async () => {
const { createRegistrar } = await service.setup(setupDeps);
const { registerAnonymousCoreApp } = createRegistrar(router);
registerAnonymousCoreApp({
path: '/',
headers: {
'content-security-policy': "script-src 'unsafe-eval'",
'x-kibana': '42',
},
});

const [[, routeHandler]] = router.get.mock.calls;

const responseFactory = httpResourcesMock.createResponseFactory();
await routeHandler(context, kibanaRequest, responseFactory);

expect(responseFactory.ok).toHaveBeenCalledWith({
body: '<body />',
headers: {
'x-kibana': '42',
'content-security-policy':
"script-src 'unsafe-eval' 'self'; worker-src blob: 'self'; style-src 'unsafe-inline' 'self'",
},
});
});
});

describe('register', () => {
describe('renderCoreApp', () => {
Expand Down
34 changes: 9 additions & 25 deletions src/core/server/http_resources/http_resources_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import {
HttpResources,
HttpResourcesResponseOptions,
HttpResourcesRenderOptions,
StaticHttpResourcesRenderOptions,
HttpResourcesRequestHandler,
HttpResourcesServiceToolkit,
} from './types';
Expand All @@ -63,33 +62,18 @@ export class HttpResourcesService implements CoreService<InternalHttpResourcesSe
stop() {}

private createRegistrar(deps: SetupDeps, router: IRouter): HttpResources {
const register = <P, Q, B>(
route: RouteConfig<P, Q, B, 'get'>,
handler: HttpResourcesRequestHandler<P, Q, B>
) => {
return router.get<P, Q, B>(route, (context, request, response) => {
return handler(context, request, {
...response,
...this.createResponseToolkit(deps, context, request, response),
});
});
};

return {
registerCoreApp: (options: StaticHttpResourcesRenderOptions) => {
register({ path: options.path, validate: false }, async (context, request, response) => {
return response.renderCoreApp({ headers: options.headers });
register: <P, Q, B>(
route: RouteConfig<P, Q, B, 'get'>,
handler: HttpResourcesRequestHandler<P, Q, B>
) => {
return router.get<P, Q, B>(route, (context, request, response) => {
return handler(context, request, {
...response,
...this.createResponseToolkit(deps, context, request, response),
});
});
},
registerAnonymousCoreApp: (options: StaticHttpResourcesRenderOptions) => {
register(
{ path: options.path, validate: false, options: { authRequired: false } },
async (context, request, response) => {
return response.renderAnonymousCoreApp({ headers: options.headers });
}
);
},
register,
};
}

Expand Down
1 change: 0 additions & 1 deletion src/core/server/http_resources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,4 @@ export {
HttpResourcesRequestHandler,
HttpResources,
InternalHttpResourcesSetup,
StaticHttpResourcesRenderOptions,
} from './types';
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,6 @@ describe('http resources service', () => {
await root.shutdown();
});

describe('registerAnonymousCoreApp', () => {
it('renders core application', async () => {
const { http, httpResources } = await root.setup();

const router = http.createRouter('');
const resources = httpResources.createRegistrar(router);
resources.registerAnonymousCoreApp({ path: '/render-anon-core' });

await root.start();
const response = await kbnTestServer.request.get(root, '/render-anon-core').expect(200);

expect(response.text.length).toBeGreaterThan(0);
});
});

describe('renderAnonymousCoreApp', () => {
it('renders core application', async () => {
const { http, httpResources } = await root.setup();
Expand Down
12 changes: 0 additions & 12 deletions src/core/server/http_resources/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,6 @@ import {
RequestHandler,
} from '../http';

/**
* Options for static HttpResources declaration
* @public
*/
export interface StaticHttpResourcesRenderOptions extends HttpResourcesRenderOptions {
path: string;
}

/**
* Allows to configure HTTP response parameters
* @public
Expand Down Expand Up @@ -116,10 +108,6 @@ export interface InternalHttpResourcesSetup {
* @public
*/
export interface HttpResources {
/** To register a route handler rendering HTML bootstrapping Kibana application. */
registerCoreApp: (route: StaticHttpResourcesRenderOptions) => void;
/** To register a route handler rendering HTML bootstrapping Kibana application without retrieving user-specific information. */
registerAnonymousCoreApp: (route: StaticHttpResourcesRenderOptions) => void;
/** To register a route handler executing passed function to form response. */
register: <P, Q, B>(
route: RouteConfig<P, Q, B, 'get'>,
Expand Down
1 change: 0 additions & 1 deletion src/core/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ export {
HttpResourcesResponseOptions,
HttpResourcesServiceToolkit,
HttpResourcesRequestHandler,
StaticHttpResourcesRenderOptions,
} from './http_resources';

export { IRenderOptions } from './rendering';
Expand Down
8 changes: 0 additions & 8 deletions src/core/server/server.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -866,8 +866,6 @@ export type Headers = {
// @public
export interface HttpResources {
register: <P, Q, B>(route: RouteConfig<P, Q, B, 'get'>, handler: HttpResourcesRequestHandler<P, Q, B>) => void;
registerAnonymousCoreApp: (route: StaticHttpResourcesRenderOptions) => void;
registerCoreApp: (route: StaticHttpResourcesRenderOptions) => void;
}

// @public
Expand Down Expand Up @@ -2397,12 +2395,6 @@ export type SharedGlobalConfig = RecursiveReadonly_2<{
// @public
export type StartServicesAccessor<TPluginsStart extends object = object, TStart = unknown> = () => Promise<[CoreStart, TPluginsStart, TStart]>;

// @public
export interface StaticHttpResourcesRenderOptions extends HttpResourcesRenderOptions {
// (undocumented)
path: string;
}

// @public
export interface StatusServiceSetup {
core$: Observable<CoreStatus>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ import { RouteDefinitionParams } from '..';
* Defines routes required for the Account Management view.
*/
export function defineAccountManagementRoutes({ httpResources }: RouteDefinitionParams) {
httpResources.registerCoreApp({ path: '/security/account' });
httpResources.register({ path: '/security/account', validate: false }, (context, req, res) =>
res.renderCoreApp()
);
}
Loading

0 comments on commit 9e58fe0

Please sign in to comment.