Skip to content

Commit

Permalink
[Ingest Manager] expose method to get agent and list agents to other …
Browse files Browse the repository at this point in the history
…plugins (#70087)
  • Loading branch information
nchaulet authored Jun 29, 2020
1 parent f47b3e5 commit 6e9972e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
11 changes: 9 additions & 2 deletions x-pack/plugins/ingest_manager/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -236,7 +241,7 @@ export class IngestManagerPlugin
plugins: {
encryptedSavedObjects: EncryptedSavedObjectsPluginStart;
}
) {
): Promise<IngestManagerStartContract> {
await appContextService.start({
encryptedSavedObjectsStart: plugins.encryptedSavedObjects,
encryptedSavedObjectsSetup: this.encryptedSavedObjectsSetup,
Expand All @@ -255,6 +260,8 @@ export class IngestManagerPlugin
return {
esIndexPatternService: new ESIndexPatternSavedObjectService(),
agentService: {
getAgent,
listAgents,
getAgentStatusById,
authenticateAgentWithAccessToken,
},
Expand Down
34 changes: 30 additions & 4 deletions x-pack/plugins/ingest_manager/server/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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<Agent>;
/**
* Authenticate an agent with access toekn
*/
authenticateAgentWithAccessToken(
soClient: SavedObjectsClientContract,
request: KibanaRequest
): Promise<Agent>;
/**
* Return the status by the Agent's id
* @param soClient
* @param agentId
*/
getAgentStatusById(soClient: SavedObjectsClientContract, agentId: string): Promise<AgentStatus>;
/**
* 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
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/security_solution/server/endpoint/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ export const createMockEndpointAppContextServiceStartContract = (): jest.Mocked<
export const createMockAgentService = (): jest.Mocked<AgentService> => {
return {
getAgentStatusById: jest.fn(),
authenticateAgentWithAccessToken: jest.fn(),
getAgent: jest.fn(),
listAgents: jest.fn(),
};
};

Expand Down

0 comments on commit 6e9972e

Please sign in to comment.