diff --git a/x-pack/plugins/ingest_manager/common/constants/agent_policy.ts b/x-pack/plugins/ingest_manager/common/constants/agent_policy.ts index f6261790f6673..ed4b32aeaa50c 100644 --- a/x-pack/plugins/ingest_manager/common/constants/agent_policy.ts +++ b/x-pack/plugins/ingest_manager/common/constants/agent_policy.ts @@ -3,15 +3,22 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -import { AgentPolicyStatus, DefaultPackages } from '../types'; - +import { AgentPolicy, DefaultPackages } from '../types'; export const AGENT_POLICY_SAVED_OBJECT_TYPE = 'ingest-agent-policies'; -export const DEFAULT_AGENT_POLICY = { +export const agentPolicyStatuses = { + Active: 'active', + Inactive: 'inactive', +} as const; + +export const DEFAULT_AGENT_POLICY: Omit< + AgentPolicy, + 'id' | 'updated_at' | 'updated_by' | 'revision' +> = { name: 'Default policy', namespace: 'default', description: 'Default agent policy created by Kibana', - status: AgentPolicyStatus.Active, + status: agentPolicyStatuses.Active, package_policies: [], is_default: true, monitoring_enabled: ['logs', 'metrics'] as Array<'logs' | 'metrics'>, diff --git a/x-pack/plugins/ingest_manager/common/types/models/agent_policy.ts b/x-pack/plugins/ingest_manager/common/types/models/agent_policy.ts index 0232bd766ca53..6685c725b5e7e 100644 --- a/x-pack/plugins/ingest_manager/common/types/models/agent_policy.ts +++ b/x-pack/plugins/ingest_manager/common/types/models/agent_policy.ts @@ -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 { agentPolicyStatuses } from '../../constants'; +import { ValueOf } from '../../types'; import { PackagePolicy, PackagePolicyPackage } from './package_policy'; import { Output } from './output'; -export enum AgentPolicyStatus { - Active = 'active', - Inactive = 'inactive', -} +export type AgentPolicyStatus = typeof agentPolicyStatuses; export interface NewAgentPolicy { name: string; @@ -21,7 +20,7 @@ export interface NewAgentPolicy { export interface AgentPolicy extends NewAgentPolicy { id: string; - status: AgentPolicyStatus; + status: ValueOf; package_policies: string[] | PackagePolicy[]; updated_at: string; updated_by: string; diff --git a/x-pack/plugins/ingest_manager/server/services/agent_policy.ts b/x-pack/plugins/ingest_manager/server/services/agent_policy.ts index b003d16d379ca..e12a7890f0694 100644 --- a/x-pack/plugins/ingest_manager/server/services/agent_policy.ts +++ b/x-pack/plugins/ingest_manager/server/services/agent_policy.ts @@ -18,12 +18,12 @@ import { AgentPolicy, AgentPolicySOAttributes, FullAgentPolicy, - AgentPolicyStatus, ListWithKuery, } from '../types'; import { DeleteAgentPolicyResponse, Settings, + agentPolicyStatuses, storedPackagePoliciesToAgentInputs, } from '../../common'; import { AgentPolicyNameExistsError } from '../errors'; @@ -61,8 +61,8 @@ class AgentPolicyService { } if ( - oldAgentPolicy.status === AgentPolicyStatus.Inactive && - agentPolicy.status !== AgentPolicyStatus.Active + oldAgentPolicy.status === agentPolicyStatuses.Inactive && + agentPolicy.status !== agentPolicyStatuses.Active ) { throw new Error( `Agent policy ${id} cannot be updated because it is ${oldAgentPolicy.status}` diff --git a/x-pack/plugins/ingest_manager/server/types/models/agent_policy.ts b/x-pack/plugins/ingest_manager/server/types/models/agent_policy.ts index 5fff9247d78d9..0155b0ddc2632 100644 --- a/x-pack/plugins/ingest_manager/server/types/models/agent_policy.ts +++ b/x-pack/plugins/ingest_manager/server/types/models/agent_policy.ts @@ -5,7 +5,7 @@ */ import { schema } from '@kbn/config-schema'; import { PackagePolicySchema, NamespaceSchema } from './package_policy'; -import { AgentPolicyStatus } from '../../../common'; +import { agentPolicyStatuses } from '../../../common'; const AgentPolicyBaseSchema = { name: schema.string({ minLength: 1 }), @@ -24,8 +24,8 @@ export const AgentPolicySchema = schema.object({ ...AgentPolicyBaseSchema, id: schema.string(), status: schema.oneOf([ - schema.literal(AgentPolicyStatus.Active), - schema.literal(AgentPolicyStatus.Inactive), + schema.literal(agentPolicyStatuses.Active), + schema.literal(agentPolicyStatuses.Inactive), ]), package_policies: schema.oneOf([ schema.arrayOf(schema.string()), diff --git a/x-pack/plugins/security_solution/common/endpoint/generate_data.ts b/x-pack/plugins/security_solution/common/endpoint/generate_data.ts index 07b230ffc6cc5..a2aafee4312aa 100644 --- a/x-pack/plugins/security_solution/common/endpoint/generate_data.ts +++ b/x-pack/plugins/security_solution/common/endpoint/generate_data.ts @@ -29,11 +29,11 @@ import { GetPackagesResponse, } from '../../../ingest_manager/common/types/rest_spec'; import { - AgentPolicyStatus, EsAssetReference, InstallationStatus, KibanaAssetReference, } from '../../../ingest_manager/common/types/models'; +import { agentPolicyStatuses } from '../../../ingest_manager/common/constants'; import { firstNonNullValue } from './models/ecs_safety_helpers'; export type Event = AlertEvent | SafeEndpointEvent; @@ -1235,7 +1235,7 @@ export class EndpointDocGenerator { return { id: this.seededUUIDv4(), name: 'Agent Policy', - status: AgentPolicyStatus.Active, + status: agentPolicyStatuses.Active, description: 'Some description', namespace: 'default', monitoring_enabled: ['logs', 'metrics'],