Skip to content

Commit

Permalink
[Ingest Manager] Switch DefaultPackage enum to approach from #82188 (#…
Browse files Browse the repository at this point in the history
…82512)

## Summary

Follow pattern from #82188. Same behavior as now. Stronger type safety.

 * `defaultPackages` is runtime value (JS object)
 * `DefaultPackage` is TS type (`typeof defaultPackages`)
 * `ValueOf<DefaultPackage>` is TS union type `'system' | 'endpoint'`
 * Can access values directly as `defaultPackages.System` (JS) or `DefaultPackage['System']` (TS)
  • Loading branch information
John Schulz authored Nov 4, 2020
1 parent ae992ba commit c3f4024
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 { AgentPolicy, DefaultPackages } from '../types';
import { defaultPackages } from './epm';
import { AgentPolicy } from '../types';
export const AGENT_POLICY_SAVED_OBJECT_TYPE = 'ingest-agent-policies';

export const agentPolicyStatuses = {
Expand All @@ -24,4 +25,4 @@ export const DEFAULT_AGENT_POLICY: Omit<
monitoring_enabled: ['logs', 'metrics'] as Array<'logs' | 'metrics'>,
};

export const DEFAULT_AGENT_POLICIES_PACKAGES = [DefaultPackages.system];
export const DEFAULT_AGENT_POLICIES_PACKAGES = [defaultPackages.System];
3 changes: 3 additions & 0 deletions x-pack/plugins/ingest_manager/common/constants/epm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ export const requiredPackages = {
Endpoint: 'endpoint',
} as const;

// these are currently identical. we can separate if they later diverge
export const defaultPackages = requiredPackages;

export const agentAssetTypes = {
Input: 'input',
} as const;
Expand Down
6 changes: 2 additions & 4 deletions x-pack/plugins/ingest_manager/common/types/models/epm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { SavedObject, SavedObjectAttributes, SavedObjectReference } from 'src/co
import {
agentAssetTypes,
dataTypes,
defaultPackages,
installationStatuses,
requiredPackages,
} from '../../constants';
Expand Down Expand Up @@ -278,10 +279,7 @@ export type EsAssetReference = Pick<SavedObjectReference, 'id'> & {

export type RequiredPackage = typeof requiredPackages;

export enum DefaultPackages {
system = 'system',
endpoint = 'endpoint',
}
export type DefaultPackages = typeof defaultPackages;

export interface IndexTemplateMappings {
properties: any;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
DeleteAgentPolicyRequestSchema,
GetFullAgentPolicyRequestSchema,
AgentPolicy,
DefaultPackages,
NewPackagePolicy,
} from '../../types';
import {
Expand All @@ -31,6 +30,7 @@ import {
CopyAgentPolicyResponse,
DeleteAgentPolicyResponse,
GetFullAgentPolicyResponse,
defaultPackages,
} from '../../../common';
import { defaultIngestErrorHandler } from '../../errors';

Expand Down Expand Up @@ -117,7 +117,7 @@ export const createAgentPolicyHandler: RequestHandler<
// successfully
withSysMonitoring
? packagePolicyService
.buildPackagePolicyFromPackage(soClient, DefaultPackages.system)
.buildPackagePolicyFromPackage(soClient, defaultPackages.System)
.catch(() => undefined)
: undefined,
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ import { SavedObject, SavedObjectsClientContract } from 'src/core/server';
import semver from 'semver';
import Boom from '@hapi/boom';
import { UnwrapPromise } from '@kbn/utility-types';
import { BulkInstallPackageInfo, InstallSource } from '../../../../common';
import { BulkInstallPackageInfo, InstallSource, defaultPackages } from '../../../../common';
import { PACKAGES_SAVED_OBJECT_TYPE, MAX_TIME_COMPLETE_INSTALL } from '../../../constants';
import {
AssetReference,
Installation,
CallESAsCurrentUser,
DefaultPackages,
AssetType,
KibanaAssetReference,
EsAssetReference,
Expand Down Expand Up @@ -65,7 +64,7 @@ export async function ensureInstalledDefaultPackages(
const installations = [];
const bulkResponse = await bulkInstallPackages({
savedObjectsClient,
packagesToUpgrade: Object.values(DefaultPackages),
packagesToUpgrade: Object.values(defaultPackages),
callCluster,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import {
AGENT_SAVED_OBJECT_TYPE,
AGENT_EVENT_SAVED_OBJECT_TYPE,
} from './../../../../ingest_manager/common/constants/agent';
import { Agent, DefaultPackages as FleetDefaultPackages } from '../../../../ingest_manager/common';
import { Agent, defaultPackages as FleetDefaultPackages } from '../../../../ingest_manager/common';

export const FLEET_ENDPOINT_PACKAGE_CONSTANT = FleetDefaultPackages.endpoint;
export const FLEET_ENDPOINT_PACKAGE_CONSTANT = FleetDefaultPackages.Endpoint;

export const getFleetSavedObjectsMetadata = async (savedObjectsClient: ISavedObjectsRepository) =>
savedObjectsClient.find<Agent>({
Expand Down

0 comments on commit c3f4024

Please sign in to comment.