Skip to content

Commit

Permalink
Expose spaces plugin function signatures in TypeScript (elastic#42133)
Browse files Browse the repository at this point in the history
* Expose spaces plugin function signatures

* Apply PR feedback
  • Loading branch information
mikecote committed Jul 30, 2019
1 parent c5ef51f commit c35f1d4
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { SpacesPlugin } from '../../../../spaces/types';
import { SpacesPlugin } from '../../../../spaces';
import { OptionalPlugin } from '../../../../../server/lib/optional_plugin';
import { checkPrivilegesDynamicallyWithRequestFactory } from './check_privileges_dynamically';

Expand All @@ -18,6 +18,10 @@ test(`checkPrivileges.atSpace when spaces is enabled`, async () => {
const mockSpaces = {
isEnabled: true,
getSpaceId: jest.fn().mockReturnValue(spaceId),
spaceIdToNamespace: jest.fn(),
namespaceToSpaceId: jest.fn(),
getBasePath: jest.fn(),
getScopedSpacesClient: jest.fn(),
} as OptionalPlugin<SpacesPlugin>;
const request = Symbol();
const privilegeOrPrivileges = ['foo', 'bar'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { Legacy } from 'kibana';
import { CheckPrivilegesAtResourceResponse, CheckPrivilegesWithRequest } from './check_privileges';

/*
Expand All @@ -12,22 +13,22 @@ import { CheckPrivilegesAtResourceResponse, CheckPrivilegesWithRequest } from '.
* you may not use this file except in compliance with the Elastic License.
*/

import { SpacesPlugin } from '../../../../spaces/types';
import { SpacesPlugin } from '../../../../spaces';
import { OptionalPlugin } from '../../../../../server/lib/optional_plugin';

export type CheckPrivilegesDynamically = (
privilegeOrPrivileges: string | string[]
) => Promise<CheckPrivilegesAtResourceResponse>;

export type CheckPrivilegesDynamicallyWithRequest = (
request: Record<string, any>
request: Legacy.Request
) => CheckPrivilegesDynamically;

export function checkPrivilegesDynamicallyWithRequestFactory(
checkPrivilegesWithRequest: CheckPrivilegesWithRequest,
spaces: OptionalPlugin<SpacesPlugin>
): CheckPrivilegesDynamicallyWithRequest {
return function checkPrivilegesDynamicallyWithRequest(request: Record<string, any>) {
return function checkPrivilegesDynamicallyWithRequest(request: Legacy.Request) {
const checkPrivileges = checkPrivilegesWithRequest(request);
return async function checkPrivilegesDynamically(privilegeOrPrivileges: string | string[]) {
if (spaces.isEnabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { Server } from 'hapi';

import { getClient } from '../../../../../server/lib/get_client_shield';
import { SpacesPlugin } from '../../../../spaces/types';
import { SpacesPlugin } from '../../../../spaces';
import { XPackFeature, XPackMainPlugin } from '../../../../xpack_main/xpack_main';
import { APPLICATION_PREFIX } from '../../../common/constants';
import { OptionalPlugin } from '../../../../../server/lib/optional_plugin';
Expand Down
10 changes: 10 additions & 0 deletions x-pack/legacy/plugins/spaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ import {
} from './server/new_platform/plugin';
import { initSpacesRequestInterceptors } from './server/lib/request_interceptors';
import { SecurityPlugin } from '../security';
import { SpacesServiceSetup } from './server/new_platform/spaces_service/spaces_service';

export interface SpacesPlugin {
getSpaceId: SpacesServiceSetup['getSpaceId'];
spaceIdToNamespace: SpacesServiceSetup['spaceIdToNamespace'];
namespaceToSpaceId: SpacesServiceSetup['namespaceToSpaceId'];
getBasePath: SpacesServiceSetup['getBasePath'];
getScopedSpacesClient: SpacesServiceSetup['scopedClient'];
}

export const spaces = (kibana: Record<string, any>) =>
new kibana.Plugin({
id: 'spaces',
Expand Down
10 changes: 0 additions & 10 deletions x-pack/legacy/plugins/spaces/types.d.ts

This file was deleted.

0 comments on commit c35f1d4

Please sign in to comment.