Skip to content

Commit

Permalink
[Synthetics] Fix project monitor private location editing (elastic#16…
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzad31 authored and dej611 committed Oct 17, 2023
1 parent 0f9ee91 commit d5cede6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { formatSyntheticsPolicy } from '../formatters/private_formatters/format_
import { savedObjectsServiceMock } from '@kbn/core-saved-objects-server-mocks';
import { SyntheticsServerSetup } from '../../types';
import { PrivateLocationAttributes } from '../../runtime_types/private_locations';
import { elasticsearchServiceMock } from '@kbn/core/server/mocks';

describe('SyntheticsPrivateLocation', () => {
const mockPrivateLocation: PrivateLocationAttributes = {
Expand Down Expand Up @@ -77,6 +78,7 @@ describe('SyntheticsPrivateLocation', () => {
},
coreStart: {
savedObjects: savedObjectsServiceMock.createStartContract(),
elasticsearch: elasticsearchServiceMock.createStart(),
},
} as unknown as SyntheticsServerSetup;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ export class SyntheticsPrivateLocation {

async createPolicyBulk(newPolicies: NewPackagePolicyWithId[]) {
const soClient = this.server.coreStart.savedObjects.createInternalRepository();
const esClient = this.server.uptimeEsClient.baseESClient;
const esClient = this.server.coreStart.elasticsearch.client.asInternalUser;
if (esClient && newPolicies.length > 0) {
return await this.server.fleet.packagePolicyService.bulkCreate(
soClient,
Expand All @@ -368,8 +368,8 @@ export class SyntheticsPrivateLocation {

async updatePolicyBulk(policiesToUpdate: NewPackagePolicyWithId[]) {
const soClient = this.server.coreStart.savedObjects.createInternalRepository();
const esClient = this.server.uptimeEsClient.baseESClient;
if (soClient && esClient && policiesToUpdate.length > 0) {
const esClient = this.server.coreStart.elasticsearch.client.asInternalUser;
if (policiesToUpdate.length > 0) {
const { failedPolicies } = await this.server.fleet.packagePolicyService.bulkUpdate(
soClient,
esClient,
Expand All @@ -384,8 +384,8 @@ export class SyntheticsPrivateLocation {

async deletePolicyBulk(policyIdsToDelete: string[]) {
const soClient = this.server.coreStart.savedObjects.createInternalRepository();
const esClient = this.server.uptimeEsClient.baseESClient;
if (soClient && esClient && policyIdsToDelete.length > 0) {
const esClient = this.server.coreStart.elasticsearch.client.asInternalUser;
if (policyIdsToDelete.length > 0) {
try {
return await this.server.fleet.packagePolicyService.delete(
soClient,
Expand All @@ -403,7 +403,7 @@ export class SyntheticsPrivateLocation {

async deleteMonitors(configs: HeartbeatConfig[], spaceId: string) {
const soClient = this.server.coreStart.savedObjects.createInternalRepository();
const esClient = this.server.uptimeEsClient.baseESClient;
const esClient = this.server.coreStart.elasticsearch.client.asInternalUser;

const policyIdsToDelete = [];
for (const config of configs) {
Expand Down

0 comments on commit d5cede6

Please sign in to comment.