Skip to content

Commit

Permalink
Switch to new 'as const' + typeof + ValueOf approach
Browse files Browse the repository at this point in the history
  • Loading branch information
John Schulz committed Nov 3, 2020
1 parent 6689167 commit 3ca697d
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 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 '../constants';
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
7 changes: 2 additions & 5 deletions x-pack/plugins/ingest_manager/common/types/models/epm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// 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, defaultPackages, requiredPackages } from '../../constants';
import { ValueOf } from '../../types';

export enum InstallationStatus {
Expand Down Expand Up @@ -275,10 +275,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 3ca697d

Please sign in to comment.