Skip to content

Commit

Permalink
Use TS types vs config-schema in common & public
Browse files Browse the repository at this point in the history
Move all @kbn/config-schema usage to server
  • Loading branch information
John Schulz committed Feb 18, 2020
1 parent b907ff8 commit 64fc710
Show file tree
Hide file tree
Showing 21 changed files with 432 additions and 221 deletions.
19 changes: 0 additions & 19 deletions x-pack/plugins/ingest_manager/common/constants/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,5 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { schema } from '@kbn/config-schema';

export const PLUGIN_ID = 'ingestManager';

export const config = {
exposeToBrowser: {
epm: true,
fleet: true,
},
schema: schema.object({
enabled: schema.boolean({ defaultValue: false }),
epm: schema.object({
enabled: schema.boolean({ defaultValue: false }),
registryUrl: schema.uri({ defaultValue: 'https://epr-staging.elastic.co' }),
}),
fleet: schema.object({
enabled: schema.boolean({ defaultValue: false }),
defaultOutputHost: schema.string({ defaultValue: 'http://localhost:9200' }),
}),
}),
};
14 changes: 11 additions & 3 deletions x-pack/plugins/ingest_manager/common/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { TypeOf } from '@kbn/config-schema';

export * from './models';
export * from './rest_spec';
import { config } from '../constants';

export type IngestManagerConfigType = TypeOf<typeof config.schema>;
export interface IngestManagerConfigType {
enabled: boolean;
epm: {
enabled: boolean;
registryUrl: string;
};
fleet: {
enabled: boolean;
defaultOutputHost: string;
};
}
38 changes: 16 additions & 22 deletions x-pack/plugins/ingest_manager/common/types/models/agent_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,30 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { schema, TypeOf } from '@kbn/config-schema';

import { DatasourceSchema } from './datasource';

export enum AgentConfigStatus {
Active = 'active',
Inactive = 'inactive',
}

const AgentConfigBaseSchema = {
name: schema.string(),
namespace: schema.string(),
description: schema.maybe(schema.string()),
};
interface AgentConfigBaseSchema {
name: string;
namespace: string;
description?: string;
}

export const NewAgentConfigSchema = schema.object({
...AgentConfigBaseSchema,
});
export type NewAgentConfigSchema = AgentConfigBaseSchema;

export const AgentConfigSchema = schema.object({
...AgentConfigBaseSchema,
id: schema.string(),
status: schema.oneOf([
schema.literal(AgentConfigStatus.Active),
schema.literal(AgentConfigStatus.Inactive),
]),
datasources: schema.oneOf([schema.arrayOf(schema.string()), schema.arrayOf(DatasourceSchema)]),
updated_on: schema.string(),
updated_by: schema.string(),
});
export type AgentConfigSchema = AgentConfigBaseSchema & {
id: string;
status: AgentConfigStatus;
datasources: Array<string | DatasourceSchema>;
updated_on: string;
updated_by: string;
};

export type NewAgentConfig = TypeOf<typeof NewAgentConfigSchema>;
export type NewAgentConfig = NewAgentConfigSchema;

export type AgentConfig = TypeOf<typeof AgentConfigSchema>;
export type AgentConfig = AgentConfigSchema;
88 changes: 32 additions & 56 deletions x-pack/plugins/ingest_manager/common/types/models/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,65 +3,41 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { schema, TypeOf } from '@kbn/config-schema';

export enum InputType {
Etc = 'etc',
Log = 'log',
MetricDocker = 'metric/docker',
MetricSystem = 'metric/system',
interface DatasourceBaseSchema {
name: string;
namespace: string;
read_alias: string;
agent_config_id: string;
package: {
assets: Array<{
id: string;
type: string;
}>;
description: string;
name: string;
title: string;
version: string;
};
streams: Array<{
config: Record<string, any>;
input: {
type: string;
config: Record<string, any>;
fields: Array<Record<string, any>>;
ilm_policy: string;
index_template: string;
ingest_pipelines: string[];
};
output_id: string;
processors: string[];
}>;
}

const DatasourceBaseSchema = {
name: schema.string(),
namespace: schema.maybe(schema.string()),
read_alias: schema.maybe(schema.string()),
agent_config_id: schema.string(),
package: schema.maybe(
schema.object({
assets: schema.arrayOf(
schema.object({
id: schema.string(),
type: schema.string(),
})
),
description: schema.string(),
name: schema.string(),
title: schema.string(),
version: schema.string(),
})
),
streams: schema.arrayOf(
schema.object({
config: schema.recordOf(schema.string(), schema.any()),
input: schema.object({
type: schema.oneOf([
schema.literal(InputType.Etc),
schema.literal(InputType.Log),
schema.literal(InputType.MetricDocker),
schema.literal(InputType.MetricSystem),
]),
config: schema.recordOf(schema.string(), schema.any()),
fields: schema.maybe(schema.arrayOf(schema.recordOf(schema.string(), schema.any()))),
ilm_policy: schema.maybe(schema.string()),
index_template: schema.maybe(schema.string()),
ingest_pipelines: schema.maybe(schema.arrayOf(schema.string())),
}),
output_id: schema.string(),
processors: schema.maybe(schema.arrayOf(schema.string())),
})
),
};
export type NewDatasourceSchema = DatasourceBaseSchema;

export const NewDatasourceSchema = schema.object({
...DatasourceBaseSchema,
});
export type DatasourceSchema = DatasourceBaseSchema & { id: string };

export const DatasourceSchema = schema.object({
...DatasourceBaseSchema,
id: schema.string(),
});
export type NewDatasource = NewDatasourceSchema;

export type NewDatasource = TypeOf<typeof NewDatasourceSchema>;

export type Datasource = TypeOf<typeof DatasourceSchema>;
export type Datasource = DatasourceSchema;
42 changes: 19 additions & 23 deletions x-pack/plugins/ingest_manager/common/types/models/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,31 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { schema, TypeOf } from '@kbn/config-schema';

export enum OutputType {
Elasticsearch = 'elasticsearch',
}

const OutputBaseSchema = {
name: schema.string(),
type: schema.oneOf([schema.literal(OutputType.Elasticsearch)]),
username: schema.maybe(schema.string()),
password: schema.maybe(schema.string()),
index_name: schema.maybe(schema.string()),
ingest_pipeline: schema.maybe(schema.string()),
hosts: schema.maybe(schema.arrayOf(schema.string())),
api_key: schema.maybe(schema.string()),
admin_username: schema.maybe(schema.string()),
admin_password: schema.maybe(schema.string()),
config: schema.maybe(schema.recordOf(schema.string(), schema.any())),
};
interface OutputBaseSchema {
name: string;
type: OutputType;
username?: string;
password?: string;
index_name?: string;
ingest_pipeline?: string;
hosts?: string[];
api_key?: string;
admin_username?: string;
admin_password?: string;
config?: Record<string, any>;
}

export const NewOutputSchema = schema.object({
...OutputBaseSchema,
});
export type NewOutputSchema = OutputBaseSchema;

export const OutputSchema = schema.object({
...OutputBaseSchema,
id: schema.string(),
});
export type OutputSchema = OutputBaseSchema & {
id: string;
};

export type NewOutput = TypeOf<typeof NewOutputSchema>;
export type NewOutput = NewOutputSchema;

export type Output = TypeOf<typeof OutputSchema>;
export type Output = OutputSchema;
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { schema } from '@kbn/config-schema';
import { AgentConfig, NewAgentConfigSchema } from '../models';
import { ListWithKuerySchema } from './common';

export const GetAgentConfigsRequestSchema = {
query: ListWithKuerySchema,
};
export interface GetAgentConfigsRequestSchema {
query: ListWithKuerySchema;
}

export interface GetAgentConfigsResponse {
items: AgentConfig[];
Expand All @@ -19,41 +18,40 @@ export interface GetAgentConfigsResponse {
success: boolean;
}

export const GetOneAgentConfigRequestSchema = {
params: schema.object({
agentConfigId: schema.string(),
}),
};
export interface GetOneAgentConfigRequestSchema {
params: {
agentConfigId: string;
};
}

export interface GetOneAgentConfigResponse {
item: AgentConfig;
success: boolean;
}

export const CreateAgentConfigRequestSchema = {
body: NewAgentConfigSchema,
};
export interface CreateAgentConfigRequestSchema {
body: NewAgentConfigSchema;
}

export interface CreateAgentConfigResponse {
item: AgentConfig;
success: boolean;
}

export const UpdateAgentConfigRequestSchema = {
...GetOneAgentConfigRequestSchema,
body: NewAgentConfigSchema,
export type UpdateAgentConfigRequestSchema = GetOneAgentConfigRequestSchema & {
body: NewAgentConfigSchema;
};

export interface UpdateAgentConfigResponse {
item: AgentConfig;
success: boolean;
}

export const DeleteAgentConfigsRequestSchema = {
body: schema.object({
agentConfigIds: schema.arrayOf(schema.string()),
}),
};
export interface DeleteAgentConfigsRequestSchema {
body: {
agentConfigIds: string[];
};
}

export type DeleteAgentConfigsResponse = Array<{
id: string;
Expand Down
13 changes: 6 additions & 7 deletions x-pack/plugins/ingest_manager/common/types/rest_spec/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { schema, TypeOf } from '@kbn/config-schema';

export const ListWithKuerySchema = schema.object({
page: schema.number({ defaultValue: 1 }),
perPage: schema.number({ defaultValue: 20 }),
kuery: schema.maybe(schema.string()),
});
export interface ListWithKuerySchema {
page: number;
perPage: number;
kuery?: string;
}

export type ListWithKuery = TypeOf<typeof ListWithKuerySchema>;
export type ListWithKuery = ListWithKuerySchema;
38 changes: 18 additions & 20 deletions x-pack/plugins/ingest_manager/common/types/rest_spec/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,32 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { schema } from '@kbn/config-schema';
import { NewDatasourceSchema } from '../models';
import { ListWithKuerySchema } from './common';

export const GetDatasourcesRequestSchema = {
query: ListWithKuerySchema,
};
export interface GetDatasourcesRequestSchema {
query: ListWithKuerySchema;
}

export const GetOneDatasourceRequestSchema = {
params: schema.object({
datasourceId: schema.string(),
}),
};
export interface GetOneDatasourceRequestSchema {
params: {
datasourceId: string;
};
}

export const CreateDatasourceRequestSchema = {
body: NewDatasourceSchema,
};
export interface CreateDatasourceRequestSchema {
body: NewDatasourceSchema;
}

export const UpdateDatasourceRequestSchema = {
...GetOneDatasourceRequestSchema,
body: NewDatasourceSchema,
export type UpdateDatasourceRequestSchema = GetOneDatasourceRequestSchema & {
body: NewDatasourceSchema;
};

export const DeleteDatasourcesRequestSchema = {
body: schema.object({
datasourceIds: schema.arrayOf(schema.string()),
}),
};
export interface DeleteDatasourcesRequestSchema {
body: {
datasourceIds: string[];
};
}

export type DeleteDatasourcesResponse = Array<{
id: string;
Expand Down
Loading

0 comments on commit 64fc710

Please sign in to comment.