Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix tests
Browse files Browse the repository at this point in the history
nchaulet committed Oct 20, 2020
1 parent 890dc00 commit 8f197e8
Showing 3 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ export async function agentPolicyUpdateEventHandler(
agentPolicyId: string
) {
// If Agents are not setup skip this hook
if (!isAgentsSetup(soClient)) {
if (!(await isAgentsSetup(soClient))) {
return;
}

9 changes: 4 additions & 5 deletions x-pack/plugins/ingest_manager/server/services/agents/setup.ts
Original file line number Diff line number Diff line change
@@ -10,12 +10,11 @@ import { agentPolicyService } from '../agent_policy';
import { outputService } from '../output';
import { getLatestConfigChangeAction } from './actions';

export async function isAgentsSetup(soClient: SavedObjectsClientContract) {
const adminUser = await outputService.getAdminUser(soClient);
export async function isAgentsSetup(soClient: SavedObjectsClientContract): Promise<boolean> {
const adminUser = await outputService.getAdminUser(soClient, false);
const outputId = await outputService.getDefaultOutputId(soClient);

// If admin user (fleet_enroll) and output id exist Agents are correctly setup
return adminUser && outputId;
return adminUser !== null && outputId !== null;
}

/**
@@ -26,7 +25,7 @@ export async function isAgentsSetup(soClient: SavedObjectsClientContract) {
*/
export async function ensureAgentActionPolicyChangeExists(soClient: SavedObjectsClientContract) {
// If Agents are not setup skip
if (!isAgentsSetup(soClient)) {
if (!(await isAgentsSetup(soClient))) {
return;
}

4 changes: 2 additions & 2 deletions x-pack/plugins/ingest_manager/server/services/output.ts
Original file line number Diff line number Diff line change
@@ -65,8 +65,8 @@ class OutputService {
return outputs.saved_objects[0].id;
}

public async getAdminUser(soClient: SavedObjectsClientContract) {
if (cachedAdminUser) {
public async getAdminUser(soClient: SavedObjectsClientContract, useCache = true) {
if (useCache && cachedAdminUser) {
return cachedAdminUser;
}

0 comments on commit 8f197e8

Please sign in to comment.