Skip to content

Commit

Permalink
Merge branch 'master' into observability-alerts-section-style-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine authored Sep 16, 2020
2 parents 0ed2eb5 + b3aabe9 commit e1e7172
Show file tree
Hide file tree
Showing 58 changed files with 3,105 additions and 186 deletions.
4 changes: 4 additions & 0 deletions docs/developer/plugin-list.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,10 @@ in their infrastructure.
|This plugins adopts some conventions in addition to or in place of conventions in Kibana (at the time of the plugin's creation):
|{kib-repo}blob/{branch}/x-pack/plugins/xpack_legacy/README.md[xpackLegacy]
|Contains HTTP endpoints and UiSettings that are slated for removal.
|===
include::{kibana-root}/src/plugins/dashboard/README.asciidoc[leveloffset=+1]
Expand Down
4 changes: 2 additions & 2 deletions src/core/server/context/context_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import type { PublicMethodsOf } from '@kbn/utility-types';
import { ContextService, ContextSetup } from './context_service';
import { contextMock } from '../../utils/context.mock';

const createSetupContractMock = () => {
const createSetupContractMock = (mockContext = {}) => {
const setupContract: jest.Mocked<ContextSetup> = {
createContextContainer: jest.fn().mockImplementation(() => contextMock.create()),
createContextContainer: jest.fn().mockImplementation(() => contextMock.create(mockContext)),
};
return setupContract;
};
Expand Down
1 change: 1 addition & 0 deletions src/core/server/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export { typeRegistryMock as savedObjectsTypeRegistryMock } from './saved_object
export { uiSettingsServiceMock } from './ui_settings/ui_settings_service.mock';
export { metricsServiceMock } from './metrics/metrics_service.mock';
export { renderingMock } from './rendering/rendering_service.mock';
export { contextServiceMock } from './context/context_service.mock';

export function pluginInitializerContextConfigMock<T>(config: T) {
const globalConfig: SharedGlobalConfig = {
Expand Down
8 changes: 3 additions & 5 deletions src/core/utils/context.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ import { IContextContainer } from './context';

export type ContextContainerMock = jest.Mocked<IContextContainer<any>>;

const createContextMock = () => {
const createContextMock = (mockContext = {}) => {
const contextMock: ContextContainerMock = {
registerContext: jest.fn(),
createHandler: jest.fn((id, handler) => (...args: any[]) =>
Promise.resolve(handler({}, ...args))
),
createHandler: jest.fn(),
};
contextMock.createHandler.mockImplementation((pluginId, handler) => (...args) =>
handler({}, ...args)
handler(mockContext, ...args)
);
return contextMock;
};
Expand Down
3 changes: 1 addition & 2 deletions x-pack/legacy/plugins/xpack_main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { resolve } from 'path';
import { mirrorPluginStatus } from '../../server/lib/mirror_plugin_status';
import { setupXPackMain } from './server/lib/setup_xpack_main';
import { xpackInfoRoute, settingsRoute } from './server/routes/api/v1';
import { xpackInfoRoute } from './server/routes/api/v1';

export const xpackMain = (kibana) => {
return new kibana.Plugin({
Expand All @@ -29,7 +29,6 @@ export const xpackMain = (kibana) => {

// register routes
xpackInfoRoute(server);
settingsRoute(server, this.kbnServer);
},
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@
*/

export { xpackInfoRoute } from './xpack_info';
export { settingsRoute } from './settings';
68 changes: 0 additions & 68 deletions x-pack/legacy/plugins/xpack_main/server/routes/api/v1/settings.js

This file was deleted.

1 change: 1 addition & 0 deletions x-pack/plugins/monitoring/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Plugin } from './plugin';
import { configSchema } from './config';
import { deprecations } from './deprecations';

export { KibanaSettingsCollector } from './kibana_monitoring/collectors';
export { MonitoringConfig } from './config';
export const plugin = (initContext: PluginInitializerContext) => new Plugin(initContext);
export const config: PluginConfigDescriptor<TypeOf<typeof configSchema>> = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { Collector } from '../../../../../../src/plugins/usage_collection/server';

import { KIBANA_SETTINGS_TYPE } from '../../../common/constants';
import { MonitoringConfig } from '../../config';

Expand Down Expand Up @@ -38,11 +40,19 @@ export async function checkForEmailValue(
}
}

interface EmailSettingData {
xpack: { default_admin_email: string | null };
}

export interface KibanaSettingsCollector extends Collector<EmailSettingData | undefined> {
getEmailValueStructure(email: string | null): EmailSettingData;
}

export function getSettingsCollector(usageCollection: any, config: MonitoringConfig) {
return usageCollection.makeStatsCollector({
type: KIBANA_SETTINGS_TYPE,
isReady: () => true,
async fetch() {
async fetch(this: KibanaSettingsCollector) {
let kibanaSettingsData;
const defaultAdminEmail = await checkForEmailValue(config);

Expand All @@ -64,7 +74,7 @@ export function getSettingsCollector(usageCollection: any, config: MonitoringCon
// returns undefined if there was no result
return kibanaSettingsData;
},
getEmailValueStructure(email: string) {
getEmailValueStructure(email: string | null) {
return {
xpack: {
default_admin_email: email,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { UsageCollectionSetup } from 'src/plugins/usage_collection/server';
import { getSettingsCollector } from './get_settings_collector';
import { MonitoringConfig } from '../../config';

export { KibanaSettingsCollector } from './get_settings_collector';

export function registerCollectors(
usageCollection: UsageCollectionSetup,
config: MonitoringConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const telemetryIndexPattern = 'metrics-endpoint.telemetry-*';
export const LIMITED_CONCURRENCY_ENDPOINT_ROUTE_TAG = 'endpoint:limited-concurrency';
export const LIMITED_CONCURRENCY_ENDPOINT_COUNT = 100;

export const TRUSTED_APPS_SUPPORTED_OS_TYPES: readonly string[] = ['macos', 'windows', 'linux'];
export const TRUSTED_APPS_LIST_API = '/api/endpoint/trusted_apps';
export const TRUSTED_APPS_CREATE_API = '/api/endpoint/trusted_apps';
export const TRUSTED_APPS_DELETE_API = '/api/endpoint/trusted_apps/{id}';
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe('When invoking Trusted Apps Schema', () => {
os: 'windows',
entries: [
{
field: 'path',
field: 'process.path',
type: 'match',
operator: 'included',
value: 'c:/programs files/Anti-Virus',
Expand Down Expand Up @@ -111,14 +111,6 @@ describe('When invoking Trusted Apps Schema', () => {
expect(body.validate(bodyMsg)).toStrictEqual(bodyMsg);
});

it('should validate `description` to be non-empty if defined', () => {
const bodyMsg = {
...getCreateTrustedAppItem(),
description: '',
};
expect(() => body.validate(bodyMsg)).toThrow();
});

it('should validate `os` to to only accept known values', () => {
const bodyMsg = {
...getCreateTrustedAppItem(),
Expand Down Expand Up @@ -202,7 +194,7 @@ describe('When invoking Trusted Apps Schema', () => {
};
expect(() => body.validate(bodyMsg2)).toThrow();

['hash', 'path'].forEach((field) => {
['process.hash.*', 'process.path'].forEach((field) => {
const bodyMsg3 = {
...getCreateTrustedAppItem(),
entries: [
Expand All @@ -217,9 +209,55 @@ describe('When invoking Trusted Apps Schema', () => {
});
});

it.todo('should validate `entry.type` is limited to known values');
it('should validate `entry.type` is limited to known values', () => {
const bodyMsg = {
...getCreateTrustedAppItem(),
entries: [
{
...getTrustedAppItemEntryItem(),
type: 'invalid',
},
],
};
expect(() => body.validate(bodyMsg)).toThrow();

// Allow `match`
const bodyMsg2 = {
...getCreateTrustedAppItem(),
entries: [
{
...getTrustedAppItemEntryItem(),
type: 'match',
},
],
};
expect(() => body.validate(bodyMsg2)).not.toThrow();
});

it('should validate `entry.operator` is limited to known values', () => {
const bodyMsg = {
...getCreateTrustedAppItem(),
entries: [
{
...getTrustedAppItemEntryItem(),
operator: 'invalid',
},
],
};
expect(() => body.validate(bodyMsg)).toThrow();

it.todo('should validate `entry.operator` is limited to known values');
// Allow `match`
const bodyMsg2 = {
...getCreateTrustedAppItem(),
entries: [
{
...getTrustedAppItemEntryItem(),
operator: 'included',
},
],
};
expect(() => body.validate(bodyMsg2)).not.toThrow();
});

it('should validate `entry.value` required', () => {
const { value, ...entry } = getTrustedAppItemEntryItem();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ export const GetTrustedAppsRequestSchema = {
export const PostTrustedAppCreateRequestSchema = {
body: schema.object({
name: schema.string({ minLength: 1 }),
description: schema.maybe(schema.string({ minLength: 1 })),
description: schema.maybe(schema.string({ minLength: 0, defaultValue: '' })),
os: schema.oneOf([schema.literal('linux'), schema.literal('macos'), schema.literal('windows')]),
entries: schema.arrayOf(
schema.object({
field: schema.oneOf([schema.literal('hash'), schema.literal('path')]),
field: schema.oneOf([schema.literal('process.hash.*'), schema.literal('process.path')]),
type: schema.literal('match'),
operator: schema.literal('included'),
value: schema.string({ minLength: 1 }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ export interface PostTrustedAppCreateResponse {
data: TrustedApp;
}

interface MacosLinuxConditionEntry {
field: 'hash' | 'path';
export interface MacosLinuxConditionEntry {
field: 'process.hash.*' | 'process.path';
type: 'match';
operator: 'included';
value: string;
}

type WindowsConditionEntry =
export type WindowsConditionEntry =
| MacosLinuxConditionEntry
| (Omit<MacosLinuxConditionEntry, 'field'> & {
field: 'signer';
field: 'process.code_signature';
});

/** Type for a new Trusted App Entry */
Expand Down
Loading

0 comments on commit e1e7172

Please sign in to comment.