44 * you may not use this file except in compliance with the Elastic License.
55 */
66import * as t from 'io-ts' ;
7+ import { AGENT_TYPE_EPHEMERAL , AGENT_TYPE_PERMANENT , AGENT_TYPE_TEMPORARY } from '../constants' ;
78export { Policy , Datasource , Status , Output } from '../../../ingest/server/libs/types' ;
8- import { RuntimeAgent , RuntimeAgentAction } from '../../server/repositories/agents/types' ;
9- import { RuntimeAgentEvent } from '../../server/repositories/agent_events/types' ;
10- export { EnrollmentApiKey } from '../../server/repositories/enrollment_api_keys/types' ;
9+
10+ const RuntimeAgentActionType = t . union ( [
11+ t . literal ( 'POLICY_CHANGE' ) ,
12+ t . literal ( 'DATA_DUMP' ) ,
13+ t . literal ( 'RESUME' ) ,
14+ t . literal ( 'PAUSE' ) ,
15+ ] ) ;
16+
17+ export type AgentActionType = t . TypeOf < typeof RuntimeAgentActionType > ;
18+
19+ export const RuntimeAgentActionData = t . interface (
20+ {
21+ type : RuntimeAgentActionType ,
22+ } ,
23+ 'AgentActionData'
24+ ) ;
25+
26+ export const RuntimeAgentAction = t . intersection ( [
27+ RuntimeAgentActionData ,
28+ t . interface (
29+ {
30+ id : t . string ,
31+ created_at : t . string ,
32+ } ,
33+ 'AgentAction'
34+ ) ,
35+ t . partial ( {
36+ data : t . string ,
37+ sent_at : t . string ,
38+ } ) ,
39+ ] ) ;
40+
41+ export const RuntimeAgentType = t . union ( [
42+ t . literal ( AGENT_TYPE_PERMANENT ) ,
43+ t . literal ( AGENT_TYPE_EPHEMERAL ) ,
44+ t . literal ( AGENT_TYPE_TEMPORARY ) ,
45+ ] ) ;
46+
47+ export type AgentType = t . TypeOf < typeof RuntimeAgentType > ;
48+
49+ export const RuntimeAgentEventType = t . union ( [
50+ t . literal ( 'STATE' ) ,
51+ t . literal ( 'ERROR' ) ,
52+ t . literal ( 'ACTION_RESULT' ) ,
53+ t . literal ( 'ACTION' ) ,
54+ ] ) ;
55+
56+ export const RuntimeAgentEventSubtype = t . union ( [
57+ // State
58+ t . literal ( 'RUNNING' ) ,
59+ t . literal ( 'STARTING' ) ,
60+ t . literal ( 'IN_PROGRESS' ) ,
61+ t . literal ( 'CONFIG' ) ,
62+ t . literal ( 'FAILED' ) ,
63+ t . literal ( 'STOPPED' ) ,
64+ // Action results
65+ t . literal ( 'DATA_DUMP' ) ,
66+ // Actions
67+ t . literal ( 'ACKNOWLEDGED' ) ,
68+ t . literal ( 'UNKNOWN' ) ,
69+ ] ) ;
70+
71+ export const RuntimeAgentEvent = t . intersection (
72+ [
73+ t . interface ( {
74+ type : RuntimeAgentEventType ,
75+ subtype : RuntimeAgentEventSubtype ,
76+ timestamp : t . string ,
77+ message : t . string ,
78+ } ) ,
79+ t . partial ( {
80+ payload : t . any ,
81+ data : t . string ,
82+ action_id : t . string ,
83+ policy_id : t . string ,
84+ stream_id : t . string ,
85+ } ) ,
86+ ] ,
87+ 'AgentEvent'
88+ ) ;
89+
90+ export type AgentEvent = t . TypeOf < typeof RuntimeAgentEvent > ;
91+
92+ const newAgentProperties = {
93+ type : RuntimeAgentType ,
94+ active : t . boolean ,
95+ } ;
96+ const newAgentOptionalProperties = t . partial ( {
97+ parent_id : t . string ,
98+ version : t . string ,
99+ enrolled_at : t . string ,
100+ user_provided_metadata : t . dictionary ( t . string , t . string ) ,
101+ local_metadata : t . dictionary ( t . string , t . string ) ,
102+ shared_id : t . string ,
103+ access_api_key_id : t . string ,
104+ access_api_key : t . string ,
105+ policy_id : t . string ,
106+ } ) ;
107+
108+ export const RuntimeAgent = t . intersection ( [
109+ t . interface ( {
110+ ...newAgentProperties ,
111+ id : t . string ,
112+ actions : t . array ( RuntimeAgentAction ) ,
113+ current_error_events : t . array ( RuntimeAgentEvent ) ,
114+ } ) ,
115+ t . partial ( {
116+ last_updated : t . string ,
117+ last_checkin : t . string ,
118+ } ) ,
119+ newAgentOptionalProperties ,
120+ ] ) ;
121+
122+ export const NewRuntimeAgent = t . intersection ( [
123+ t . interface ( newAgentProperties ) ,
124+ newAgentOptionalProperties ,
125+ ] ) ;
126+ export type NewAgent = t . TypeOf < typeof NewRuntimeAgent > ;
11127
12128// Here we create the runtime check for a generic, unknown beat config type.
13129// We can also pass in optional params to create spacific runtime checks that
@@ -39,7 +155,6 @@ export type Agent = t.TypeOf<typeof RuntimeAgent> & {
39155 status : AgentStatus ;
40156} ;
41157export type AgentAction = t . TypeOf < typeof RuntimeAgentAction > ;
42- export type AgentEvent = t . TypeOf < typeof RuntimeAgentEvent > ;
43158
44159export type PolicyUpdatedEvent =
45160 | {
@@ -56,3 +171,38 @@ export type PolicyUpdatedEvent =
56171 type : 'deleted' ;
57172 policyId : string ;
58173 } ;
174+
175+ export const RuntimeEnrollmentRuleData = t . partial (
176+ {
177+ ip_ranges : t . array ( t . string ) ,
178+ window_duration : t . interface (
179+ {
180+ from : t . string ,
181+ to : t . string ,
182+ } ,
183+ 'WindowDuration'
184+ ) ,
185+ types : t . array ( RuntimeAgentType ) ,
186+ } ,
187+ 'EnrollmentRuleData'
188+ ) ;
189+
190+ export type EnrollmentRuleData = t . TypeOf < typeof RuntimeEnrollmentRuleData > ;
191+
192+ export type EnrollmentRule = EnrollmentRuleData & {
193+ id : string ;
194+ created_at : string ;
195+ updated_at ?: string ;
196+ } ;
197+ export interface EnrollmentApiKey {
198+ id : string ;
199+ api_key_id : string ;
200+ api_key : string ;
201+ name ?: string ;
202+ created_at : string ;
203+ expire_at ?: string ;
204+ active : boolean ;
205+ enrollment_rules : EnrollmentRule [ ] ;
206+ policy_id ?: string ;
207+ [ k : string ] : any ; // allow to use it as saved object attributes type
208+ }
0 commit comments