From 6e9972e693a718ba315859b97b3062b457924995 Mon Sep 17 00:00:00 2001 From: Nicolas Chaulet Date: Mon, 29 Jun 2020 10:51:30 -0400 Subject: [PATCH] [Ingest Manager] expose method to get agent and list agents to other plugins (#70087) --- .../plugins/ingest_manager/server/plugin.ts | 11 ++++-- .../ingest_manager/server/services/index.ts | 34 ++++++++++++++++--- .../server/endpoint/mocks.ts | 3 ++ 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/x-pack/plugins/ingest_manager/server/plugin.ts b/x-pack/plugins/ingest_manager/server/plugin.ts index fcdb6387fed3..1ae9528f3441 100644 --- a/x-pack/plugins/ingest_manager/server/plugin.ts +++ b/x-pack/plugins/ingest_manager/server/plugin.ts @@ -54,7 +54,12 @@ import { AgentService, datasourceService, } from './services'; -import { getAgentStatusById, authenticateAgentWithAccessToken } from './services/agents'; +import { + getAgentStatusById, + authenticateAgentWithAccessToken, + listAgents, + getAgent, +} from './services/agents'; import { CloudSetup } from '../../cloud/server'; import { agentCheckinState } from './services/agents/checkin/state'; @@ -236,7 +241,7 @@ export class IngestManagerPlugin plugins: { encryptedSavedObjects: EncryptedSavedObjectsPluginStart; } - ) { + ): Promise { await appContextService.start({ encryptedSavedObjectsStart: plugins.encryptedSavedObjects, encryptedSavedObjectsSetup: this.encryptedSavedObjectsSetup, @@ -255,6 +260,8 @@ export class IngestManagerPlugin return { esIndexPatternService: new ESIndexPatternSavedObjectService(), agentService: { + getAgent, + listAgents, getAgentStatusById, authenticateAgentWithAccessToken, }, diff --git a/x-pack/plugins/ingest_manager/server/services/index.ts b/x-pack/plugins/ingest_manager/server/services/index.ts index 1a0fb262eeb7..49896959f3c3 100644 --- a/x-pack/plugins/ingest_manager/server/services/index.ts +++ b/x-pack/plugins/ingest_manager/server/services/index.ts @@ -4,8 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ -import { SavedObjectsClientContract } from 'kibana/server'; -import { AgentStatus } from '../types'; +import { SavedObjectsClientContract, KibanaRequest } from 'kibana/server'; +import { AgentStatus, Agent } from '../types'; import * as settingsService from './settings'; export { ESIndexPatternSavedObjectService } from './es_index_pattern'; @@ -24,12 +24,38 @@ export interface ESIndexPatternService { * A service that provides exported functions that return information about an Agent */ export interface AgentService { + /** + * Get an Agent by id + */ + getAgent(soClient: SavedObjectsClientContract, agentId: string): Promise; + /** + * Authenticate an agent with access toekn + */ + authenticateAgentWithAccessToken( + soClient: SavedObjectsClientContract, + request: KibanaRequest + ): Promise; /** * Return the status by the Agent's id - * @param soClient - * @param agentId */ getAgentStatusById(soClient: SavedObjectsClientContract, agentId: string): Promise; + /** + * List agents + */ + listAgents( + soClient: SavedObjectsClientContract, + options: { + page: number; + perPage: number; + kuery?: string; + showInactive: boolean; + } + ): Promise<{ + agents: Agent[]; + total: number; + page: number; + perPage: number; + }>; } // Saved object services diff --git a/x-pack/plugins/security_solution/server/endpoint/mocks.ts b/x-pack/plugins/security_solution/server/endpoint/mocks.ts index 5435eff4ef15..aca8a4e0ce78 100644 --- a/x-pack/plugins/security_solution/server/endpoint/mocks.ts +++ b/x-pack/plugins/security_solution/server/endpoint/mocks.ts @@ -35,6 +35,9 @@ export const createMockEndpointAppContextServiceStartContract = (): jest.Mocked< export const createMockAgentService = (): jest.Mocked => { return { getAgentStatusById: jest.fn(), + authenticateAgentWithAccessToken: jest.fn(), + getAgent: jest.fn(), + listAgents: jest.fn(), }; };