diff --git a/x-pack/plugins/ingest_manager/common/constants/epm.ts b/x-pack/plugins/ingest_manager/common/constants/epm.ts index 91b240f75cfbd..abd6becae4ae6 100644 --- a/x-pack/plugins/ingest_manager/common/constants/epm.ts +++ b/x-pack/plugins/ingest_manager/common/constants/epm.ts @@ -22,3 +22,8 @@ export const dataTypes = { Logs: 'logs', Metrics: 'metrics', } as const; + +export const installationStatuses = { + Installed: 'installed', + NotInstalled: 'not_installed', +} as const; diff --git a/x-pack/plugins/ingest_manager/common/services/package_to_package_policy.test.ts b/x-pack/plugins/ingest_manager/common/services/package_to_package_policy.test.ts index a62fcddd16e0f..8927b5ab3ca4b 100644 --- a/x-pack/plugins/ingest_manager/common/services/package_to_package_policy.test.ts +++ b/x-pack/plugins/ingest_manager/common/services/package_to_package_policy.test.ts @@ -3,7 +3,8 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -import { PackageInfo, InstallationStatus } from '../types'; +import { installationStatuses } from '../constants'; +import { PackageInfo } from '../types'; import { packageToPackagePolicy, packageToPackagePolicyInputs } from './package_to_package_policy'; describe('Ingest Manager - packageToPackagePolicy', () => { @@ -28,7 +29,7 @@ describe('Ingest Manager - packageToPackagePolicy', () => { map: [], }, }, - status: InstallationStatus.notInstalled, + status: installationStatuses.NotInstalled, }; describe('packageToPackagePolicyInputs', () => { diff --git a/x-pack/plugins/ingest_manager/common/types/models/epm.ts b/x-pack/plugins/ingest_manager/common/types/models/epm.ts index 40ae47a2e3fbc..ca4aa3965bc30 100644 --- a/x-pack/plugins/ingest_manager/common/types/models/epm.ts +++ b/x-pack/plugins/ingest_manager/common/types/models/epm.ts @@ -7,13 +7,16 @@ // Follow pattern from https://github.com/elastic/kibana/pull/52447 // TODO: Update when https://github.com/elastic/kibana/issues/53021 is closed import { SavedObject, SavedObjectAttributes, SavedObjectReference } from 'src/core/public'; -import { agentAssetTypes, dataTypes, requiredPackages } from '../../constants'; +import { + agentAssetTypes, + dataTypes, + installationStatuses, + requiredPackages, +} from '../../constants'; import { ValueOf } from '../../types'; -export enum InstallationStatus { - installed = 'installed', - notInstalled = 'not_installed', -} +export type InstallationStatus = typeof installationStatuses; + export enum InstallStatus { installed = 'installed', notInstalled = 'not_installed', @@ -233,7 +236,7 @@ interface PackageAdditions { export type PackageList = PackageListItem[]; export type PackageListItem = Installable; -export type PackagesGroupedByStatus = Record; +export type PackagesGroupedByStatus = Record, PackageList>; export type PackageInfo = Installable< // remove the properties we'll be altering/replacing from the base type Omit & @@ -256,12 +259,12 @@ export interface Installation extends SavedObjectAttributes { export type Installable = Installed | NotInstalled; export type Installed = T & { - status: InstallationStatus.installed; + status: InstallationStatus['Installed']; savedObject: SavedObject; }; export type NotInstalled = T & { - status: InstallationStatus.notInstalled; + status: InstallationStatus['NotInstalled']; }; export type AssetReference = KibanaAssetReference | EsAssetReference; diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_policy/create_package_policy_page/services/validate_package_policy.test..ts b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_policy/create_package_policy_page/services/validate_package_policy.test..ts index d621db615f2bd..9022e312ece79 100644 --- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_policy/create_package_policy_page/services/validate_package_policy.test..ts +++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_policy/create_package_policy_page/services/validate_package_policy.test..ts @@ -3,12 +3,8 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -import { - PackageInfo, - InstallationStatus, - NewPackagePolicy, - RegistryPolicyTemplate, -} from '../../../../types'; +import { installationStatuses } from '../../../../../../../common/constants'; +import { PackageInfo, NewPackagePolicy, RegistryPolicyTemplate } from '../../../../types'; import { validatePackagePolicy, validationHasErrors } from './validate_package_policy'; describe('Ingest Manager - validatePackagePolicy()', () => { @@ -31,7 +27,7 @@ describe('Ingest Manager - validatePackagePolicy()', () => { 'index-pattern': [], }, }, - status: InstallationStatus.notInstalled, + status: installationStatuses.NotInstalled, data_streams: [ { dataset: 'foo', diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/epm/screens/home/index.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/epm/screens/home/index.tsx index 8cf45a13ae8b3..fc1dc44f4b5cc 100644 --- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/epm/screens/home/index.tsx +++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/epm/screens/home/index.tsx @@ -8,6 +8,7 @@ import React, { useState } from 'react'; import { useRouteMatch, Switch, Route, useLocation, useHistory } from 'react-router-dom'; import { Props as EuiTabProps } from '@elastic/eui/src/components/tabs/tab'; import { i18n } from '@kbn/i18n'; +import { installationStatuses } from '../../../../../../../common/constants'; import { PAGE_ROUTING_PATHS } from '../../../../constants'; import { useLink, useGetCategories, useGetPackages, useBreadcrumbs } from '../../../../hooks'; import { WithHeaderLayout } from '../../../../layouts'; @@ -72,7 +73,7 @@ function InstalledPackages() { const allInstalledPackages = allPackages && allPackages.response - ? allPackages.response.filter((pkg) => pkg.status === 'installed') + ? allPackages.response.filter((pkg) => pkg.status === installationStatuses.Installed) : []; const updatablePackages = allInstalledPackages.filter( diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/overview/components/integration_section.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/overview/components/integration_section.tsx index 1ba1424d21b3a..3f13b65a160d8 100644 --- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/overview/components/integration_section.tsx +++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/overview/components/integration_section.tsx @@ -17,14 +17,14 @@ import { OverviewPanel } from './overview_panel'; import { OverviewStats } from './overview_stats'; import { useLink, useGetPackages } from '../../../hooks'; import { Loading } from '../../fleet/components'; -import { InstallationStatus } from '../../../types'; +import { installationStatuses } from '../../../../../../common/constants'; export const OverviewIntegrationSection: React.FC = () => { const { getHref } = useLink(); const packagesRequest = useGetPackages(); const res = packagesRequest.data?.response; const total = res?.length ?? 0; - const installed = res?.filter((p) => p.status === InstallationStatus.installed)?.length ?? 0; + const installed = res?.filter((p) => p.status === installationStatuses.Installed)?.length ?? 0; const updatablePackages = res?.filter( (item) => 'savedObject' in item && item.version > item.savedObject.attributes.version diff --git a/x-pack/plugins/ingest_manager/server/services/epm/kibana/index_pattern/install.ts b/x-pack/plugins/ingest_manager/server/services/epm/kibana/index_pattern/install.ts index 366c5306a2969..4ca8e9d52c337 100644 --- a/x-pack/plugins/ingest_manager/server/services/epm/kibana/index_pattern/install.ts +++ b/x-pack/plugins/ingest_manager/server/services/epm/kibana/index_pattern/install.ts @@ -12,14 +12,9 @@ import { import * as Registry from '../../registry'; import { loadFieldsFromYaml, Fields, Field } from '../../fields/field'; import { getPackageKeysByStatus } from '../../packages/get'; -import { dataTypes } from '../../../../../common/constants'; +import { dataTypes, installationStatuses } from '../../../../../common/constants'; import { ValueOf } from '../../../../../common/types'; -import { - InstallationStatus, - RegistryPackage, - CallESAsCurrentUser, - DataType, -} from '../../../../types'; +import { RegistryPackage, CallESAsCurrentUser, DataType } from '../../../../types'; import { appContextService } from '../../../../services'; interface FieldFormatMap { @@ -87,7 +82,7 @@ export async function installIndexPatterns( // get all user installed packages const installedPackages = await getPackageKeysByStatus( savedObjectsClient, - InstallationStatus.installed + installationStatuses.Installed ); // TODO: move to install package // cache all installed packages if they don't exist diff --git a/x-pack/plugins/ingest_manager/server/services/epm/packages/get.ts b/x-pack/plugins/ingest_manager/server/services/epm/packages/get.ts index cd0dcba7b97b2..2021b353f1a27 100644 --- a/x-pack/plugins/ingest_manager/server/services/epm/packages/get.ts +++ b/x-pack/plugins/ingest_manager/server/services/epm/packages/get.ts @@ -5,8 +5,9 @@ */ import { SavedObjectsClientContract, SavedObjectsFindOptions } from 'src/core/server'; -import { isPackageLimited } from '../../../../common'; +import { isPackageLimited, installationStatuses } from '../../../../common'; import { PACKAGES_SAVED_OBJECT_TYPE } from '../../../constants'; +import { ValueOf } from '../../../../common/types'; import { Installation, InstallationStatus, PackageInfo, KibanaAssetType } from '../../../types'; import * as Registry from '../registry'; import { createInstallableFrom, isRequiredPackage } from './index'; @@ -58,7 +59,7 @@ export async function getLimitedPackages(options: { const { savedObjectsClient } = options; const allPackages = await getPackages({ savedObjectsClient, experimental: true }); const installedPackages = allPackages.filter( - (pkg) => pkg.status === InstallationStatus.installed + (pkg) => pkg.status === installationStatuses.Installed ); const installedPackagesInfo = await Promise.all( installedPackages.map((pkgInstall) => { @@ -84,12 +85,12 @@ export async function getPackageSavedObjects( export async function getPackageKeysByStatus( savedObjectsClient: SavedObjectsClientContract, - status: InstallationStatus + status: ValueOf ) { const allPackages = await getPackages({ savedObjectsClient, experimental: true }); return allPackages.reduce>((acc, pkg) => { if (pkg.status === status) { - if (pkg.status === InstallationStatus.installed) { + if (pkg.status === installationStatuses.Installed) { // if we're looking for installed packages grab the version from the saved object because `getPackages` will // return the latest package information from the registry acc.push({ pkgName: pkg.name, pkgVersion: pkg.savedObject.attributes.version }); diff --git a/x-pack/plugins/ingest_manager/server/services/epm/packages/index.ts b/x-pack/plugins/ingest_manager/server/services/epm/packages/index.ts index 15c45e7449fec..410a9c0b22537 100644 --- a/x-pack/plugins/ingest_manager/server/services/epm/packages/index.ts +++ b/x-pack/plugins/ingest_manager/server/services/epm/packages/index.ts @@ -5,14 +5,13 @@ */ import { SavedObject } from 'src/core/server'; -import { RequiredPackage, requiredPackages, ValueOf } from '../../../../common'; import { - AssetType, - Installable, - Installation, - InstallationStatus, - KibanaAssetType, -} from '../../../types'; + RequiredPackage, + requiredPackages, + ValueOf, + installationStatuses, +} from '../../../../common'; +import { AssetType, Installable, Installation, KibanaAssetType } from '../../../types'; export { bulkInstallPackages, isBulkInstallError } from './bulk_install_packages'; export { @@ -56,11 +55,11 @@ export function createInstallableFrom( return savedObject ? { ...from, - status: InstallationStatus.installed, + status: installationStatuses.Installed, savedObject, } : { ...from, - status: InstallationStatus.notInstalled, + status: installationStatuses.NotInstalled, }; } 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 a2aafee4312aa..6db9c12250e8a 100644 --- a/x-pack/plugins/security_solution/common/endpoint/generate_data.ts +++ b/x-pack/plugins/security_solution/common/endpoint/generate_data.ts @@ -30,7 +30,6 @@ import { } from '../../../ingest_manager/common/types/rest_spec'; import { EsAssetReference, - InstallationStatus, KibanaAssetReference, } from '../../../ingest_manager/common/types/models'; import { agentPolicyStatuses } from '../../../ingest_manager/common/constants'; @@ -1267,7 +1266,7 @@ export class EndpointDocGenerator { type: 'image/svg+xml', }, ], - status: 'installed' as InstallationStatus, + status: 'installed', savedObject: { type: 'epm-packages', id: 'endpoint',