Skip to content

Commit

Permalink
Merge branch 'master' into kertal-pr-2020-05-26-improve-discover-cont…
Browse files Browse the repository at this point in the history
…ext-a11y-test
  • Loading branch information
elasticmachine authored May 28, 2020
2 parents 869dfd4 + 639dbbe commit afb4dd4
Show file tree
Hide file tree
Showing 160 changed files with 2,293 additions and 713 deletions.
1 change: 0 additions & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@
/x-pack/legacy/plugins/security/ @elastic/kibana-security
/x-pack/legacy/plugins/spaces/ @elastic/kibana-security
/x-pack/plugins/spaces/ @elastic/kibana-security
/x-pack/legacy/plugins/encrypted_saved_objects/ @elastic/kibana-security
/x-pack/plugins/encrypted_saved_objects/ @elastic/kibana-security
/x-pack/plugins/security/ @elastic/kibana-security
/x-pack/test/api_integration/apis/security/ @elastic/kibana-security
Expand Down
1 change: 0 additions & 1 deletion src/core/server/legacy/legacy_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,6 @@ export class LegacyService implements CoreService {
uiPlugins: setupDeps.uiPlugins,
elasticsearch: setupDeps.core.elasticsearch,
rendering: setupDeps.core.rendering,
uiSettings: setupDeps.core.uiSettings,
savedObjectsClientProvider: startDeps.core.savedObjects.clientProvider,
legacy: this.legacyInternals,
},
Expand Down
10 changes: 5 additions & 5 deletions src/core/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,21 +247,21 @@ export class Server {
coreId,
'core',
async (context, req, res): Promise<RequestHandlerContext['core']> => {
const savedObjectsClient = this.coreStart!.savedObjects.getScopedClient(req);
const uiSettingsClient = coreSetup.uiSettings.asScopedToClient(savedObjectsClient);
const coreStart = this.coreStart!;
const savedObjectsClient = coreStart.savedObjects.getScopedClient(req);

return {
savedObjects: {
client: savedObjectsClient,
typeRegistry: this.coreStart!.savedObjects.getTypeRegistry(),
typeRegistry: coreStart.savedObjects.getTypeRegistry(),
},
elasticsearch: {
legacy: {
client: coreSetup.elasticsearch.dataClient.asScoped(req),
client: coreStart.elasticsearch.legacy.client.asScoped(req),
},
},
uiSettings: {
client: uiSettingsClient,
client: coreStart.uiSettings.asScopedToClient(savedObjectsClient),
},
};
}
Expand Down
5 changes: 0 additions & 5 deletions src/core/server/ui_settings/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,6 @@ export interface InternalUiSettingsServiceSetup {
* @param settings
*/
register(settings: Record<string, UiSettingsParams>): void;
/**
* Creates uiSettings client with provided *scoped* saved objects client {@link IUiSettingsClient}
* @param savedObjectsClient
*/
asScopedToClient(savedObjectsClient: SavedObjectsClientContract): IUiSettingsClient;
}

/** @public */
Expand Down
3 changes: 0 additions & 3 deletions src/core/server/ui_settings/ui_settings_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,8 @@ const createClientMock = () => {
const createSetupMock = () => {
const mocked: jest.Mocked<InternalUiSettingsServiceSetup> = {
register: jest.fn(),
asScopedToClient: jest.fn(),
};

mocked.asScopedToClient.mockReturnValue(createClientMock());

return mocked;
};

Expand Down
28 changes: 0 additions & 28 deletions src/core/server/ui_settings/ui_settings_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,34 +67,6 @@ describe('uiSettings', () => {
expect(setupDeps.savedObjects.registerType).toHaveBeenCalledWith(uiSettingsType);
});

describe('#asScopedToClient', () => {
it('passes saved object type "config" to UiSettingsClient', async () => {
const setup = await service.setup(setupDeps);
setup.asScopedToClient(savedObjectsClient);
expect(MockUiSettingsClientConstructor).toBeCalledTimes(1);
expect(MockUiSettingsClientConstructor.mock.calls[0][0].type).toBe('config');
});

it('passes overrides to UiSettingsClient', async () => {
const setup = await service.setup(setupDeps);
setup.asScopedToClient(savedObjectsClient);
expect(MockUiSettingsClientConstructor).toBeCalledTimes(1);
expect(MockUiSettingsClientConstructor.mock.calls[0][0].overrides).toBe(overrides);
expect(MockUiSettingsClientConstructor.mock.calls[0][0].overrides).toEqual(overrides);
});

it('passes a copy of set defaults to UiSettingsClient', async () => {
const setup = await service.setup(setupDeps);

setup.register(defaults);
setup.asScopedToClient(savedObjectsClient);
expect(MockUiSettingsClientConstructor).toBeCalledTimes(1);

expect(MockUiSettingsClientConstructor.mock.calls[0][0].defaults).toEqual(defaults);
expect(MockUiSettingsClientConstructor.mock.calls[0][0].defaults).not.toBe(defaults);
});
});

describe('#register', () => {
it('throws if registers the same key twice', async () => {
const setup = await service.setup(setupDeps);
Expand Down
1 change: 0 additions & 1 deletion src/core/server/ui_settings/ui_settings_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ export class UiSettingsService

return {
register: this.register.bind(this),
asScopedToClient: this.getScopedClientFactory(),
};
}

Expand Down
1 change: 0 additions & 1 deletion src/legacy/server/kbn_server.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ export interface KibanaCore {
legacy: ILegacyInternals;
rendering: LegacyServiceSetupDeps['core']['rendering'];
uiPlugins: UiPlugins;
uiSettings: LegacyServiceSetupDeps['core']['uiSettings'];
savedObjectsClientProvider: LegacyServiceStartDeps['core']['savedObjects']['clientProvider'];
};
env: {
Expand Down
5 changes: 3 additions & 2 deletions src/legacy/ui/ui_render/ui_render_mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,10 @@ export function uiRenderMixin(kbnServer, server, config) {
rendering,
legacy,
savedObjectsClientProvider: savedObjects,
uiSettings: { asScopedToClient },
} = kbnServer.newPlatform.__internals;
const uiSettings = asScopedToClient(savedObjects.getClient(h.request));
const uiSettings = kbnServer.newPlatform.start.core.uiSettings.asScopedToClient(
savedObjects.getClient(h.request)
);
const vars = await legacy.getVars(app.getId(), h.request, {
apmConfig: getApmConfig(app),
...overrides,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ describe('uiSettingsMixin()', () => {
decorate: sinon.spy((type: keyof Decorators, name: string, value: any) => {
decorations[type][name] = value;
}),
newPlatform: {
setup: {
core: {
uiSettings: {
register: sinon.stub(),
},
},
},
},
};

// "promise" returned from kbnServer.ready()
Expand All @@ -70,13 +79,6 @@ describe('uiSettingsMixin()', () => {
server,
uiExports: { uiSettingDefaults },
ready: sinon.stub().returns(readyPromise),
newPlatform: {
__internals: {
uiSettings: {
register: sinon.stub(),
},
},
},
};

uiSettingsMixin(kbnServer, server);
Expand All @@ -92,10 +94,10 @@ describe('uiSettingsMixin()', () => {
afterEach(() => sandbox.restore());

it('passes uiSettingsDefaults to the new platform', () => {
const { kbnServer } = setup();
sinon.assert.calledOnce(kbnServer.newPlatform.__internals.uiSettings.register);
const { server } = setup();
sinon.assert.calledOnce(server.newPlatform.setup.core.uiSettings.register);
sinon.assert.calledWithExactly(
kbnServer.newPlatform.__internals.uiSettings.register,
server.newPlatform.setup.core.uiSettings.register,
uiSettingDefaults
);
});
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/ui/ui_settings/ui_settings_mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function uiSettingsMixin(kbnServer, server) {
return acc;
}, {});

kbnServer.newPlatform.__internals.uiSettings.register(mergedUiSettingDefaults);
server.newPlatform.setup.core.uiSettings.register(mergedUiSettingDefaults);

server.decorate('server', 'uiSettingsServiceFactory', (options = {}) => {
return uiSettingsServiceFactory(server, options);
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/ui/ui_settings/ui_settings_service_factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ export function uiSettingsServiceFactory(
server: Legacy.Server,
options: UiSettingsServiceFactoryOptions
): IUiSettingsClient {
return server.newPlatform.__internals.uiSettings.asScopedToClient(options.savedObjectsClient);
return server.newPlatform.start.core.uiSettings.asScopedToClient(options.savedObjectsClient);
}
2 changes: 0 additions & 2 deletions x-pack/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { dashboardMode } from './legacy/plugins/dashboard_mode';
import { beats } from './legacy/plugins/beats_management';
import { maps } from './legacy/plugins/maps';
import { spaces } from './legacy/plugins/spaces';
import { encryptedSavedObjects } from './legacy/plugins/encrypted_saved_objects';
import { ingestManager } from './legacy/plugins/ingest_manager';

module.exports = function (kibana) {
Expand All @@ -25,7 +24,6 @@ module.exports = function (kibana) {
dashboardMode(kibana),
beats(kibana),
maps(kibana),
encryptedSavedObjects(kibana),
ingestManager(kibana),
];
};
46 changes: 0 additions & 46 deletions x-pack/legacy/plugins/encrypted_saved_objects/index.ts

This file was deleted.

27 changes: 8 additions & 19 deletions x-pack/legacy/plugins/security/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import { resolve } from 'path';
import { Server } from 'src/legacy/server/kbn_server';
import { KibanaRequest, LegacyRequest } from '../../../../src/core/server';
// @ts-ignore
import { AuditLogger } from '../../server/lib/audit_logger';
// @ts-ignore
import { watchStatusAndLicenseToInitialize } from '../../server/lib/watch_status_and_license_to_initialize';
import { AuthenticatedUser, SecurityPluginSetup } from '../../../plugins/security/server';

Expand All @@ -33,28 +31,24 @@ function getSecurityPluginSetup(server: Server) {
export const security = (kibana: Record<string, any>) =>
new kibana.Plugin({
id: 'security',
configPrefix: 'xpack.security',
publicDir: resolve(__dirname, 'public'),
require: ['kibana', 'elasticsearch', 'xpack_main'],
require: ['kibana', 'xpack_main'],
configPrefix: 'xpack.security',
uiExports: {
hacks: ['plugins/security/hacks/legacy'],
injectDefaultVars: (server: Server) => {
return { enableSpaceAwarePrivileges: server.config().get('xpack.spaces.enabled') };
},
},

// This config is only used by `AuditLogger` and should be removed as soon as `AuditLogger`
// is migrated to Kibana Platform.
config(Joi: Root) {
return Joi.object({
enabled: Joi.boolean().default(true),
audit: Joi.object({ enabled: Joi.boolean().default(false) }).default(),
})
.unknown()
.default();
},

uiExports: {
hacks: ['plugins/security/hacks/legacy'],
injectDefaultVars: (server: Server) => {
return { enableSpaceAwarePrivileges: server.config().get('xpack.spaces.enabled') };
},
},

async postInit(server: Server) {
watchStatusAndLicenseToInitialize(server.plugins.xpack_main, this, async () => {
const xpackInfo = server.plugins.xpack_main.info;
Expand All @@ -67,11 +61,6 @@ export const security = (kibana: Record<string, any>) =>
async init(server: Server) {
const securityPlugin = getSecurityPluginSetup(server);

const xpackInfo = server.plugins.xpack_main.info;
securityPlugin.__legacyCompat.registerLegacyAPI({
auditLogger: new AuditLogger(server, 'security', server.config(), xpackInfo),
});

server.expose({
getUser: async (request: LegacyRequest) =>
securityPlugin.authc.getCurrentUser(KibanaRequest.from(request)),
Expand Down
20 changes: 0 additions & 20 deletions x-pack/legacy/plugins/spaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,9 @@ import { resolve } from 'path';
import KbnServer, { Server } from 'src/legacy/server/kbn_server';
import { Legacy } from 'kibana';
import { KibanaRequest } from '../../../../src/core/server';
import { SpacesServiceSetup } from '../../../plugins/spaces/server';
import { SpacesPluginSetup } from '../../../plugins/spaces/server';
// @ts-ignore
import { AuditLogger } from '../../server/lib/audit_logger';
import { wrapError } from './server/lib/errors';

export interface LegacySpacesPlugin {
getSpaceId: (request: Legacy.Request) => ReturnType<SpacesServiceSetup['getSpaceId']>;
getActiveSpace: (request: Legacy.Request) => ReturnType<SpacesServiceSetup['getActiveSpace']>;
spaceIdToNamespace: SpacesServiceSetup['spaceIdToNamespace'];
namespaceToSpaceId: SpacesServiceSetup['namespaceToSpaceId'];
getBasePath: SpacesServiceSetup['getBasePath'];
}

export const spaces = (kibana: Record<string, any>) =>
new kibana.Plugin({
id: 'spaces',
Expand Down Expand Up @@ -79,15 +68,6 @@ export const spaces = (kibana: Record<string, any>) =>
throw new Error('New Platform XPack Spaces plugin is not available.');
}

const { registerLegacyAPI } = spacesPlugin.__legacyCompat;

registerLegacyAPI({
auditLogger: {
create: (pluginId: string) =>
new AuditLogger(server, pluginId, server.config(), server.plugins.xpack_main.info),
},
});

server.expose('getSpaceId', (request: Legacy.Request) =>
spacesPlugin.spacesService.getSpaceId(request)
);
Expand Down
40 changes: 0 additions & 40 deletions x-pack/legacy/server/lib/audit_logger.js

This file was deleted.

Loading

0 comments on commit afb4dd4

Please sign in to comment.