[Synthetics] Separate Attributes type from Encrypted Monitor types (#160308)

Co-authored-by: Shahzad <shahzad31comp@gmail.com>
This commit is contained in:
Justin Kambic 2023-07-20 06:46:21 -04:00 committed by GitHub
parent 2943fc9e06
commit c892067f75
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
28 changed files with 177 additions and 174 deletions

View file

@ -31,8 +31,6 @@ const ScheduleCodec = t.interface({
unit: ScheduleUnitCodec,
});
export type SyntheticsMonitorSchedule = t.TypeOf<typeof ScheduleCodec>;
// TLSFields
export const TLSFieldsCodec = t.partial({
[ConfigKey.TLS_CERTIFICATE_AUTHORITIES]: t.string,
@ -48,8 +46,6 @@ export const TLSSensitiveFieldsCodec = t.partial({
export const TLSCodec = t.intersection([TLSFieldsCodec, TLSSensitiveFieldsCodec]);
export type TLSFields = t.TypeOf<typeof TLSCodec>;
// CommonFields
export const CommonFieldsCodec = t.intersection([
t.interface({
@ -79,8 +75,6 @@ export const CommonFieldsCodec = t.intersection([
}),
]);
export type CommonFields = t.TypeOf<typeof CommonFieldsCodec>;
// TCP Simple Fields
export const TCPSimpleFieldsCodec = t.intersection([
t.interface({
@ -94,8 +88,6 @@ export const TCPSimpleFieldsCodec = t.intersection([
CommonFieldsCodec,
]);
export type TCPSimpleFields = t.TypeOf<typeof TCPSimpleFieldsCodec>;
// TCPAdvancedFields
export const TCPAdvancedFieldsCodec = t.intersection([
t.interface({
@ -210,8 +202,6 @@ export const HTTPAdvancedCodec = t.intersection([
HTTPSensitiveAdvancedFieldsCodec,
]);
export type HTTPAdvancedFields = t.TypeOf<typeof HTTPAdvancedCodec>;
// HTTPFields
export const EncryptedHTTPFieldsCodec = t.intersection([
HTTPSimpleFieldsCodec,
@ -225,8 +215,6 @@ export const HTTPFieldsCodec = t.intersection([
TLSSensitiveFieldsCodec,
]);
export type HTTPFields = t.TypeOf<typeof HTTPFieldsCodec>;
export const EncryptedBrowserSimpleFieldsCodec = t.intersection([
t.intersection([
t.interface({
@ -300,10 +288,6 @@ export const BrowserFieldsCodec = t.intersection([
TLSCodec,
]);
export type BrowserFields = t.TypeOf<typeof BrowserFieldsCodec>;
export type BrowserSimpleFields = t.TypeOf<typeof BrowserSimpleFieldsCodec>;
export type BrowserAdvancedFields = t.TypeOf<typeof BrowserAdvancedFieldsCodec>;
// MonitorFields, represents any possible monitor type
export const MonitorFieldsCodec = t.intersection([
HTTPFieldsCodec,
@ -312,8 +296,6 @@ export const MonitorFieldsCodec = t.intersection([
BrowserFieldsCodec,
]);
export type MonitorFields = t.TypeOf<typeof MonitorFieldsCodec>;
// Monitor, represents one of (Icmp | Tcp | Http | Browser)
export const SyntheticsMonitorCodec = t.union([
HTTPFieldsCodec,
@ -329,8 +311,6 @@ export const EncryptedSyntheticsMonitorCodec = t.union([
EncryptedBrowserFieldsCodec,
]);
export type SyntheticsMonitor = t.TypeOf<typeof SyntheticsMonitorCodec>;
export const SyntheticsMonitorWithIdCodec = t.intersection([
SyntheticsMonitorCodec,
t.interface({ id: t.string }),
@ -359,12 +339,6 @@ export const EncryptedSyntheticsSavedMonitorCodec = t.intersection([
t.interface({ id: t.string, updated_at: t.string, created_at: t.string }),
]);
export type SyntheticsMonitorWithId = t.TypeOf<typeof SyntheticsMonitorWithIdCodec>;
export type EncryptedSyntheticsSavedMonitor = t.TypeOf<typeof EncryptedSyntheticsSavedMonitorCodec>;
export type HeartbeatConfig = t.TypeOf<typeof HeartbeatConfigCodec>;
export const MonitorDefaultsCodec = t.interface({
[DataStream.HTTP]: HTTPFieldsCodec,
[DataStream.TCP]: TCPFieldsCodec,
@ -372,8 +346,6 @@ export const MonitorDefaultsCodec = t.interface({
[DataStream.BROWSER]: BrowserFieldsCodec,
});
export type MonitorDefaults = t.TypeOf<typeof MonitorDefaultsCodec>;
export const MonitorManagementListResultCodec = t.type({
monitors: t.array(EncryptedSyntheticsSavedMonitorCodec),
page: t.number,
@ -383,8 +355,6 @@ export const MonitorManagementListResultCodec = t.type({
syncErrors: t.union([ServiceLocationErrors, t.null]),
});
export type MonitorManagementListResult = t.TypeOf<typeof MonitorManagementListResultCodec>;
export const MonitorOverviewItemCodec = t.intersection([
t.interface({
name: t.string,
@ -402,16 +372,12 @@ export const MonitorOverviewItemCodec = t.intersection([
}),
]);
export type MonitorOverviewItem = t.TypeOf<typeof MonitorOverviewItemCodec>;
export const MonitorOverviewResultCodec = t.type({
total: t.number,
allMonitorIds: t.array(t.string),
monitors: t.array(MonitorOverviewItemCodec),
});
export type MonitorOverviewResult = t.TypeOf<typeof MonitorOverviewResultCodec>;
export const SyntheticsMonitorWithSecretsCodec = t.intersection([
EncryptedSyntheticsMonitorCodec,
t.interface({
@ -419,11 +385,32 @@ export const SyntheticsMonitorWithSecretsCodec = t.intersection([
}),
]);
export type SyntheticsMonitorSchedule = t.TypeOf<typeof ScheduleCodec>;
export type TLSFields = t.TypeOf<typeof TLSCodec>;
export type CommonFields = t.TypeOf<typeof CommonFieldsCodec>;
export type TCPSimpleFields = t.TypeOf<typeof TCPSimpleFieldsCodec>;
export type HTTPAdvancedFields = t.TypeOf<typeof HTTPAdvancedCodec>;
export type HTTPFields = t.TypeOf<typeof HTTPFieldsCodec>;
export type BrowserFields = t.TypeOf<typeof BrowserFieldsCodec>;
export type BrowserSimpleFields = t.TypeOf<typeof BrowserSimpleFieldsCodec>;
export type BrowserAdvancedFields = t.TypeOf<typeof BrowserAdvancedFieldsCodec>;
export type MonitorFields = t.TypeOf<typeof MonitorFieldsCodec>;
export type SyntheticsMonitor = t.TypeOf<typeof SyntheticsMonitorCodec>;
export type SyntheticsMonitorWithId = t.TypeOf<typeof SyntheticsMonitorWithIdCodec>;
export type EncryptedSyntheticsSavedMonitor = t.TypeOf<typeof EncryptedSyntheticsSavedMonitorCodec>;
export type HeartbeatConfig = t.TypeOf<typeof HeartbeatConfigCodec>;
export type MonitorDefaults = t.TypeOf<typeof MonitorDefaultsCodec>;
export type MonitorManagementListResult = t.TypeOf<typeof MonitorManagementListResultCodec>;
export type MonitorOverviewItem = t.TypeOf<typeof MonitorOverviewItemCodec>;
export type MonitorOverviewResult = t.TypeOf<typeof MonitorOverviewResultCodec>;
export type Secret = typeof secretKeys[number];
export type SyntheticsMonitorWithSecrets = Omit<
t.TypeOf<typeof SyntheticsMonitorWithSecretsCodec>,
Secret
>;
export type SyntheticsMonitorWithSecretsAttributes = Omit<
t.TypeOf<typeof SyntheticsMonitorWithSecretsCodec>,
Secret
>;
export type EncryptedSyntheticsMonitor = Omit<SyntheticsMonitorWithSecrets, 'secrets'>;
export type EncryptedSyntheticsMonitorAttributes = Omit<SyntheticsMonitorWithSecrets, 'secrets'>;

View file

@ -22,7 +22,7 @@ import { queryMonitorStatus } from '../../queries/query_monitor_status';
import { StatusRuleParams } from '../../../common/rules/status_rule';
import {
ConfigKey,
EncryptedSyntheticsMonitor,
EncryptedSyntheticsMonitorAttributes,
OverviewStatus,
OverviewStatusMetaData,
} from '../../../common/runtime_types';
@ -47,7 +47,7 @@ export class StatusRuleExecutor {
soClient: SavedObjectsClientContract;
server: SyntheticsServerSetup;
syntheticsMonitorClient: SyntheticsMonitorClient;
monitors: Array<SavedObjectsFindResult<EncryptedSyntheticsMonitor>> = [];
monitors: Array<SavedObjectsFindResult<EncryptedSyntheticsMonitorAttributes>> = [];
public locationIdNameMap: Record<string, string> = {};

View file

@ -25,7 +25,7 @@ import {
import {
CertResult,
ConfigKey,
EncryptedSyntheticsMonitor,
EncryptedSyntheticsMonitorAttributes,
Ping,
} from '../../../common/runtime_types';
import { SyntheticsMonitorClient } from '../../synthetics_service/synthetics_monitor/synthetics_monitor_client';
@ -40,7 +40,7 @@ export class TLSRuleExecutor {
soClient: SavedObjectsClientContract;
server: SyntheticsServerSetup;
syntheticsMonitorClient: SyntheticsMonitorClient;
monitors: Array<SavedObjectsFindResult<EncryptedSyntheticsMonitor>> = [];
monitors: Array<SavedObjectsFindResult<EncryptedSyntheticsMonitorAttributes>> = [];
constructor(
previousStartedAt: Date | null,

View file

@ -9,8 +9,8 @@ import { SavedObjectsClientContract } from '@kbn/core/server';
import { EncryptedSavedObjectsClient } from '@kbn/encrypted-saved-objects-plugin/server';
import { syntheticsMonitorType } from '../../../../common/types/saved_objects';
import {
SyntheticsMonitorWithSecrets,
EncryptedSyntheticsMonitor,
SyntheticsMonitorWithSecretsAttributes,
EncryptedSyntheticsMonitorAttributes,
SyntheticsMonitor,
} from '../../../../common/runtime_types';
import { normalizeSecrets } from '../../../synthetics_service/utils/secrets';
@ -25,13 +25,13 @@ export const getSyntheticsMonitor = async ({
savedObjectsClient: SavedObjectsClientContract;
}): Promise<SyntheticsMonitor> => {
try {
const encryptedMonitor = await savedObjectsClient.get<EncryptedSyntheticsMonitor>(
const encryptedMonitor = await savedObjectsClient.get<EncryptedSyntheticsMonitorAttributes>(
syntheticsMonitorType,
monitorId
);
const decryptedMonitor =
await encryptedSavedObjectsClient.getDecryptedAsInternalUser<SyntheticsMonitorWithSecrets>(
await encryptedSavedObjectsClient.getDecryptedAsInternalUser<SyntheticsMonitorWithSecretsAttributes>(
syntheticsMonitorType,
monitorId,
{

View file

@ -10,7 +10,7 @@ import { SavedObjectsFindResponse } from '@kbn/core/server';
import { RouteContext } from './types';
import { MonitorSortFieldSchema } from '../../common/runtime_types/monitor_management/sort_field';
import { getAllLocations } from '../synthetics_service/get_all_locations';
import { EncryptedSyntheticsMonitor, ServiceLocations } from '../../common/runtime_types';
import { EncryptedSyntheticsMonitorAttributes, ServiceLocations } from '../../common/runtime_types';
import { monitorAttributes, syntheticsMonitorType } from '../../common/types/saved_objects';
const StringOrArraySchema = schema.maybe(
@ -63,7 +63,7 @@ export const SEARCH_FIELDS = [
export const getMonitors = async (
context: RouteContext<MonitorsQuery>,
{ fields }: { fields?: string[] } = {}
): Promise<SavedObjectsFindResponse<EncryptedSyntheticsMonitor>> => {
): Promise<SavedObjectsFindResponse<EncryptedSyntheticsMonitorAttributes>> => {
const {
perPage = 50,
page,

View file

@ -25,7 +25,7 @@ import {
ConfigKey,
MonitorFields,
SyntheticsMonitor,
EncryptedSyntheticsMonitor,
EncryptedSyntheticsMonitorAttributes,
PrivateLocation,
} from '../../../common/runtime_types';
import { SYNTHETICS_API_URLS } from '../../../common/constants';
@ -120,7 +120,7 @@ export const createNewSavedObjectMonitor = async ({
savedObjectsClient: SavedObjectsClientContract;
normalizedMonitor: SyntheticsMonitor;
}) => {
return await savedObjectsClient.create<EncryptedSyntheticsMonitor>(
return await savedObjectsClient.create<EncryptedSyntheticsMonitorAttributes>(
syntheticsMonitorType,
formatSecrets({
...normalizedMonitor,
@ -176,7 +176,7 @@ export const syncNewMonitor = async ({
const { savedObjectsClient, server, syntheticsMonitorClient, request, spaceId } = routeContext;
const newMonitorId = id ?? uuidV4();
let monitorSavedObject: SavedObject<EncryptedSyntheticsMonitor> | null = null;
let monitorSavedObject: SavedObject<EncryptedSyntheticsMonitorAttributes> | null = null;
const monitorWithNamespace = hydrateMonitorFields({
normalizedMonitor,
routeContext,
@ -249,7 +249,7 @@ export const deleteMonitorIfCreated = async ({
}) => {
const { server, savedObjectsClient } = routeContext;
try {
const encryptedMonitor = await savedObjectsClient.get<EncryptedSyntheticsMonitor>(
const encryptedMonitor = await savedObjectsClient.get<EncryptedSyntheticsMonitorAttributes>(
syntheticsMonitorType,
newMonitorId
);

View file

@ -19,7 +19,7 @@ import { formatSecrets } from '../../../synthetics_service/utils';
import { syntheticsMonitorType } from '../../../../common/types/saved_objects';
import {
ConfigKey,
EncryptedSyntheticsMonitor,
EncryptedSyntheticsMonitorAttributes,
MonitorFields,
PrivateLocation,
ServiceLocationErrors,
@ -44,13 +44,14 @@ export const createNewSavedObjectMonitorBulk = async ({
}),
}));
const result = await soClient.bulkCreate<EncryptedSyntheticsMonitor>(newMonitors);
const result = await soClient.bulkCreate<EncryptedSyntheticsMonitorAttributes>(newMonitors);
return result.saved_objects;
};
type MonitorSavedObject = SavedObject<EncryptedSyntheticsMonitor>;
type MonitorSavedObject = SavedObject<EncryptedSyntheticsMonitorAttributes>;
type CreatedMonitors = SavedObjectsBulkResponse<EncryptedSyntheticsMonitor>['saved_objects'];
type CreatedMonitors =
SavedObjectsBulkResponse<EncryptedSyntheticsMonitorAttributes>['saved_objects'];
export const syncNewMonitorBulk = async ({
routeContext,
@ -169,7 +170,7 @@ const rollBackNewMonitorBulk = async (
const sendNewMonitorTelemetry = (
server: SyntheticsServerSetup,
monitors: Array<SavedObject<EncryptedSyntheticsMonitor>>,
monitors: Array<SavedObject<EncryptedSyntheticsMonitorAttributes>>,
errors?: ServiceLocationErrors | null
) => {
for (const monitor of monitors) {

View file

@ -16,7 +16,7 @@ import {
ConfigKey,
MonitorFields,
SyntheticsMonitor,
EncryptedSyntheticsMonitor,
EncryptedSyntheticsMonitorAttributes,
SyntheticsMonitorWithId,
} from '../../../../common/runtime_types';
import { SyntheticsMonitorClient } from '../../../synthetics_service/synthetics_monitor/synthetics_monitor_client';
@ -31,7 +31,7 @@ export const deleteMonitorBulk = async ({
}: {
savedObjectsClient: SavedObjectsClientContract;
server: SyntheticsServerSetup;
monitors: Array<SavedObject<SyntheticsMonitor | EncryptedSyntheticsMonitor>>;
monitors: Array<SavedObject<SyntheticsMonitor | EncryptedSyntheticsMonitorAttributes>>;
syntheticsMonitorClient: SyntheticsMonitorClient;
request: KibanaRequest;
}) => {

View file

@ -11,12 +11,12 @@ import { syntheticsMonitorType } from '../../../../common/types/saved_objects';
import { FailedPolicyUpdate } from '../../../synthetics_service/private_location/synthetics_private_location';
import {
ConfigKey,
EncryptedSyntheticsMonitor,
EncryptedSyntheticsMonitorAttributes,
HeartbeatConfig,
MonitorFields,
PrivateLocation,
SyntheticsMonitor,
SyntheticsMonitorWithSecrets,
SyntheticsMonitorWithSecretsAttributes,
} from '../../../../common/runtime_types';
import {
formatTelemetryUpdateEvent,
@ -27,9 +27,9 @@ import {
interface MonitorConfigUpdate {
normalizedMonitor: SyntheticsMonitor;
monitorWithRevision: SyntheticsMonitorWithSecrets;
previousMonitor: SavedObject<EncryptedSyntheticsMonitor>;
decryptedPreviousMonitor: SavedObject<SyntheticsMonitorWithSecrets>;
monitorWithRevision: SyntheticsMonitorWithSecretsAttributes;
previousMonitor: SavedObject<EncryptedSyntheticsMonitorAttributes>;
decryptedPreviousMonitor: SavedObject<SyntheticsMonitorWithSecretsAttributes>;
}
const updateConfigSavedObjects = async ({
@ -114,7 +114,7 @@ export const syncEditedMonitorBulk = async ({
server.logger,
server.telemetry,
formatTelemetryUpdateEvent(
editedMonitorSavedObject as SavedObjectsUpdateResponse<EncryptedSyntheticsMonitor>,
editedMonitorSavedObject as SavedObjectsUpdateResponse<EncryptedSyntheticsMonitorAttributes>,
previousMonitor,
server.stackVersion,
Boolean((normalizedMonitor as MonitorFields)[ConfigKey.SOURCE_INLINE]),
@ -168,8 +168,8 @@ export const rollbackFailedUpdates = async ({
monitorsToUpdate,
}: {
monitorsToUpdate: Array<{
previousMonitor: SavedObject<EncryptedSyntheticsMonitor>;
decryptedPreviousMonitor: SavedObject<SyntheticsMonitorWithSecrets>;
previousMonitor: SavedObject<EncryptedSyntheticsMonitorAttributes>;
decryptedPreviousMonitor: SavedObject<SyntheticsMonitorWithSecretsAttributes>;
}>;
routeContext: RouteContext;
failedPolicyUpdates?: FailedPolicyUpdate[];

View file

@ -11,10 +11,10 @@ import { RouteContext, SyntheticsRestApiRouteFactory } from '../types';
import { syntheticsMonitorType } from '../../../common/types/saved_objects';
import {
ConfigKey,
EncryptedSyntheticsMonitor,
EncryptedSyntheticsMonitorAttributes,
MonitorFields,
SyntheticsMonitorWithId,
SyntheticsMonitorWithSecrets,
SyntheticsMonitorWithSecretsAttributes,
} from '../../../common/runtime_types';
import { SYNTHETICS_API_URLS } from '../../../common/constants';
import { getMonitorNotFoundResponse } from '../synthetics_service/service_errors';
@ -146,7 +146,7 @@ const getMonitorToDelete = async (
try {
const monitor =
await encryptedSOClient.getDecryptedAsInternalUser<SyntheticsMonitorWithSecrets>(
await encryptedSOClient.getDecryptedAsInternalUser<SyntheticsMonitorWithSecretsAttributes>(
syntheticsMonitorType,
monitorId,
{
@ -166,7 +166,10 @@ const getMonitorToDelete = async (
});
}
const monitor = await soClient.get<EncryptedSyntheticsMonitor>(syntheticsMonitorType, monitorId);
const monitor = await soClient.get<EncryptedSyntheticsMonitorAttributes>(
syntheticsMonitorType,
monitorId
);
return { monitor, withSecrets: false };
};
@ -176,11 +179,14 @@ const restoreDeletedMonitor = async ({
normalizedMonitor,
}: {
monitorId: string;
normalizedMonitor: SyntheticsMonitorWithSecrets;
normalizedMonitor: SyntheticsMonitorWithSecretsAttributes;
savedObjectsClient: SavedObjectsClientContract;
}) => {
try {
await savedObjectsClient.get<EncryptedSyntheticsMonitor>(syntheticsMonitorType, monitorId);
await savedObjectsClient.get<EncryptedSyntheticsMonitorAttributes>(
syntheticsMonitorType,
monitorId
);
} catch (e) {
if (SavedObjectsErrorHelpers.isNotFoundError(e)) {
await savedObjectsClient.create(syntheticsMonitorType, normalizedMonitor, {

View file

@ -9,9 +9,9 @@ import { loggerMock } from '@kbn/logging-mocks';
import { syncEditedMonitor } from './edit_monitor';
import { SavedObject, SavedObjectsClientContract, KibanaRequest } from '@kbn/core/server';
import {
EncryptedSyntheticsMonitor,
EncryptedSyntheticsMonitorAttributes,
SyntheticsMonitor,
SyntheticsMonitorWithSecrets,
SyntheticsMonitorWithSecretsAttributes,
} from '../../../common/runtime_types';
import { SyntheticsService } from '../../synthetics_service/synthetics_service';
import { SyntheticsMonitorClient } from '../../synthetics_service/synthetics_monitor/synthetics_monitor_client';
@ -79,7 +79,7 @@ describe('syncEditedMonitor', () => {
attributes: { name: editedMonitor.name, locations: [] } as any,
type: 'synthetics-monitor',
references: [],
} as SavedObject<EncryptedSyntheticsMonitor>;
} as SavedObject<EncryptedSyntheticsMonitorAttributes>;
const syntheticsService = new SyntheticsService(serverMock);
@ -92,7 +92,7 @@ describe('syncEditedMonitor', () => {
normalizedMonitor: editedMonitor,
previousMonitor,
decryptedPreviousMonitor:
previousMonitor as unknown as SavedObject<SyntheticsMonitorWithSecrets>,
previousMonitor as unknown as SavedObject<SyntheticsMonitorWithSecretsAttributes>,
routeContext: {
syntheticsMonitorClient,
server: serverMock,

View file

@ -14,8 +14,8 @@ import { syntheticsMonitorType } from '../../../common/types/saved_objects';
import { getSyntheticsPrivateLocations } from '../../saved_objects/private_locations';
import {
MonitorFields,
EncryptedSyntheticsMonitor,
SyntheticsMonitorWithSecrets,
EncryptedSyntheticsMonitorAttributes,
SyntheticsMonitorWithSecretsAttributes,
SyntheticsMonitor,
ConfigKey,
} from '../../../common/runtime_types';
@ -48,16 +48,14 @@ export const editSyntheticsMonitorRoute: SyntheticsRestApiRouteFactory = () => (
try {
const spaceId = server.spaces?.spacesService.getSpaceId(request) ?? DEFAULT_SPACE_ID;
const previousMonitor: SavedObject<EncryptedSyntheticsMonitor> = await savedObjectsClient.get(
syntheticsMonitorType,
monitorId
);
const previousMonitor: SavedObject<EncryptedSyntheticsMonitorAttributes> =
await savedObjectsClient.get(syntheticsMonitorType, monitorId);
/* Decrypting the previous monitor before editing ensures that all existing fields remain
* on the object, even in flows where decryption does not take place, such as the enabled tab
* on the monitor list table. We do not decrypt monitors in bulk for the monitor list table */
const decryptedPreviousMonitor =
await encryptedSavedObjectsClient.getDecryptedAsInternalUser<SyntheticsMonitorWithSecrets>(
await encryptedSavedObjectsClient.getDecryptedAsInternalUser<SyntheticsMonitorWithSecretsAttributes>(
syntheticsMonitorType,
monitorId,
{
@ -135,7 +133,7 @@ const rollbackUpdate = async ({
configId,
attributes,
}: {
attributes: SyntheticsMonitorWithSecrets;
attributes: SyntheticsMonitorWithSecretsAttributes;
configId: string;
routeContext: RouteContext;
}) => {
@ -155,8 +153,8 @@ export const syncEditedMonitor = async ({
routeContext,
}: {
normalizedMonitor: SyntheticsMonitor;
previousMonitor: SavedObject<EncryptedSyntheticsMonitor>;
decryptedPreviousMonitor: SavedObject<SyntheticsMonitorWithSecrets>;
previousMonitor: SavedObject<EncryptedSyntheticsMonitorAttributes>;
decryptedPreviousMonitor: SavedObject<SyntheticsMonitorWithSecretsAttributes>;
routeContext: RouteContext;
spaceId: string;
}) => {
@ -203,7 +201,7 @@ export const syncEditedMonitor = async ({
server.logger,
server.telemetry,
formatTelemetryUpdateEvent(
editedMonitorSavedObject as SavedObjectsUpdateResponse<EncryptedSyntheticsMonitor>,
editedMonitorSavedObject as SavedObjectsUpdateResponse<EncryptedSyntheticsMonitorAttributes>,
previousMonitor,
server.stackVersion,
Boolean((normalizedMonitor as MonitorFields)[ConfigKey.SOURCE_INLINE]),

View file

@ -12,7 +12,7 @@ import { syntheticsMonitorType } from '../../../common/types/saved_objects';
import { isStatusEnabled } from '../../../common/runtime_types/monitor_management/alert_config';
import {
ConfigKey,
EncryptedSyntheticsMonitor,
EncryptedSyntheticsMonitorAttributes,
MonitorOverviewItem,
} from '../../../common/runtime_types';
import { SYNTHETICS_API_URLS } from '../../../common/constants';
@ -44,7 +44,10 @@ export const getSyntheticsMonitorRoute: SyntheticsRestApiRouteFactory = () => ({
if (!decrypted) {
return mapSavedObjectToMonitor(
await savedObjectsClient.get<EncryptedSyntheticsMonitor>(syntheticsMonitorType, monitorId)
await savedObjectsClient.get<EncryptedSyntheticsMonitorAttributes>(
syntheticsMonitorType,
monitorId
)
);
} else {
// only user with write permissions can decrypt the monitor
@ -124,7 +127,7 @@ export const getSyntheticsMonitorOverviewRoute: SyntheticsRestApiRouteFactory =
});
export function getOverviewConfigsPerLocation(
attributes: EncryptedSyntheticsMonitor,
attributes: EncryptedSyntheticsMonitorAttributes,
queriedLocations?: string | string[]
) {
const id = attributes[ConfigKey.MONITOR_QUERY_ID];

View file

@ -6,8 +6,8 @@
*/
import { SavedObject } from '@kbn/core/server';
import { EncryptedSyntheticsMonitor } from '../../../common/runtime_types';
import { EncryptedSyntheticsMonitorAttributes } from '../../../common/runtime_types';
export function mapSavedObjectToMonitor(so: SavedObject<EncryptedSyntheticsMonitor>) {
export function mapSavedObjectToMonitor(so: SavedObject<EncryptedSyntheticsMonitorAttributes>) {
return Object.assign(so.attributes, { created_at: so.created_at, updated_at: so.updated_at });
}

View file

@ -11,7 +11,7 @@ import { queryMonitorStatus } from '../../queries/query_monitor_status';
import { getStatus } from './overview_status';
import times from 'lodash/times';
import * as monitorsFns from '../../saved_objects/synthetics_monitor/get_all_monitors';
import { EncryptedSyntheticsMonitor } from '../../../common/runtime_types';
import { EncryptedSyntheticsMonitorAttributes } from '../../../common/runtime_types';
import { RouteContext } from '../types';
import { getUptimeESMockClient } from '../../legacy_uptime/lib/requests/test_helpers';
@ -624,7 +624,7 @@ describe('current status route', () => {
namespaces: ['default'],
score: null,
sort: ['a', 3013],
} as unknown as SavedObjectsFindResult<EncryptedSyntheticsMonitor>,
} as unknown as SavedObjectsFindResult<EncryptedSyntheticsMonitorAttributes>,
]);
const { esClient, uptimeEsClient } = getUptimeESMockClient();
esClient.search.mockResponseOnce(
@ -790,7 +790,7 @@ describe('current status route', () => {
namespaces: ['default'],
score: null,
sort: ['a', 3013],
} as unknown as SavedObjectsFindResult<EncryptedSyntheticsMonitor>,
} as unknown as SavedObjectsFindResult<EncryptedSyntheticsMonitorAttributes>,
]);
const { esClient, uptimeEsClient } = getUptimeESMockClient();
esClient.search.mockResponseOnce(getEsResponse([]));

View file

@ -12,7 +12,7 @@ import { TestNowResponse } from '../../../common/types';
import {
ConfigKey,
MonitorFields,
SyntheticsMonitorWithSecrets,
SyntheticsMonitorWithSecretsAttributes,
} from '../../../common/runtime_types';
import { SYNTHETICS_API_URLS } from '../../../common/constants';
import { normalizeSecrets } from '../../synthetics_service/utils/secrets';
@ -38,7 +38,7 @@ export const triggerTestNow = async (
const encryptedClient = server.encryptedSavedObjects.getClient();
const monitorWithSecrets =
await encryptedClient.getDecryptedAsInternalUser<SyntheticsMonitorWithSecrets>(
await encryptedClient.getDecryptedAsInternalUser<SyntheticsMonitorWithSecretsAttributes>(
syntheticsMonitorType,
monitorId,
{

View file

@ -18,7 +18,7 @@ import {
import { MonitorErrorEvent } from '../../telemetry/types';
import {
MonitorFields,
EncryptedSyntheticsMonitor,
EncryptedSyntheticsMonitorAttributes,
ConfigKey,
ServiceLocationErrors,
SourceType,
@ -67,7 +67,7 @@ export function formatTelemetryEvent({
deletedAt,
errors,
}: {
monitor: SavedObject<EncryptedSyntheticsMonitor>;
monitor: SavedObject<EncryptedSyntheticsMonitorAttributes>;
stackVersion: string;
isInlineScript: boolean;
lastUpdatedAt?: string;
@ -108,8 +108,8 @@ export function formatTelemetryEvent({
}
export function formatTelemetryUpdateEvent(
currentMonitor: SavedObjectsUpdateResponse<EncryptedSyntheticsMonitor>,
previousMonitor: SavedObject<EncryptedSyntheticsMonitor>,
currentMonitor: SavedObjectsUpdateResponse<EncryptedSyntheticsMonitorAttributes>,
previousMonitor: SavedObject<EncryptedSyntheticsMonitorAttributes>,
stackVersion: string,
isInlineScript: boolean,
errors?: ServiceLocationErrors | null
@ -123,7 +123,7 @@ export function formatTelemetryUpdateEvent(
return formatTelemetryEvent({
stackVersion,
monitor: currentMonitor as SavedObject<EncryptedSyntheticsMonitor>,
monitor: currentMonitor as SavedObject<EncryptedSyntheticsMonitorAttributes>,
durationSinceLastUpdated,
lastUpdatedAt: previousMonitor.updated_at,
isInlineScript,
@ -132,7 +132,7 @@ export function formatTelemetryUpdateEvent(
}
export function formatTelemetryDeleteEvent(
previousMonitor: SavedObject<EncryptedSyntheticsMonitor>,
previousMonitor: SavedObject<EncryptedSyntheticsMonitorAttributes>,
stackVersion: string,
deletedAt: string,
isInlineScript: boolean,
@ -146,7 +146,7 @@ export function formatTelemetryDeleteEvent(
return formatTelemetryEvent({
stackVersion,
monitor: previousMonitor as SavedObject<EncryptedSyntheticsMonitor>,
monitor: previousMonitor as SavedObject<EncryptedSyntheticsMonitorAttributes>,
durationSinceLastUpdated,
lastUpdatedAt: previousMonitor.updated_at,
deletedAt,

View file

@ -10,7 +10,7 @@ import { migrationMocks } from '@kbn/core/server/mocks';
import {
ConfigKey,
LocationStatus,
SyntheticsMonitorWithSecrets,
SyntheticsMonitorWithSecretsAttributes,
} from '../../../../common/runtime_types';
const context = migrationMocks.createContext();
@ -53,7 +53,7 @@ const monitor850UI = {
revision: 1,
secrets:
'{"password":"","check.request.body":{"type":"text","value":""},"check.request.headers":{},"check.response.body.negative":[],"check.response.body.positive":[],"check.response.headers":{},"ssl.key":"","ssl.key_passphrase":"","username":""}',
} as SyntheticsMonitorWithSecrets,
} as SyntheticsMonitorWithSecretsAttributes,
references: [],
coreMigrationVersion: '8.5.0',
};
@ -119,7 +119,7 @@ const monitor850Project = {
revision: 1,
secrets:
'{"params":"{\\"url\\":\\"https://elastic.github.io/synthetics-demo/\\"}","source.inline.script":"","source.project.content":"UEsDBBQACAAIAAAAIQAAAAAAAAAAAAAAAAAXAAAAam91cm5leXMvb25lLmpvdXJuZXkudHNVkL1uwzAMhHc/BeFJAQyrLdAlQYouXbp3KjqwMhMrlUVVohMYgd+9in+AdCHED6c7kloDpkSy1R+JYtINd9bb356Mw/hDuqGzToOXlsSapIWSPOkT99HTkDR7qpemllTYLnAUuMLCKkhCoYKOvRWOMMIhcgflKzlM2e/OudwVZ4xgIqHQ+/wd9qA8drSB/QtcC1h96j6RuvUA0kYWcdYftzATgIYv3jE2W3h8qBbWh5k8r8DlGG+Gm2YiY67jZpfrMvuUXIG6QsBjfgSM2KWsWYeBaTlVOuy9aQFDcNagWPZllW86eAPqTgyAF7QyudVHFlazY91HN+Wu+bc67orPErNP+V1+1QeOb2hapXDy+3ejzLL+D1BLBwgqc7lrFgEAAMYBAABQSwECLQMUAAgACAAAACEAKnO5axYBAADGAQAAFwAAAAAAAAAAACAApIEAAAAAam91cm5leXMvb25lLmpvdXJuZXkudHNQSwUGAAAAAAEAAQBFAAAAWwEAAAAA","source.zip_url.username":"","source.zip_url.password":"","synthetics_args":[],"ssl.key":"","ssl.key_passphrase":""}',
} as SyntheticsMonitorWithSecrets,
} as SyntheticsMonitorWithSecretsAttributes,
references: [],
coreMigrationVersion: '8.5.0',
};

View file

@ -6,22 +6,25 @@
*/
import { EncryptedSavedObjectsPluginSetup } from '@kbn/encrypted-saved-objects-plugin/server';
import { SavedObjectUnsanitizedDoc } from '@kbn/core/server';
import { ConfigKey, SyntheticsMonitorWithSecrets } from '../../../../common/runtime_types';
import {
ConfigKey,
SyntheticsMonitorWithSecretsAttributes,
} from '../../../../common/runtime_types';
import { LEGACY_SYNTHETICS_MONITOR_ENCRYPTED_TYPE } from '../../synthetics_monitor';
export const migration860 = (encryptedSavedObjects: EncryptedSavedObjectsPluginSetup) => {
return encryptedSavedObjects.createMigration<
SyntheticsMonitorWithSecrets,
SyntheticsMonitorWithSecrets
SyntheticsMonitorWithSecretsAttributes,
SyntheticsMonitorWithSecretsAttributes
>({
isMigrationNeededPredicate: function shouldBeMigrated(
doc
): doc is SavedObjectUnsanitizedDoc<SyntheticsMonitorWithSecrets> {
): doc is SavedObjectUnsanitizedDoc<SyntheticsMonitorWithSecretsAttributes> {
return true;
},
migration: (
doc: SavedObjectUnsanitizedDoc<SyntheticsMonitorWithSecrets>
): SavedObjectUnsanitizedDoc<SyntheticsMonitorWithSecrets> => {
doc: SavedObjectUnsanitizedDoc<SyntheticsMonitorWithSecretsAttributes>
): SavedObjectUnsanitizedDoc<SyntheticsMonitorWithSecretsAttributes> => {
const { attributes, id } = doc;
return {
...doc,

View file

@ -13,7 +13,7 @@ import {
ConfigKey,
MonitorFields,
ScheduleUnit,
SyntheticsMonitorWithSecrets,
SyntheticsMonitorWithSecretsAttributes,
ThrottlingConfig,
} from '../../../../common/runtime_types';
import {
@ -35,18 +35,18 @@ import {
export const migration880 = (encryptedSavedObjects: EncryptedSavedObjectsPluginSetup) => {
return encryptedSavedObjects.createMigration<
SyntheticsMonitorWithSecrets,
SyntheticsMonitorWithSecrets
SyntheticsMonitorWithSecretsAttributes,
SyntheticsMonitorWithSecretsAttributes
>({
isMigrationNeededPredicate: function shouldBeMigrated(
doc
): doc is SavedObjectUnsanitizedDoc<SyntheticsMonitorWithSecrets> {
): doc is SavedObjectUnsanitizedDoc<SyntheticsMonitorWithSecretsAttributes> {
return true;
},
migration: (
doc: SavedObjectUnsanitizedDoc<SyntheticsMonitorWithSecrets>,
doc: SavedObjectUnsanitizedDoc<SyntheticsMonitorWithSecretsAttributes>,
logger
): SavedObjectUnsanitizedDoc<SyntheticsMonitorWithSecrets> => {
): SavedObjectUnsanitizedDoc<SyntheticsMonitorWithSecretsAttributes> => {
let migrated = doc;
migrated = {
...migrated,
@ -131,7 +131,7 @@ const omitZipUrlFields = (fields: BrowserFields) => {
const updateThrottlingFields = (
doc: SavedObjectUnsanitizedDoc<
SyntheticsMonitorWithSecrets &
SyntheticsMonitorWithSecretsAttributes &
Partial<{
[LegacyConfigKey.THROTTLING_CONFIG]: string;
[LegacyConfigKey.IS_THROTTLING_ENABLED]: boolean;

View file

@ -6,22 +6,25 @@
*/
import { EncryptedSavedObjectsPluginSetup } from '@kbn/encrypted-saved-objects-plugin/server';
import { SavedObjectUnsanitizedDoc } from '@kbn/core/server';
import { ConfigKey, SyntheticsMonitorWithSecrets } from '../../../../common/runtime_types';
import {
ConfigKey,
SyntheticsMonitorWithSecretsAttributes,
} from '../../../../common/runtime_types';
import { SYNTHETICS_MONITOR_ENCRYPTED_TYPE } from '../../synthetics_monitor';
export const migration890 = (encryptedSavedObjects: EncryptedSavedObjectsPluginSetup) => {
return encryptedSavedObjects.createMigration<
SyntheticsMonitorWithSecrets,
SyntheticsMonitorWithSecrets
SyntheticsMonitorWithSecretsAttributes,
SyntheticsMonitorWithSecretsAttributes
>({
isMigrationNeededPredicate: function shouldBeMigrated(
doc
): doc is SavedObjectUnsanitizedDoc<SyntheticsMonitorWithSecrets> {
): doc is SavedObjectUnsanitizedDoc<SyntheticsMonitorWithSecretsAttributes> {
return true;
},
migration: (
doc: SavedObjectUnsanitizedDoc<SyntheticsMonitorWithSecrets>
): SavedObjectUnsanitizedDoc<SyntheticsMonitorWithSecrets> => {
doc: SavedObjectUnsanitizedDoc<SyntheticsMonitorWithSecretsAttributes>
): SavedObjectUnsanitizedDoc<SyntheticsMonitorWithSecretsAttributes> => {
let migrated = doc;
migrated = {
...migrated,

View file

@ -5,7 +5,7 @@
* 2.0.
*/
import { SavedObjectUnsanitizedDoc } from '@kbn/core/server';
import { SyntheticsMonitorWithSecrets } from '../../../../../common/runtime_types';
import { SyntheticsMonitorWithSecretsAttributes } from '../../../../../common/runtime_types';
export const httpUI = {
type: 'synthetics-monitor',
@ -46,4 +46,4 @@ export const httpUI = {
coreMigrationVersion: '8.8.0',
updated_at: '2023-04-11T17:42:11.734Z',
typeMigrationVersion: '8.6.0',
} as SavedObjectUnsanitizedDoc<SyntheticsMonitorWithSecrets>;
} as SavedObjectUnsanitizedDoc<SyntheticsMonitorWithSecretsAttributes>;

View file

@ -5,7 +5,7 @@
* 2.0.
*/
import { SavedObjectUnsanitizedDoc } from '@kbn/core/server';
import { SyntheticsMonitorWithSecrets } from '../../../../../common/runtime_types';
import { SyntheticsMonitorWithSecretsAttributes } from '../../../../../common/runtime_types';
export const browserUI = {
type: 'synthetics-monitor',
@ -68,7 +68,7 @@ export const browserUI = {
updated_at: '2023-03-31T20:31:24.177Z',
created_at: '2023-03-31T20:31:24.177Z',
typeMigrationVersion: '8.6.0',
} as SavedObjectUnsanitizedDoc<SyntheticsMonitorWithSecrets>;
} as SavedObjectUnsanitizedDoc<SyntheticsMonitorWithSecretsAttributes>;
export const browserSinglePageUI = {
type: 'synthetics-monitor',
id: '7a72e681-6033-444e-b402-bddbe4a9fc4e',
@ -123,7 +123,7 @@ export const browserSinglePageUI = {
updated_at: '2023-03-31T20:32:01.498Z',
created_at: '2023-03-31T20:32:01.498Z',
typeMigrationVersion: '8.6.0',
} as SavedObjectUnsanitizedDoc<SyntheticsMonitorWithSecrets>;
} as SavedObjectUnsanitizedDoc<SyntheticsMonitorWithSecretsAttributes>;
export const httpUI = {
type: 'synthetics-monitor',
id: '8f4ad634-205b-440b-80c6-27aa6ef57bba',
@ -166,7 +166,7 @@ export const httpUI = {
updated_at: '2023-03-31T20:32:14.362Z',
created_at: '2023-03-31T20:32:14.362Z',
typeMigrationVersion: '8.6.0',
} as SavedObjectUnsanitizedDoc<SyntheticsMonitorWithSecrets>;
} as SavedObjectUnsanitizedDoc<SyntheticsMonitorWithSecretsAttributes>;
export const tcpUI = {
type: 'synthetics-monitor',
id: 'b56a8fab-9a69-4435-b368-cc4fe6cdc6b0',
@ -205,7 +205,7 @@ export const tcpUI = {
updated_at: '2023-03-31T20:32:27.678Z',
created_at: '2023-03-31T20:32:27.678Z',
typeMigrationVersion: '8.6.0',
} as SavedObjectUnsanitizedDoc<SyntheticsMonitorWithSecrets>;
} as SavedObjectUnsanitizedDoc<SyntheticsMonitorWithSecretsAttributes>;
const icmpUI = {
type: 'synthetics-monitor',
id: '1b625301-fe0b-46c0-9980-21347c58a6f8',
@ -236,7 +236,7 @@ const icmpUI = {
updated_at: '2023-03-31T20:32:39.147Z',
created_at: '2023-03-31T20:32:39.147Z',
typeMigrationVersion: '8.6.0',
} as SavedObjectUnsanitizedDoc<SyntheticsMonitorWithSecrets>;
} as SavedObjectUnsanitizedDoc<SyntheticsMonitorWithSecretsAttributes>;
export const browserUptimeUI = {
type: 'synthetics-monitor',
id: '9bf12063-271f-47b1-9121-db1d14a71bb3',
@ -299,7 +299,7 @@ export const browserUptimeUI = {
updated_at: '2023-03-31T20:35:34.916Z',
created_at: '2023-03-31T20:35:34.916Z',
typeMigrationVersion: '8.6.0',
} as SavedObjectUnsanitizedDoc<SyntheticsMonitorWithSecrets>;
} as SavedObjectUnsanitizedDoc<SyntheticsMonitorWithSecretsAttributes>;
export const tcpUptimeUI = {
type: 'synthetics-monitor',
id: '726d3f74-7760-4045-ad8d-87642403c721',
@ -345,7 +345,7 @@ export const tcpUptimeUI = {
updated_at: '2023-03-31T20:38:29.582Z',
created_at: '2023-03-31T20:38:29.582Z',
typeMigrationVersion: '8.6.0',
} as SavedObjectUnsanitizedDoc<SyntheticsMonitorWithSecrets>;
} as SavedObjectUnsanitizedDoc<SyntheticsMonitorWithSecretsAttributes>;
export const httpUptimeUI = {
type: 'synthetics-monitor',
id: '35b2d765-4a62-4511-91c8-d5d52fdf4639',
@ -395,7 +395,7 @@ export const httpUptimeUI = {
updated_at: '2023-03-31T20:37:24.093Z',
created_at: '2023-03-31T20:37:24.093Z',
typeMigrationVersion: '8.6.0',
} as SavedObjectUnsanitizedDoc<SyntheticsMonitorWithSecrets>;
} as SavedObjectUnsanitizedDoc<SyntheticsMonitorWithSecretsAttributes>;
export const icmpUptimeUI = {
type: 'synthetics-monitor',
id: '28b14c99-4a39-475d-9545-21b35b35751d',
@ -433,7 +433,7 @@ export const icmpUptimeUI = {
updated_at: '2023-03-31T20:40:28.889Z',
created_at: '2023-03-31T20:39:13.783Z',
typeMigrationVersion: '8.6.0',
} as SavedObjectUnsanitizedDoc<SyntheticsMonitorWithSecrets>;
} as SavedObjectUnsanitizedDoc<SyntheticsMonitorWithSecretsAttributes>;
export const browserProject = {
type: 'synthetics-monitor',
id: 'ea123f46-eb02-4a8a-b3ce-53e645ce4aef',
@ -497,7 +497,7 @@ export const browserProject = {
updated_at: '2023-03-31T20:43:35.214Z',
created_at: '2023-03-31T20:43:35.214Z',
typeMigrationVersion: '8.6.0',
} as SavedObjectUnsanitizedDoc<SyntheticsMonitorWithSecrets>;
} as SavedObjectUnsanitizedDoc<SyntheticsMonitorWithSecretsAttributes>;
export const httpProject = {
type: 'synthetics-monitor',
id: '316c0df8-56fc-428a-a477-7bf580f6cb4c',
@ -550,7 +550,7 @@ export const httpProject = {
updated_at: '2023-03-31T20:43:35.214Z',
created_at: '2023-03-31T20:43:35.214Z',
typeMigrationVersion: '8.6.0',
} as SavedObjectUnsanitizedDoc<SyntheticsMonitorWithSecrets>;
} as SavedObjectUnsanitizedDoc<SyntheticsMonitorWithSecretsAttributes>;
export const icmpProject = {
type: 'synthetics-monitor',
id: 'e21a30b5-6d40-4458-8cff-9003d7b83eb6',
@ -591,7 +591,7 @@ export const icmpProject = {
updated_at: '2023-03-31T20:43:35.214Z',
created_at: '2023-03-31T20:43:35.214Z',
typeMigrationVersion: '8.6.0',
} as SavedObjectUnsanitizedDoc<SyntheticsMonitorWithSecrets>;
} as SavedObjectUnsanitizedDoc<SyntheticsMonitorWithSecretsAttributes>;
export const tcpProject = {
type: 'synthetics-monitor',
id: '9f5d6206-9a1d-47fb-bd67-c7895b07f716',
@ -640,7 +640,7 @@ export const tcpProject = {
updated_at: '2023-03-31T20:47:15.781Z',
created_at: '2023-03-31T20:43:35.214Z',
typeMigrationVersion: '8.6.0',
} as SavedObjectUnsanitizedDoc<SyntheticsMonitorWithSecrets>;
} as SavedObjectUnsanitizedDoc<SyntheticsMonitorWithSecretsAttributes>;
export const testMonitors = [
browserUI,

View file

@ -18,7 +18,7 @@ import { periodToMs } from '../../routes/overview_status/overview_status';
import { getAllLocations } from '../../synthetics_service/get_all_locations';
import {
ConfigKey,
EncryptedSyntheticsMonitor,
EncryptedSyntheticsMonitorAttributes,
ServiceLocation,
SourceType,
} from '../../../common/runtime_types';
@ -37,7 +37,7 @@ export const getAllMonitors = async ({
search?: string;
filter?: string;
} & Pick<SavedObjectsFindOptions, 'sortField' | 'sortOrder' | 'fields' | 'searchFields'>) => {
const finder = soClient.createPointInTimeFinder<EncryptedSyntheticsMonitor>({
const finder = soClient.createPointInTimeFinder<EncryptedSyntheticsMonitorAttributes>({
type: syntheticsMonitorType,
perPage: 1000,
search,
@ -48,7 +48,7 @@ export const getAllMonitors = async ({
searchFields,
});
const hits: Array<SavedObjectsFindResult<EncryptedSyntheticsMonitor>> = [];
const hits: Array<SavedObjectsFindResult<EncryptedSyntheticsMonitorAttributes>> = [];
for await (const result of finder.find()) {
hits.push(...result.saved_objects);
}
@ -60,7 +60,7 @@ export const getAllMonitors = async ({
};
export const processMonitors = async (
allMonitors: Array<SavedObjectsFindResult<EncryptedSyntheticsMonitor>>,
allMonitors: Array<SavedObjectsFindResult<EncryptedSyntheticsMonitorAttributes>>,
server: SyntheticsServerSetup,
soClient: SavedObjectsClientContract,
syntheticsMonitorClient: SyntheticsMonitorClient,

View file

@ -21,8 +21,8 @@ import { SyntheticsMonitorClient } from '../synthetics_monitor/synthetics_monito
import { syncEditedMonitorBulk } from '../../routes/monitor_cruds/bulk_cruds/edit_monitor_bulk';
import {
ConfigKey,
SyntheticsMonitorWithSecrets,
EncryptedSyntheticsMonitor,
SyntheticsMonitorWithSecretsAttributes,
EncryptedSyntheticsMonitorAttributes,
ServiceLocationErrors,
ProjectMonitor,
Locations,
@ -122,7 +122,7 @@ export class ProjectMonitorFormatter {
const normalizedNewMonitors: SyntheticsMonitor[] = [];
const normalizedUpdateMonitors: Array<{
previousMonitor: SavedObjectsFindResult<EncryptedSyntheticsMonitor>;
previousMonitor: SavedObjectsFindResult<EncryptedSyntheticsMonitorAttributes>;
monitor: SyntheticsMonitor;
}> = [];
@ -243,10 +243,12 @@ export class ProjectMonitorFormatter {
filter: this.projectFilter,
});
const hits: Array<SavedObjectsFindResult<EncryptedSyntheticsMonitor>> = [];
const hits: Array<SavedObjectsFindResult<EncryptedSyntheticsMonitorAttributes>> = [];
for await (const result of finder.find()) {
hits.push(
...(result.saved_objects as Array<SavedObjectsFindResult<EncryptedSyntheticsMonitor>>)
...(result.saved_objects as Array<
SavedObjectsFindResult<EncryptedSyntheticsMonitorAttributes>
>)
);
}
@ -323,12 +325,12 @@ export class ProjectMonitorFormatter {
};
private getDecryptedMonitors = async (
monitors: Array<SavedObjectsFindResult<EncryptedSyntheticsMonitor>>
monitors: Array<SavedObjectsFindResult<EncryptedSyntheticsMonitorAttributes>>
) => {
return await pMap(
monitors,
async (monitor) =>
this.encryptedSavedObjectsClient.getDecryptedAsInternalUser<SyntheticsMonitorWithSecrets>(
this.encryptedSavedObjectsClient.getDecryptedAsInternalUser<SyntheticsMonitorWithSecretsAttributes>(
syntheticsMonitorType,
monitor.id,
{
@ -342,11 +344,11 @@ export class ProjectMonitorFormatter {
private updateMonitorsBulk = async (
monitors: Array<{
monitor: SyntheticsMonitor;
previousMonitor: SavedObjectsFindResult<EncryptedSyntheticsMonitor>;
previousMonitor: SavedObjectsFindResult<EncryptedSyntheticsMonitorAttributes>;
}>
): Promise<
| {
editedMonitors: Array<SavedObjectsUpdateResponse<EncryptedSyntheticsMonitor>>;
editedMonitors: Array<SavedObjectsUpdateResponse<EncryptedSyntheticsMonitorAttributes>>;
errors: ServiceLocationErrors;
updatedCount: number;
}

View file

@ -22,13 +22,13 @@ import {
import { SyntheticsService } from '../synthetics_service';
import {
EncryptedSyntheticsMonitor,
EncryptedSyntheticsMonitorAttributes,
HeartbeatConfig,
MonitorFields,
MonitorServiceLocation,
PrivateLocation,
SyntheticsMonitorWithId,
SyntheticsMonitorWithSecrets,
SyntheticsMonitorWithSecretsAttributes,
} from '../../../common/runtime_types';
import {
ConfigData,
@ -90,8 +90,8 @@ export class SyntheticsMonitorClient {
monitors: Array<{
monitor: MonitorFields;
id: string;
previousMonitor: SavedObject<EncryptedSyntheticsMonitor>;
decryptedPreviousMonitor: SavedObject<SyntheticsMonitorWithSecrets>;
previousMonitor: SavedObject<EncryptedSyntheticsMonitorAttributes>;
decryptedPreviousMonitor: SavedObject<SyntheticsMonitorWithSecretsAttributes>;
}>,
routeContext: RouteContext,
allPrivateLocations: PrivateLocation[],
@ -176,7 +176,7 @@ export class SyntheticsMonitorClient {
return pubicResponse;
}
hasPrivateLocations(previousMonitor: SavedObject<EncryptedSyntheticsMonitor>) {
hasPrivateLocations(previousMonitor: SavedObject<EncryptedSyntheticsMonitorAttributes>) {
const { locations } = previousMonitor.attributes;
return locations.some((loc) => !loc.isServiceManaged);
@ -184,7 +184,7 @@ export class SyntheticsMonitorClient {
hasDeletedPublicLocations(
updatedLocations: MonitorServiceLocation[],
decryptedPreviousMonitor: SavedObject<SyntheticsMonitorWithSecrets>
decryptedPreviousMonitor: SavedObject<SyntheticsMonitorWithSecretsAttributes>
) {
const { locations } = decryptedPreviousMonitor.attributes;
@ -287,10 +287,10 @@ export class SyntheticsMonitorClient {
}) {
const encryptedClient = encryptedSavedObjects.getClient();
const monitors: Array<SavedObjectsFindResult<SyntheticsMonitorWithSecrets>> = [];
const monitors: Array<SavedObjectsFindResult<SyntheticsMonitorWithSecretsAttributes>> = [];
const finder =
await encryptedClient.createPointInTimeFinderDecryptedAsInternalUser<SyntheticsMonitorWithSecrets>(
await encryptedClient.createPointInTimeFinderDecryptedAsInternalUser<SyntheticsMonitorWithSecretsAttributes>(
{
type: syntheticsMonitorType,
perPage: 1000,
@ -312,7 +312,7 @@ export class SyntheticsMonitorClient {
mixParamsWithMonitors(
spaceId: string,
monitors: Array<SavedObjectsFindResult<SyntheticsMonitorWithSecrets>>,
monitors: Array<SavedObjectsFindResult<SyntheticsMonitorWithSecretsAttributes>>,
paramsBySpace: Record<string, Record<string, string>>
) {
const heartbeatConfigs: HeartbeatConfig[] = [];

View file

@ -30,12 +30,12 @@ import { ServiceAPIClient, ServiceData } from './service_api_client';
import {
ConfigKey,
EncryptedSyntheticsMonitor,
EncryptedSyntheticsMonitorAttributes,
MonitorFields,
ServiceLocationErrors,
ServiceLocations,
SyntheticsMonitorWithId,
SyntheticsMonitorWithSecrets,
SyntheticsMonitorWithSecretsAttributes,
SyntheticsParams,
ThrottlingOptions,
} from '../../common/runtime_types';
@ -507,7 +507,7 @@ export class SyntheticsService {
const paramsBySpace = await this.getSyntheticsParams();
const finder = soClient.createPointInTimeFinder<EncryptedSyntheticsMonitor>({
const finder = soClient.createPointInTimeFinder<EncryptedSyntheticsMonitorAttributes>({
type: syntheticsMonitorType,
perPage: 100,
namespaces: [ALL_SPACES_ID],
@ -539,7 +539,7 @@ export class SyntheticsService {
}
async decryptMonitors(
monitors: Array<SavedObject<EncryptedSyntheticsMonitor>>,
monitors: Array<SavedObject<EncryptedSyntheticsMonitorAttributes>>,
encryptedClient: EncryptedSavedObjectsClient
) {
const start = performance.now();
@ -549,7 +549,7 @@ export class SyntheticsService {
(monitor) =>
new Promise((resolve) => {
encryptedClient
.getDecryptedAsInternalUser<SyntheticsMonitorWithSecrets>(
.getDecryptedAsInternalUser<SyntheticsMonitorWithSecretsAttributes>(
syntheticsMonitorType,
monitor.id,
{
@ -583,7 +583,7 @@ export class SyntheticsService {
});
return decryptedMonitors.filter((monitor) => monitor !== null) as Array<
SavedObject<SyntheticsMonitorWithSecrets>
SavedObject<SyntheticsMonitorWithSecretsAttributes>
>;
}

View file

@ -10,12 +10,12 @@ import { secretKeys } from '../../../common/constants/monitor_management';
import {
ConfigKey,
SyntheticsMonitor,
SyntheticsMonitorWithSecrets,
SyntheticsMonitorWithSecretsAttributes,
} from '../../../common/runtime_types/monitor_management';
import { DEFAULT_FIELDS } from '../../../common/constants/monitor_defaults';
export function formatSecrets(monitor: SyntheticsMonitor): SyntheticsMonitorWithSecrets {
const monitorWithoutSecrets = omit(monitor, secretKeys) as SyntheticsMonitorWithSecrets;
export function formatSecrets(monitor: SyntheticsMonitor): SyntheticsMonitorWithSecretsAttributes {
const monitorWithoutSecrets = omit(monitor, secretKeys) as SyntheticsMonitorWithSecretsAttributes;
const secrets = pick(monitor, secretKeys);
return {
@ -25,7 +25,7 @@ export function formatSecrets(monitor: SyntheticsMonitor): SyntheticsMonitorWith
}
export function normalizeSecrets(
monitor: SavedObject<SyntheticsMonitorWithSecrets>
monitor: SavedObject<SyntheticsMonitorWithSecretsAttributes>
): SavedObject<SyntheticsMonitor> {
const attributes = normalizeMonitorSecretAttributes(monitor.attributes);
const normalizedMonitor = {
@ -36,7 +36,7 @@ export function normalizeSecrets(
}
export function normalizeMonitorSecretAttributes(
monitor: SyntheticsMonitorWithSecrets
monitor: SyntheticsMonitorWithSecretsAttributes
): SyntheticsMonitor {
const defaultFields = DEFAULT_FIELDS[monitor[ConfigKey.MONITOR_TYPE]];
const normalizedMonitorAttributes = {