Skip to content

Commit

Permalink
Move policy ingest service to a common service
Browse files Browse the repository at this point in the history
  • Loading branch information
Esteban Beltran committed Nov 17, 2021
1 parent 3e4ac9f commit 2e1801c
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
} from '../../../../common/store/test_utils';
import { getEndpointListPath } from '../../../common/routing';

jest.mock('../../policy/store/services/ingest', () => ({
jest.mock('../../../services/policy/ingest', () => ({
sendGetAgentPolicyList: () => Promise.resolve({ items: [] }),
sendGetEndpointSecurityPackage: () => Promise.resolve({}),
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import {
HOST_METADATA_LIST_ROUTE,
} from '../../../../../common/endpoint/constants';

jest.mock('../../policy/store/services/ingest', () => ({
jest.mock('../../../services/policy/ingest', () => ({
sendGetAgentConfigList: () => Promise.resolve({ items: [] }),
sendGetAgentPolicyList: () => Promise.resolve({ items: [] }),
sendGetEndpointSecurityPackage: () => Promise.resolve({ version: '1.1.1' }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,6 @@ import {
TransformStats,
TransformStatsResponse,
} from '../types';
import {
sendGetEndpointSpecificPackagePolicies,
sendGetEndpointSecurityPackage,
sendGetAgentPolicyList,
sendGetFleetAgentsWithEndpoint,
} from '../../policy/store/services/ingest';
import { AGENT_POLICY_SAVED_OBJECT_TYPE } from '../../../../../../fleet/common';
import {
ENDPOINT_ACTION_LOG_ROUTE,
Expand All @@ -81,6 +75,12 @@ import { EndpointPackageInfoStateChanged } from './action';
import { fetchPendingActionsByAgentId } from '../../../../common/lib/endpoint_pending_actions';
import { getIsInvalidDateRange } from '../utils';
import { METADATA_TRANSFORM_STATS_URL } from '../../../../../common/constants';
import {
sendGetAgentPolicyList,
sendGetEndpointSecurityPackage,
sendGetEndpointSpecificPackagePolicies,
sendGetFleetAgentsWithEndpoint,
} from '../../../services/policy/ingest';

type EndpointPageStore = ImmutableMiddlewareAPI<EndpointState, AppAction>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ import {
PendingActionsResponse,
} from '../../../../../common/endpoint/types';
import { EndpointDocGenerator } from '../../../../../common/endpoint/generate_data';
import {
INGEST_API_AGENT_POLICIES,
INGEST_API_EPM_PACKAGES,
INGEST_API_PACKAGE_POLICIES,
INGEST_API_FLEET_AGENTS,
} from '../../policy/store/services/ingest';
import {
GetAgentPoliciesResponse,
GetAgentPoliciesResponseItem,
Expand All @@ -32,6 +26,12 @@ import { pendingActionsResponseMock } from '../../../../common/lib/endpoint_pend
import { ACTION_STATUS_ROUTE } from '../../../../../common/endpoint/constants';
import { METADATA_TRANSFORM_STATS_URL } from '../../../../../common/constants';
import { TransformStats, TransformStatsResponse } from '../types';
import {
INGEST_API_AGENT_POLICIES,
INGEST_API_EPM_PACKAGES,
INGEST_API_FLEET_AGENTS,
INGEST_API_PACKAGE_POLICIES,
} from '../../../services/policy/ingest';

const generator = new EndpointDocGenerator('seed');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {
} from '../../../../../common/endpoint/types';
import { EndpointDocGenerator } from '../../../../../common/endpoint/generate_data';
import { POLICY_STATUS_TO_HEALTH_COLOR, POLICY_STATUS_TO_TEXT } from './host_constants';
import { mockPolicyResultList } from '../../policy/store/test_mock_utils';
import { getEndpointDetailsPath } from '../../../common/routing';
import { KibanaServices, useKibana, useToasts, useUiSetting$ } from '../../../../common/lib/kibana';
import { hostIsolationHttpMocks } from '../../../../common/lib/endpoint_isolation/mocks';
Expand All @@ -55,6 +54,7 @@ import {
metadataTransformPrefix,
METADATA_UNITED_TRANSFORM,
} from '../../../../../common/endpoint/constants';
import { mockPolicyResultList } from '../../../services/policy/test_mock_utils';

// not sure why this can't be imported from '../../../../common/mock/formatted_relative';
// but sure enough it needs to be inline in this one file
Expand All @@ -68,8 +68,8 @@ jest.mock('@kbn/i18n/react', () => {
};
});
jest.mock('../../../../common/components/link_to');
jest.mock('../../policy/store/services/ingest', () => {
const originalModule = jest.requireActual('../../policy/store/services/ingest');
jest.mock('../../../services/policy/ingest', () => {
const originalModule = jest.requireActual('../../../services/policy/ingest');
return {
...originalModule,
sendGetEndpointSecurityPackage: () => Promise.resolve({}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
*/

import { IHttpFetchError } from 'kibana/public';
import {
sendGetFleetAgentStatusForPolicy,
sendGetPackagePolicy,
sendPutPackagePolicy,
} from '../../../../../services/policy/ingest';
import {
DefaultPolicyNotificationMessage,
DefaultPolicyRuleNotificationMessage,
Expand All @@ -18,11 +23,6 @@ import {
policyDetailsForUpdate,
needsToRefresh,
} from '../selectors/policy_settings_selectors';
import {
sendGetPackagePolicy,
sendGetFleetAgentStatusForPolicy,
sendPutPackagePolicy,
} from '../../services/ingest';
import { NewPolicyData, PolicyData } from '../../../../../../../common/endpoint/types';
import { getPolicyDataForUpdate } from '../../../../../../../common/endpoint/service/policy';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import { PolicyDetails } from './policy_details';
import { EndpointDocGenerator } from '../../../../../common/endpoint/generate_data';
import { AppContextTestRender, createAppRootMockRenderer } from '../../../../common/mock/endpoint';
import { getPolicyDetailPath, getEndpointListPath } from '../../../common/routing';
import { policyListApiPathHandlers } from '../store/test_mock_utils';
import { PACKAGE_POLICY_API_ROOT, AGENT_API_ROUTES } from '../../../../../../fleet/common';
import { policyListApiPathHandlers } from '../../../services/policy/test_mock_utils';

jest.mock('./policy_forms/components/policy_form_layout');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import {
createAppRootMockRenderer,
} from '../../../../../../common/mock/endpoint';
import { getPolicyDetailPath, getEndpointListPath } from '../../../../../common/routing';
import { policyListApiPathHandlers } from '../../../store/test_mock_utils';
import { licenseService } from '../../../../../../common/hooks/use_license';
import { PACKAGE_POLICY_API_ROOT, AGENT_API_ROUTES } from '../../../../../../../../fleet/common';
import { policyListApiPathHandlers } from '../../../../../services/policy/test_mock_utils';

jest.mock('../../../../../../common/hooks/use_license');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import { getMockListResponse } from '../../../test_utils';
import { createLoadedResourceState, isLoadedResourceState } from '../../../../../state';
import { getPolicyDetailsArtifactsListPath } from '../../../../../common/routing';
import { EndpointDocGenerator } from '../../../../../../../common/endpoint/generate_data';
import { policyListApiPathHandlers } from '../../../store/test_mock_utils';
import { useEndpointPrivileges } from '../../../../../../common/components/user_privileges/endpoint/use_endpoint_privileges';
import { getEndpointPrivilegesInitialStateMock } from '../../../../../../common/components/user_privileges/endpoint/mocks';
import { PACKAGE_POLICY_API_ROOT, AGENT_API_ROUTES } from '../../../../../../../../fleet/common';
import { policyListApiPathHandlers } from '../../../../../services/policy/test_mock_utils';

jest.mock('../../../../trusted_apps/service');
jest.mock('../../../../../../common/components/user_privileges/endpoint/use_endpoint_privileges');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ import {
} from '../../../../../common/endpoint/types';
import { resolvePathVariables } from '../../../../common/utils/resolve_path_variables';

import { sendGetEndpointSpecificPackagePolicies } from '../../policy/store/services/ingest';
import { toUpdateTrustedApp } from '../../../../../common/endpoint/service/trusted_apps/to_update_trusted_app';
import { isGlobalEffectScope } from '../state/type_guards';
import { sendGetEndpointSpecificPackagePolicies } from '../../../services/policy/ingest';

export interface TrustedAppsService {
getTrustedApp(params: GetOneTrustedAppRequestParams): Promise<GetOneTrustedAppResponse>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
* 2.0.
*/

import { httpServiceMock } from 'src/core/public/mocks';
import {
EPM_API_ROUTES,
PACKAGE_POLICY_API_ROOT,
PACKAGE_POLICY_API_ROUTES,
PACKAGE_POLICY_SAVED_OBJECT_TYPE,
} from '../../../../../fleet/common';
import {
INGEST_API_EPM_PACKAGES,
sendGetPackagePolicy,
sendGetEndpointSecurityPackage,
sendGetEndpointSpecificPackagePolicies,
sendGetPackagePolicy,
} from './ingest';
import { httpServiceMock } from '../../../../../../../../../src/core/public/mocks';
import {
EPM_API_ROUTES,
PACKAGE_POLICY_SAVED_OBJECT_TYPE,
PACKAGE_POLICY_API_ROOT,
PACKAGE_POLICY_API_ROUTES,
} from '../../../../../../../fleet/common';
import { policyListApiPathHandlers } from '../test_mock_utils';
import { policyListApiPathHandlers } from './test_mock_utils';

describe('ingest service', () => {
let http: ReturnType<typeof httpServiceMock.createStartContract>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,23 @@
*/

import { HttpFetchOptions, HttpStart } from 'kibana/public';
import { NewPolicyData } from '../../../../common/endpoint/types';
import {
GetPackagePoliciesRequest,
GetAgentStatusResponse,
GetAgentsResponse,
DeletePackagePoliciesResponse,
DeletePackagePoliciesRequest,
PACKAGE_POLICY_SAVED_OBJECT_TYPE,
GetPackagesResponse,
DeletePackagePoliciesResponse,
GetAgentPoliciesRequest,
GetAgentPoliciesResponse,
} from '../../../../../../../fleet/common';
import { GetPolicyListResponse, GetPolicyResponse, UpdatePolicyResponse } from '../../types';
import { NewPolicyData } from '../../../../../../common/endpoint/types';
GetAgentsResponse,
GetAgentStatusResponse,
GetPackagePoliciesRequest,
GetPackagesResponse,
PACKAGE_POLICY_SAVED_OBJECT_TYPE,
} from '../../../../../fleet/common';
import {
GetPolicyListResponse,
GetPolicyResponse,
UpdatePolicyResponse,
} from '../../pages/policy/types';

const INGEST_API_ROOT = `/api/fleet`;
export const INGEST_API_PACKAGE_POLICIES = `${INGEST_API_ROOT}/package_policies`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
* 2.0.
*/

import { INGEST_API_EPM_PACKAGES, INGEST_API_PACKAGE_POLICIES } from './services/ingest';
import { EndpointDocGenerator } from '../../../../../common/endpoint/generate_data';
import { GetPolicyListResponse } from '../types';
import { GetPackagesResponse } from '../../../../../../fleet/common';
import { GetPackagesResponse } from '../../../../../fleet/common';
import { EndpointDocGenerator } from '../../../../common/endpoint/generate_data';
import { GetPolicyListResponse } from '../../pages/policy/types';
import { INGEST_API_EPM_PACKAGES, INGEST_API_PACKAGE_POLICIES } from './ingest';

const generator = new EndpointDocGenerator('policy-list');

Expand Down

0 comments on commit 2e1801c

Please sign in to comment.