From 3e0190640355aece60439875b59c90655efd429b Mon Sep 17 00:00:00 2001 From: Nicolas Chaulet Date: Thu, 2 Jan 2020 18:00:35 -0500 Subject: [PATCH 1/6] [Fleet] Remove server code from common folder in fleet --- .../plugins/fleet/common/types/domain_data.ts | 122 +++++++++++++++++- .../legacy/plugins/fleet/server/libs/agent.ts | 12 +- .../server/libs/agent_event.contract.test.ts | 2 +- .../plugins/fleet/server/libs/agent_event.ts | 2 +- .../server/libs/agent_status_helper.test.ts | 2 +- .../agent_events/default.contract.test.ts | 2 +- .../repositories/agent_events/default.ts | 2 +- .../server/repositories/agent_events/types.ts | 46 +------ .../server/repositories/agents/default.ts | 2 +- .../fleet/server/repositories/agents/types.ts | 91 ++----------- .../repositories/enrollment_api_keys/types.ts | 2 +- .../fleet/server/routes/agents/actions.ts | 3 +- .../fleet/server/routes/agents/checkin.ts | 2 +- 13 files changed, 143 insertions(+), 147 deletions(-) diff --git a/x-pack/legacy/plugins/fleet/common/types/domain_data.ts b/x-pack/legacy/plugins/fleet/common/types/domain_data.ts index e14d190a360edf..1f5b363c8d10c8 100644 --- a/x-pack/legacy/plugins/fleet/common/types/domain_data.ts +++ b/x-pack/legacy/plugins/fleet/common/types/domain_data.ts @@ -4,11 +4,128 @@ * you may not use this file except in compliance with the Elastic License. */ import * as t from 'io-ts'; +import { AGENT_TYPE_EPHEMERAL, AGENT_TYPE_PERMANENT, AGENT_TYPE_TEMPORARY } from '../constants'; export { Policy, Datasource, Status, Output } from '../../../ingest/server/libs/types'; -import { RuntimeAgent, RuntimeAgentAction } from '../../server/repositories/agents/types'; -import { RuntimeAgentEvent } from '../../server/repositories/agent_events/types'; export { EnrollmentApiKey } from '../../server/repositories/enrollment_api_keys/types'; +const RuntimeAgentActionType = t.union([ + t.literal('POLICY_CHANGE'), + t.literal('DATA_DUMP'), + t.literal('RESUME'), + t.literal('PAUSE'), +]); + +export type AgentActionType = t.TypeOf; + +export const RuntimeAgentActionData = t.interface( + { + type: RuntimeAgentActionType, + }, + 'AgentActionData' +); + +export const RuntimeAgentAction = t.intersection([ + RuntimeAgentActionData, + t.interface( + { + id: t.string, + created_at: t.string, + }, + 'AgentAction' + ), + t.partial({ + data: t.string, + sent_at: t.string, + }), +]); + +export const RuntimeAgentType = t.union([ + t.literal(AGENT_TYPE_PERMANENT), + t.literal(AGENT_TYPE_EPHEMERAL), + t.literal(AGENT_TYPE_TEMPORARY), +]); + +export type AgentType = t.TypeOf; + +export const RuntimeAgentEventType = t.union([ + t.literal('STATE'), + t.literal('ERROR'), + t.literal('ACTION_RESULT'), + t.literal('ACTION'), +]); + +export const RuntimeAgentEventSubtype = t.union([ + // State + t.literal('RUNNING'), + t.literal('STARTING'), + t.literal('IN_PROGRESS'), + t.literal('CONFIG'), + t.literal('FAILED'), + t.literal('STOPPED'), + // Action results + t.literal('DATA_DUMP'), + // Actions + t.literal('ACKNOWLEDGED'), + t.literal('UNKNOWN'), +]); + +export const RuntimeAgentEvent = t.intersection( + [ + t.interface({ + type: RuntimeAgentEventType, + subtype: RuntimeAgentEventSubtype, + timestamp: t.string, + message: t.string, + }), + t.partial({ + payload: t.any, + data: t.string, + action_id: t.string, + policy_id: t.string, + stream_id: t.string, + }), + ], + 'AgentEvent' +); + +export type AgentEvent = t.TypeOf; + +const newAgentProperties = { + type: RuntimeAgentType, + active: t.boolean, +}; +const newAgentOptionalProperties = t.partial({ + parent_id: t.string, + version: t.string, + enrolled_at: t.string, + user_provided_metadata: t.dictionary(t.string, t.string), + local_metadata: t.dictionary(t.string, t.string), + shared_id: t.string, + access_api_key_id: t.string, + access_api_key: t.string, + policy_id: t.string, +}); + +export const RuntimeAgent = t.intersection([ + t.interface({ + ...newAgentProperties, + id: t.string, + actions: t.array(RuntimeAgentAction), + current_error_events: t.array(RuntimeAgentEvent), + }), + t.partial({ + last_updated: t.string, + last_checkin: t.string, + }), + newAgentOptionalProperties, +]); + +export const NewRuntimeAgent = t.intersection([ + t.interface(newAgentProperties), + newAgentOptionalProperties, +]); +export type NewAgent = t.TypeOf; + // Here we create the runtime check for a generic, unknown beat config type. // We can also pass in optional params to create spacific runtime checks that // can be used to validate blocs on the API and UI @@ -39,7 +156,6 @@ export type Agent = t.TypeOf & { status: AgentStatus; }; export type AgentAction = t.TypeOf; -export type AgentEvent = t.TypeOf; export type PolicyUpdatedEvent = | { diff --git a/x-pack/legacy/plugins/fleet/server/libs/agent.ts b/x-pack/legacy/plugins/fleet/server/libs/agent.ts index 4c0adf4c37791b..664ed0a582ea78 100644 --- a/x-pack/legacy/plugins/fleet/server/libs/agent.ts +++ b/x-pack/legacy/plugins/fleet/server/libs/agent.ts @@ -7,20 +7,12 @@ import Boom from 'boom'; import uuid from 'uuid/v4'; import { FrameworkUser } from '../adapters/framework/adapter_types'; -import { - Agent, - AgentAction, - AgentActionType, - AgentsRepository, - AgentType, - NewAgent, - SortOptions, -} from '../repositories/agents/types'; -import { AgentEvent } from '../repositories/agent_events/types'; +import { Agent, AgentAction, AgentsRepository, SortOptions } from '../repositories/agents/types'; import { AgentPolicy } from '../repositories/policies/types'; import { ApiKeyLib } from './api_keys'; import { AgentStatusHelper } from './agent_status_helper'; import { AgentEventLib } from './agent_event'; +import { AgentEvent, AgentType, NewAgent, AgentActionType } from '../../common/types/domain_data'; export class AgentLib { constructor( diff --git a/x-pack/legacy/plugins/fleet/server/libs/agent_event.contract.test.ts b/x-pack/legacy/plugins/fleet/server/libs/agent_event.contract.test.ts index ea5aa806fce691..0b151ab1f0580b 100644 --- a/x-pack/legacy/plugins/fleet/server/libs/agent_event.contract.test.ts +++ b/x-pack/legacy/plugins/fleet/server/libs/agent_event.contract.test.ts @@ -17,7 +17,7 @@ import { SODatabaseAdapter } from '../adapters/saved_objects_database/default'; import { FleetServerLib } from './types'; import { compose } from './compose/memorized'; import { Agent } from '../repositories/agents/types'; -import { AgentEvent } from '../repositories/agent_events/types'; +import { AgentEvent } from '../../common/types/domain_data'; jest.mock('./framework'); jest.mock('./policy', () => ({ diff --git a/x-pack/legacy/plugins/fleet/server/libs/agent_event.ts b/x-pack/legacy/plugins/fleet/server/libs/agent_event.ts index 35b30e89a44f94..77cfad9ff047e9 100644 --- a/x-pack/legacy/plugins/fleet/server/libs/agent_event.ts +++ b/x-pack/legacy/plugins/fleet/server/libs/agent_event.ts @@ -6,8 +6,8 @@ import { FrameworkUser } from '../adapters/framework/adapter_types'; import { AgentEventsRepository } from '../repositories/agent_events/default'; -import { AgentEvent } from '../repositories/agent_events/types'; import { Agent } from '../repositories/agents/types'; +import { AgentEvent } from '../../common/types/domain_data'; /** * This is the server lib to manage everything related to policies and agents diff --git a/x-pack/legacy/plugins/fleet/server/libs/agent_status_helper.test.ts b/x-pack/legacy/plugins/fleet/server/libs/agent_status_helper.test.ts index f6048037bfa719..a66276eedfc42b 100644 --- a/x-pack/legacy/plugins/fleet/server/libs/agent_status_helper.test.ts +++ b/x-pack/legacy/plugins/fleet/server/libs/agent_status_helper.test.ts @@ -12,7 +12,7 @@ import { } from '../../common/constants'; import { Agent } from '../repositories/agents/types'; import { AgentStatusHelper } from './agent_status_helper'; -import { AgentEvent } from '../repositories/agent_events/types'; +import { AgentEvent } from '../../common/types/domain_data'; describe('AgentStatusHelper', () => { describe('getAgentStatus', () => { diff --git a/x-pack/legacy/plugins/fleet/server/repositories/agent_events/default.contract.test.ts b/x-pack/legacy/plugins/fleet/server/repositories/agent_events/default.contract.test.ts index 0cd9867a2e3ea9..0571f9ecab7489 100644 --- a/x-pack/legacy/plugins/fleet/server/repositories/agent_events/default.contract.test.ts +++ b/x-pack/legacy/plugins/fleet/server/repositories/agent_events/default.contract.test.ts @@ -11,7 +11,7 @@ import { SODatabaseAdapter as SODatabaseAdapterType } from '../../adapters/saved import { SODatabaseAdapter } from '../../adapters/saved_objects_database/default'; import { MemorizeSODatabaseAdapter } from '../../adapters/saved_objects_database/memorize_adapter'; import { FrameworkUser, internalAuthData } from '../../adapters/framework/adapter_types'; -import { AgentEvent } from '../agent_events/types'; +import { AgentEvent } from '../../../common/types/domain_data'; describe('AgentsEventsRepository', () => { let repository: AgentEventsRepository; diff --git a/x-pack/legacy/plugins/fleet/server/repositories/agent_events/default.ts b/x-pack/legacy/plugins/fleet/server/repositories/agent_events/default.ts index 622805139e78a7..293e6e964791d0 100644 --- a/x-pack/legacy/plugins/fleet/server/repositories/agent_events/default.ts +++ b/x-pack/legacy/plugins/fleet/server/repositories/agent_events/default.ts @@ -9,9 +9,9 @@ import { SODatabaseAdapter } from '../../adapters/saved_objects_database/adapter import { FrameworkUser } from '../../adapters/framework/adapter_types'; import { AgentEventsRepository as AgentEventsRepositoryType, - AgentEvent, AgentEventSOAttributes, } from './types'; +import { AgentEvent } from '../../../common/types/domain_data'; const SO_TYPE = 'agent_events'; diff --git a/x-pack/legacy/plugins/fleet/server/repositories/agent_events/types.ts b/x-pack/legacy/plugins/fleet/server/repositories/agent_events/types.ts index eabc66e6fa59c0..882d28c8b25e83 100644 --- a/x-pack/legacy/plugins/fleet/server/repositories/agent_events/types.ts +++ b/x-pack/legacy/plugins/fleet/server/repositories/agent_events/types.ts @@ -7,47 +7,11 @@ import * as t from 'io-ts'; import { FrameworkUser } from '../../adapters/framework/adapter_types'; -export const RuntimeAgentEventType = t.union([ - t.literal('STATE'), - t.literal('ERROR'), - t.literal('ACTION_RESULT'), - t.literal('ACTION'), -]); - -export const RuntimeAgentEventSubtype = t.union([ - // State - t.literal('RUNNING'), - t.literal('STARTING'), - t.literal('IN_PROGRESS'), - t.literal('CONFIG'), - t.literal('FAILED'), - t.literal('STOPPED'), - // Action results - t.literal('DATA_DUMP'), - // Actions - t.literal('ACKNOWLEDGED'), - t.literal('UNKNOWN'), -]); - -export const RuntimeAgentEvent = t.intersection( - [ - t.interface({ - type: RuntimeAgentEventType, - subtype: RuntimeAgentEventSubtype, - timestamp: t.string, - message: t.string, - }), - t.partial({ - payload: t.any, - data: t.string, - action_id: t.string, - policy_id: t.string, - stream_id: t.string, - }), - ], - 'AgentEvent' -); -export type AgentEvent = t.TypeOf; +import { + RuntimeAgentEventType, + RuntimeAgentEventSubtype, + AgentEvent, +} from '../../../common/types/domain_data'; export const RuntimeAgentEventSOAttributes = t.intersection( [ diff --git a/x-pack/legacy/plugins/fleet/server/repositories/agents/default.ts b/x-pack/legacy/plugins/fleet/server/repositories/agents/default.ts index 84f24eb35d1129..6f19704609a035 100644 --- a/x-pack/legacy/plugins/fleet/server/repositories/agents/default.ts +++ b/x-pack/legacy/plugins/fleet/server/repositories/agents/default.ts @@ -17,10 +17,10 @@ import { Agent, AgentsRepository as AgentsRepositoryType, ListOptions, - NewAgent, SavedObjectAgentAttributes, SortOptions, } from './types'; +import { NewAgent } from '../../../common/types/domain_data'; const SO_TYPE = 'agents'; diff --git a/x-pack/legacy/plugins/fleet/server/repositories/agents/types.ts b/x-pack/legacy/plugins/fleet/server/repositories/agents/types.ts index a043f6ed7f9c73..7e2682a6e9b4aa 100644 --- a/x-pack/legacy/plugins/fleet/server/repositories/agents/types.ts +++ b/x-pack/legacy/plugins/fleet/server/repositories/agents/types.ts @@ -5,88 +5,13 @@ */ import * as t from 'io-ts'; -import { - AGENT_TYPE_EPHEMERAL, - AGENT_TYPE_PERMANENT, - AGENT_TYPE_TEMPORARY, -} from '../../../common/constants'; import { FrameworkUser } from '../../adapters/framework/adapter_types'; -import { RuntimeAgentEvent } from '../agent_events/types'; - -export const RuntimeAgentType = t.union([ - t.literal(AGENT_TYPE_PERMANENT), - t.literal(AGENT_TYPE_EPHEMERAL), - t.literal(AGENT_TYPE_TEMPORARY), -]); - -const RuntimeAgentActionType = t.union([ - t.literal('POLICY_CHANGE'), - t.literal('DATA_DUMP'), - t.literal('RESUME'), - t.literal('PAUSE'), -]); - -export type AgentActionType = t.TypeOf; - -export const RuntimeAgentActionData = t.interface( - { - type: RuntimeAgentActionType, - }, - 'AgentActionData' -); - -export const RuntimeAgentAction = t.intersection([ - RuntimeAgentActionData, - t.interface( - { - id: t.string, - created_at: t.string, - }, - 'AgentAction' - ), - t.partial({ - data: t.string, - sent_at: t.string, - }), -]); - -export type AgentType = t.TypeOf; - -const newAgentProperties = { - type: RuntimeAgentType, - active: t.boolean, -}; - -const newAgentOptionalProperties = t.partial({ - parent_id: t.string, - version: t.string, - enrolled_at: t.string, - user_provided_metadata: t.dictionary(t.string, t.string), - local_metadata: t.dictionary(t.string, t.string), - shared_id: t.string, - access_api_key_id: t.string, - access_api_key: t.string, - policy_id: t.string, -}); - -export const NewRuntimeAgent = t.intersection([ - t.interface(newAgentProperties), - newAgentOptionalProperties, -]); - -export const RuntimeAgent = t.intersection([ - t.interface({ - ...newAgentProperties, - id: t.string, - actions: t.array(RuntimeAgentAction), - current_error_events: t.array(RuntimeAgentEvent), - }), - t.partial({ - last_updated: t.string, - last_checkin: t.string, - }), - newAgentOptionalProperties, -]); +import { + RuntimeAgentType, + RuntimeAgentAction, + RuntimeAgent, + NewAgent, +} from '../../../common/types/domain_data'; export const RuntimeSavedObjectAgentAttributes = t.intersection([ t.partial({ @@ -100,7 +25,8 @@ export const RuntimeSavedObjectAgentAttributes = t.intersection([ current_error_events: t.string, }), t.interface({ - ...newAgentProperties, + type: RuntimeAgentType, + active: t.boolean, id: t.string, user_provided_metadata: t.string, local_metadata: t.string, @@ -110,7 +36,6 @@ export const RuntimeSavedObjectAgentAttributes = t.intersection([ export type SavedObjectAgentAttributes = t.TypeOf; export type Agent = t.TypeOf; -export type NewAgent = t.TypeOf; export type AgentAction = t.TypeOf; diff --git a/x-pack/legacy/plugins/fleet/server/repositories/enrollment_api_keys/types.ts b/x-pack/legacy/plugins/fleet/server/repositories/enrollment_api_keys/types.ts index 6564cf064d9425..1ed7a5fdaa73e2 100644 --- a/x-pack/legacy/plugins/fleet/server/repositories/enrollment_api_keys/types.ts +++ b/x-pack/legacy/plugins/fleet/server/repositories/enrollment_api_keys/types.ts @@ -6,7 +6,7 @@ import * as t from 'io-ts'; import { FrameworkUser } from '../../adapters/framework/adapter_types'; -import { RuntimeAgentType } from '../agents/types'; +import { RuntimeAgentType } from '../../../common/types/domain_data'; export const SAVED_OBJECT_TYPE = 'enrollment_api_keys'; diff --git a/x-pack/legacy/plugins/fleet/server/routes/agents/actions.ts b/x-pack/legacy/plugins/fleet/server/routes/agents/actions.ts index 05db16ca1a5209..208e35174d02a1 100644 --- a/x-pack/legacy/plugins/fleet/server/routes/agents/actions.ts +++ b/x-pack/legacy/plugins/fleet/server/routes/agents/actions.ts @@ -11,8 +11,7 @@ import { PathReporter } from 'io-ts/lib/PathReporter'; import { FrameworkRequest } from '../../adapters/framework/adapter_types'; import { ReturnTypeCreate } from '../../../common/return_types'; import { FleetServerLib } from '../../libs/types'; -import { RuntimeAgentActionData } from '../../repositories/agents/types'; -import { AgentAction } from '../../../common/types/domain_data'; +import { AgentAction, RuntimeAgentActionData } from '../../../common/types/domain_data'; export const createAgentsAddActionRoute = (libs: FleetServerLib) => ({ method: 'POST', diff --git a/x-pack/legacy/plugins/fleet/server/routes/agents/checkin.ts b/x-pack/legacy/plugins/fleet/server/routes/agents/checkin.ts index 1b9a79f9b93d62..37222c2f1660be 100644 --- a/x-pack/legacy/plugins/fleet/server/routes/agents/checkin.ts +++ b/x-pack/legacy/plugins/fleet/server/routes/agents/checkin.ts @@ -11,8 +11,8 @@ import { PathReporter } from 'io-ts/lib/PathReporter'; import { isLeft } from 'fp-ts/lib/Either'; import { FrameworkRequest } from '../../adapters/framework/adapter_types'; import { ReturnTypeCheckin } from '../../../common/return_types'; -import { RuntimeAgentEvent, AgentEvent } from '../../repositories/agent_events/types'; import { FleetServerLib } from '../../libs/types'; +import { AgentEvent, RuntimeAgentEvent } from '../../../common/types/domain_data'; type CheckinRequest = FrameworkRequest<{ payload: { From aeaf1f90fb755da602920ab6e98403fdd0688750 Mon Sep 17 00:00:00 2001 From: Nicolas Chaulet Date: Thu, 2 Jan 2020 19:34:03 -0500 Subject: [PATCH 2/6] [Fleet] Fix typescript issues after master merge --- .../plugins/fleet/public/components/layouts/no_data.tsx | 4 ++-- .../fleet/public/components/navigation/connected_link.tsx | 2 +- x-pack/legacy/plugins/fleet/public/hooks/with_url_state.tsx | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/x-pack/legacy/plugins/fleet/public/components/layouts/no_data.tsx b/x-pack/legacy/plugins/fleet/public/components/layouts/no_data.tsx index e525ea4be46e0d..f98a739ca77d7f 100644 --- a/x-pack/legacy/plugins/fleet/public/components/layouts/no_data.tsx +++ b/x-pack/legacy/plugins/fleet/public/components/layouts/no_data.tsx @@ -14,8 +14,8 @@ interface LayoutProps { modalClosePath?: string; } -export const NoDataLayout: React.FC = withRouter( - ({ actionSection, title, modalClosePath, children, history }) => { +export const NoDataLayout: React.FC = withRouter>( + ({ actionSection, title, modalClosePath, children }) => { return ( diff --git a/x-pack/legacy/plugins/fleet/public/components/navigation/connected_link.tsx b/x-pack/legacy/plugins/fleet/public/components/navigation/connected_link.tsx index 72cc5d6e74dde5..489ee85ffe28ac 100644 --- a/x-pack/legacy/plugins/fleet/public/components/navigation/connected_link.tsx +++ b/x-pack/legacy/plugins/fleet/public/components/navigation/connected_link.tsx @@ -37,4 +37,4 @@ export function ConnectedLinkComponent({ ); } -export const ConnectedLink = withRouter(ConnectedLinkComponent); +export const ConnectedLink = withRouter(ConnectedLinkComponent); diff --git a/x-pack/legacy/plugins/fleet/public/hooks/with_url_state.tsx b/x-pack/legacy/plugins/fleet/public/hooks/with_url_state.tsx index 3760b51f7b1c63..e30650a6ceb17e 100644 --- a/x-pack/legacy/plugins/fleet/public/hooks/with_url_state.tsx +++ b/x-pack/legacy/plugins/fleet/public/hooks/with_url_state.tsx @@ -85,4 +85,4 @@ export class WithURLStateComponent extends React.Compon }); }; } -export const WithUrlState = withRouter(WithURLStateComponent); +export const WithUrlState = withRouter(WithURLStateComponent); From bee7c693f2b8b6ca9b1258556009f367756fd81b Mon Sep 17 00:00:00 2001 From: Nicolas Chaulet Date: Fri, 3 Jan 2020 08:27:24 -0500 Subject: [PATCH 3/6] [Fleet] Remove server code from common folder in fleet --- .../plugins/fleet/common/types/domain_data.ts | 36 ++++++++++++++++- .../fleet/server/libs/__mocks__/api_keys.ts | 8 ++-- .../plugins/fleet/server/libs/api_keys.ts | 8 ++-- .../default.contract.test.ts | 3 +- .../enrollment_api_keys/default.ts | 2 +- .../repositories/enrollment_api_keys/types.ts | 39 +------------------ .../routes/enrollment_api_keys/rules.ts | 2 +- 7 files changed, 50 insertions(+), 48 deletions(-) diff --git a/x-pack/legacy/plugins/fleet/common/types/domain_data.ts b/x-pack/legacy/plugins/fleet/common/types/domain_data.ts index 1f5b363c8d10c8..81db337a13be88 100644 --- a/x-pack/legacy/plugins/fleet/common/types/domain_data.ts +++ b/x-pack/legacy/plugins/fleet/common/types/domain_data.ts @@ -6,7 +6,6 @@ import * as t from 'io-ts'; import { AGENT_TYPE_EPHEMERAL, AGENT_TYPE_PERMANENT, AGENT_TYPE_TEMPORARY } from '../constants'; export { Policy, Datasource, Status, Output } from '../../../ingest/server/libs/types'; -export { EnrollmentApiKey } from '../../server/repositories/enrollment_api_keys/types'; const RuntimeAgentActionType = t.union([ t.literal('POLICY_CHANGE'), @@ -172,3 +171,38 @@ export type PolicyUpdatedEvent = type: 'deleted'; policyId: string; }; + +export const RuntimeEnrollmentRuleData = t.partial( + { + ip_ranges: t.array(t.string), + window_duration: t.interface( + { + from: t.string, + to: t.string, + }, + 'WindowDuration' + ), + types: t.array(RuntimeAgentType), + }, + 'EnrollmentRuleData' +); + +export type EnrollmentRuleData = t.TypeOf; + +export type EnrollmentRule = EnrollmentRuleData & { + id: string; + created_at: string; + updated_at?: string; +}; +export interface EnrollmentApiKey { + id: string; + api_key_id: string; + api_key: string; + name?: string; + created_at: string; + expire_at?: string; + active: boolean; + enrollment_rules: EnrollmentRule[]; + policy_id?: string; + [k: string]: any; // allow to use it as saved object attributes type +} diff --git a/x-pack/legacy/plugins/fleet/server/libs/__mocks__/api_keys.ts b/x-pack/legacy/plugins/fleet/server/libs/__mocks__/api_keys.ts index 236e9565086cae..45028b23106b56 100644 --- a/x-pack/legacy/plugins/fleet/server/libs/__mocks__/api_keys.ts +++ b/x-pack/legacy/plugins/fleet/server/libs/__mocks__/api_keys.ts @@ -7,12 +7,14 @@ import { FrameworkUser, internalAuthData } from '../../adapters/framework/adapter_types'; import { AccessApiKeyVerificationResponse, - EnrollmentApiKey, EnrollmentApiKeyVerificationResponse, - EnrollmentRule, - EnrollmentRuleData, } from '../../repositories/enrollment_api_keys/types'; import { ApiKeyLib as ApiKeyLibType } from '../api_keys'; +import { + EnrollmentApiKey, + EnrollmentRuleData, + EnrollmentRule, +} from '../../../common/types/domain_data'; type Interface = { [P in keyof T]: T[P]; diff --git a/x-pack/legacy/plugins/fleet/server/libs/api_keys.ts b/x-pack/legacy/plugins/fleet/server/libs/api_keys.ts index 7672a423fe2dba..6ee49e6a5492f0 100644 --- a/x-pack/legacy/plugins/fleet/server/libs/api_keys.ts +++ b/x-pack/legacy/plugins/fleet/server/libs/api_keys.ts @@ -9,16 +9,18 @@ import Boom from 'boom'; import uuid from 'uuid/v4'; import { EnrollmentApiKeyVerificationResponse, - EnrollmentApiKey, - EnrollmentRuleData, EnrollmentApiKeysRepository, AccessApiKeyVerificationResponse, - EnrollmentRule, } from '../repositories/enrollment_api_keys/types'; import { FrameworkLib } from './framework'; import { FrameworkUser, internalAuthData } from '../adapters/framework/adapter_types'; import { ElasticsearchAdapter } from '../adapters/elasticsearch/adapter_types'; import { DEFAULT_POLICY_ID } from '../../common/constants'; +import { + EnrollmentApiKey, + EnrollmentRuleData, + EnrollmentRule, +} from '../../common/types/domain_data'; export class ApiKeyLib { constructor( diff --git a/x-pack/legacy/plugins/fleet/server/repositories/enrollment_api_keys/default.contract.test.ts b/x-pack/legacy/plugins/fleet/server/repositories/enrollment_api_keys/default.contract.test.ts index 9953cb51f4dd94..3dc9dd9f4eed4e 100644 --- a/x-pack/legacy/plugins/fleet/server/repositories/enrollment_api_keys/default.contract.test.ts +++ b/x-pack/legacy/plugins/fleet/server/repositories/enrollment_api_keys/default.contract.test.ts @@ -10,10 +10,11 @@ import { EnrollmentApiKeysRepository } from './default'; import { SODatabaseAdapter as SODatabaseAdapterType } from '../../adapters/saved_objects_database/adapter_types'; import { SODatabaseAdapter } from '../../adapters/saved_objects_database/default'; import { MemorizeSODatabaseAdapter } from '../../adapters/saved_objects_database/memorize_adapter'; -import { EnrollmentApiKey, SAVED_OBJECT_TYPE } from './types'; +import { SAVED_OBJECT_TYPE } from './types'; import { EncryptedSavedObjects } from '../../adapters/encrypted_saved_objects/default'; import { MemorizeEncryptedSavedObjects } from '../../adapters/encrypted_saved_objects/memorize_adapter'; import { FrameworkUser, internalAuthData } from '../../adapters/framework/adapter_types'; +import { EnrollmentApiKey } from '../../../common/types/domain_data'; describe('Enrollment api key Repository', () => { let adapter: EnrollmentApiKeysRepository; diff --git a/x-pack/legacy/plugins/fleet/server/repositories/enrollment_api_keys/default.ts b/x-pack/legacy/plugins/fleet/server/repositories/enrollment_api_keys/default.ts index 7c429c4e7f6f37..2cf798c3bc6fc2 100644 --- a/x-pack/legacy/plugins/fleet/server/repositories/enrollment_api_keys/default.ts +++ b/x-pack/legacy/plugins/fleet/server/repositories/enrollment_api_keys/default.ts @@ -8,12 +8,12 @@ import moment from 'moment'; import { SavedObject } from 'src/core/server'; import { SODatabaseAdapter } from '../../adapters/saved_objects_database/adapter_types'; import { - EnrollmentApiKey, EnrollmentApiKeysRepository as EnrollmentApiKeysRepositoryType, SAVED_OBJECT_TYPE, } from './types'; import { EncryptedSavedObjects } from '../../adapters/encrypted_saved_objects/adapter_types'; import { FrameworkUser } from '../../adapters/framework/adapter_types'; +import { EnrollmentApiKey } from '../../../common/types/domain_data'; function getFirstOrNull(list: T[]): T | null { return list.length > 0 ? list[0] : null; diff --git a/x-pack/legacy/plugins/fleet/server/repositories/enrollment_api_keys/types.ts b/x-pack/legacy/plugins/fleet/server/repositories/enrollment_api_keys/types.ts index 1ed7a5fdaa73e2..f72513216adc56 100644 --- a/x-pack/legacy/plugins/fleet/server/repositories/enrollment_api_keys/types.ts +++ b/x-pack/legacy/plugins/fleet/server/repositories/enrollment_api_keys/types.ts @@ -4,35 +4,11 @@ * you may not use this file except in compliance with the Elastic License. */ -import * as t from 'io-ts'; import { FrameworkUser } from '../../adapters/framework/adapter_types'; -import { RuntimeAgentType } from '../../../common/types/domain_data'; +import { EnrollmentApiKey } from '../../../common/types/domain_data'; export const SAVED_OBJECT_TYPE = 'enrollment_api_keys'; -export const RuntimeEnrollmentRuleData = t.partial( - { - ip_ranges: t.array(t.string), - window_duration: t.interface( - { - from: t.string, - to: t.string, - }, - 'WindowDuration' - ), - types: t.array(RuntimeAgentType), - }, - 'EnrollmentRuleData' -); - -export type EnrollmentRuleData = t.TypeOf; - -export type EnrollmentRule = EnrollmentRuleData & { - id: string; - created_at: string; - updated_at?: string; -}; - export type EnrollmentApiKeyVerificationResponse = | { valid: true; @@ -53,19 +29,6 @@ export type AccessApiKeyVerificationResponse = reason: string; }; -export interface EnrollmentApiKey { - id: string; - api_key_id: string; - api_key: string; - name?: string; - created_at: string; - expire_at?: string; - active: boolean; - enrollment_rules: EnrollmentRule[]; - policy_id?: string; - [k: string]: any; // allow to use it as saved object attributes type -} - export interface EnrollmentApiKeysRepository { list( user: FrameworkUser, diff --git a/x-pack/legacy/plugins/fleet/server/routes/enrollment_api_keys/rules.ts b/x-pack/legacy/plugins/fleet/server/routes/enrollment_api_keys/rules.ts index 3addbc9df39700..37cdb953b66cd2 100644 --- a/x-pack/legacy/plugins/fleet/server/routes/enrollment_api_keys/rules.ts +++ b/x-pack/legacy/plugins/fleet/server/routes/enrollment_api_keys/rules.ts @@ -10,7 +10,7 @@ import { isLeft } from 'fp-ts/lib/Either'; import { FrameworkRequest } from '../../adapters/framework/adapter_types'; import { ReturnTypeList, ReturnTypeCreate, ReturnTypeDelete } from '../../../common/return_types'; import { FleetServerLib } from '../../libs/types'; -import { RuntimeEnrollmentRuleData } from '../../repositories/enrollment_api_keys/types'; +import { RuntimeEnrollmentRuleData } from '../../../common/types/domain_data'; export const createPostEnrollmentRulesRoute = (libs: FleetServerLib) => ({ method: 'POST', From 7752c9081f8bd453835ee72caca27fcec5a66faf Mon Sep 17 00:00:00 2001 From: Nicolas Chaulet Date: Fri, 3 Jan 2020 08:28:04 -0500 Subject: [PATCH 4/6] [EPM] Fix typescript issues after master merge --- x-pack/legacy/plugins/epm/public/data.ts | 5 +++-- x-pack/legacy/plugins/epm/server/plugin.ts | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/x-pack/legacy/plugins/epm/public/data.ts b/x-pack/legacy/plugins/epm/public/data.ts index f7a40194e0ac2e..c5412cb5273976 100644 --- a/x-pack/legacy/plugins/epm/public/data.ts +++ b/x-pack/legacy/plugins/epm/public/data.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { HttpHandler } from 'src/core/public'; +import { HttpHandler, HttpFetchOptions } from 'src/core/public'; import { getCategoriesPath, getFilePath, @@ -26,7 +26,8 @@ import { } from '../common/types'; import { ReturnTypeList } from '../../ingest/common/types/std_return_format'; -const defaultClient: HttpHandler = (path, options?) => fetch(path, options).then(res => res.json()); +const defaultClient: HttpHandler = (path: string, options?: HttpFetchOptions) => + fetch(path, options).then(res => res.json()); let _fetch: HttpHandler = defaultClient; diff --git a/x-pack/legacy/plugins/epm/server/plugin.ts b/x-pack/legacy/plugins/epm/server/plugin.ts index 6aecb48ccc075d..38dbb6b931bb7d 100644 --- a/x-pack/legacy/plugins/epm/server/plugin.ts +++ b/x-pack/legacy/plugins/epm/server/plugin.ts @@ -16,7 +16,9 @@ import { routes } from './routes'; export { createSetupShim } from './shim'; -export type EPMPluginInitializerContext = Pick; +export interface EPMPluginInitializerContext { + config: Omit; +} export interface EPMCoreSetup { elasticsearch: CoreSetup['elasticsearch']; From 36b8a17a1c0d8ed5a5132a29165a93b7e97d1b7a Mon Sep 17 00:00:00 2001 From: Nicolas Chaulet Date: Fri, 3 Jan 2020 10:03:21 -0500 Subject: [PATCH 5/6] [Fleet] Fix typescript issues after master merge --- x-pack/test/api_integration/apis/fleet/agents/actions.ts | 3 +-- x-pack/test/api_integration/apis/fleet/delete_agent.ts | 3 +-- x-pack/test/api_integration/apis/fleet/list_agent.ts | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/x-pack/test/api_integration/apis/fleet/agents/actions.ts b/x-pack/test/api_integration/apis/fleet/agents/actions.ts index ab03c2755e74fd..875dd38b8a3682 100644 --- a/x-pack/test/api_integration/apis/fleet/agents/actions.ts +++ b/x-pack/test/api_integration/apis/fleet/agents/actions.ts @@ -7,12 +7,11 @@ import expect from '@kbn/expect'; import { FtrProviderContext } from '../../../ftr_provider_context'; -import { SecurityService } from '../../../../common/services'; export default function({ getService }: FtrProviderContext) { const esArchiver = getService('esArchiver'); const supertest = getService('supertestWithoutAuth'); - const security: SecurityService = getService('security'); + const security = getService('security'); const users: { [rollName: string]: { username: string; password: string; permissions?: any } } = { fleet_user: { permissions: { diff --git a/x-pack/test/api_integration/apis/fleet/delete_agent.ts b/x-pack/test/api_integration/apis/fleet/delete_agent.ts index 13581d8327a7c9..aac00f2b59eafd 100644 --- a/x-pack/test/api_integration/apis/fleet/delete_agent.ts +++ b/x-pack/test/api_integration/apis/fleet/delete_agent.ts @@ -6,12 +6,11 @@ import expect from '@kbn/expect'; import { FtrProviderContext } from '../../ftr_provider_context'; -import { SecurityService } from '../../../common/services'; export default function({ getService }: FtrProviderContext) { const esArchiver = getService('esArchiver'); const supertest = getService('supertestWithoutAuth'); - const security: SecurityService = getService('security'); + const security = getService('security'); const users: { [rollName: string]: { username: string; password: string; permissions?: any } } = { fleet_user: { permissions: { diff --git a/x-pack/test/api_integration/apis/fleet/list_agent.ts b/x-pack/test/api_integration/apis/fleet/list_agent.ts index 4c3e85b2924ad0..b7ffddd1b9d6ea 100644 --- a/x-pack/test/api_integration/apis/fleet/list_agent.ts +++ b/x-pack/test/api_integration/apis/fleet/list_agent.ts @@ -7,12 +7,11 @@ import expect from '@kbn/expect'; import { FtrProviderContext } from '../../ftr_provider_context'; -import { SecurityService } from '../../../common/services'; export default function({ getService }: FtrProviderContext) { const esArchiver = getService('esArchiver'); const supertest = getService('supertestWithoutAuth'); - const security: SecurityService = getService('security'); + const security = getService('security'); const users: { [rollName: string]: { username: string; password: string; permissions?: any } } = { kibana_basic_user: { permissions: { From 3a61d7c4d85cda53f3dd45226cafd06488e2d624 Mon Sep 17 00:00:00 2001 From: Nicolas Chaulet Date: Fri, 3 Jan 2020 10:19:15 -0500 Subject: [PATCH 6/6] Update x-pack/legacy/plugins/epm/server/plugin.ts Co-Authored-By: John Schulz --- x-pack/legacy/plugins/epm/server/plugin.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/legacy/plugins/epm/server/plugin.ts b/x-pack/legacy/plugins/epm/server/plugin.ts index 38dbb6b931bb7d..baa3dfa0aadf0b 100644 --- a/x-pack/legacy/plugins/epm/server/plugin.ts +++ b/x-pack/legacy/plugins/epm/server/plugin.ts @@ -17,7 +17,7 @@ import { routes } from './routes'; export { createSetupShim } from './shim'; export interface EPMPluginInitializerContext { - config: Omit; + config: Pick; } export interface EPMCoreSetup {