Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ export { registerCoreObjectTypes } from './registration';

// set minimum number of registered saved objects to ensure no object types are removed after 8.8
// declared in internal implementation explicitly to prevent unintended changes.
export const SAVED_OBJECT_TYPES_COUNT = 149 as const;
export const SAVED_OBJECT_TYPES_COUNT = 151 as const;
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@

import type { TestElasticsearchUtils, TestKibanaUtils } from '@kbn/core-test-helpers-kbn-server';
import type { ElasticsearchClient } from '@kbn/core/server';
import type { EncryptedSavedObjectsClient } from '@kbn/encrypted-saved-objects-plugin/server';
import type { WorkflowsServerPluginSetup } from '@kbn/workflows-management-plugin/server';
import { ALERT_ACTIONS_DATA_STREAM, type AlertAction } from '../../../resources/alert_actions';
import { ALERT_EVENTS_DATA_STREAM, type AlertEvent } from '../../../resources/alert_events';
import type {
RuleSavedObjectAttributes,
NotificationPolicySavedObjectAttributes,
} from '../../../saved_objects';
import {
RULE_SAVED_OBJECT_TYPE,
NOTIFICATION_POLICY_SAVED_OBJECT_TYPE,
} from '../../../saved_objects';
import type { LoggerServiceContract } from '../../services/logger_service/logger_service';
import { createLoggerService } from '../../services/logger_service/logger_service.mock';
import { NotificationPolicySavedObjectService } from '../../services/notification_policy_saved_object_service/notification_policy_saved_object_service';
Expand Down Expand Up @@ -359,12 +364,17 @@ describe('DispatcherService integration tests', () => {
esClient = kibanaServer.coreStart.elasticsearch.client.asInternalUser;

rulesSoService = new RulesSavedObjectService(
(opts) => kibanaServer.coreStart.savedObjects.getUnsafeInternalClient(opts),
kibanaServer.coreStart.savedObjects.getUnsafeInternalClient({
includedHiddenTypes: [RULE_SAVED_OBJECT_TYPE],
}),
undefined as unknown as SpacesPluginStart
);
npSoService = new NotificationPolicySavedObjectService(
(opts) => kibanaServer.coreStart.savedObjects.getUnsafeInternalClient(opts),
undefined as unknown as SpacesPluginStart
kibanaServer.coreStart.savedObjects.getUnsafeInternalClient({
includedHiddenTypes: [NOTIFICATION_POLICY_SAVED_OBJECT_TYPE],
}),
undefined as unknown as SpacesPluginStart,
undefined as unknown as EncryptedSavedObjectsClient
);

await waitForDataStreamsReady(esClient, [ALERT_EVENTS_DATA_STREAM, ALERT_ACTIONS_DATA_STREAM]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ export function createNotificationPolicySavedObjectService(): {
mockBulkGetDecryptedByIds: jest.SpyInstance;
} {
const mockSavedObjectsClient = savedObjectsClientMock.create();
const mockSavedObjectsClientFactory = jest.fn().mockReturnValue(mockSavedObjectsClient);
const mockSpaces = spacesMock.createStart();
const mockEncryptedSavedObjectsClient = createMockEncryptedSavedObjectsClient();

const notificationPolicySavedObjectService = new NotificationPolicySavedObjectService(
mockSavedObjectsClientFactory,
mockSavedObjectsClient,
mockSpaces,
mockEncryptedSavedObjectsClient
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
*/

import { PluginStart } from '@kbn/core-di';
import type { ISavedObjectsClientFactory } from '@kbn/core-di-server';
import { SavedObjectsClientFactory } from '@kbn/core-di-server';
import type { SavedObjectsClientContract } from '@kbn/core/server';
import { SavedObjectsUtils } from '@kbn/core/server';
import type { SavedObjectError } from '@kbn/core/types';
Expand All @@ -20,6 +18,7 @@ import type { NotificationPolicySavedObjectAttributes } from '../../../saved_obj
import { NOTIFICATION_POLICY_SAVED_OBJECT_TYPE } from '../../../saved_objects';
import type { AlertingServerStartDependencies } from '../../../types';
import { spaceIdToNamespace } from '../../space_id_to_namespace';
import { NotificationPolicySavedObjectsClientToken } from './tokens';

export type NotificationPolicySavedObjectBulkGetItem =
| {
Expand Down Expand Up @@ -66,20 +65,14 @@ export interface NotificationPolicySavedObjectServiceContract {
export class NotificationPolicySavedObjectService
implements NotificationPolicySavedObjectServiceContract
{
private readonly client: SavedObjectsClientContract;

constructor(
@inject(SavedObjectsClientFactory)
private readonly savedObjectsClientFactory: ISavedObjectsClientFactory,
@inject(NotificationPolicySavedObjectsClientToken)
private readonly client: SavedObjectsClientContract,
@inject(PluginStart<AlertingServerStartDependencies['spaces']>('spaces'))
private readonly spaces: SpacesPluginStart,
@inject(EncryptedSavedObjectsClientToken)
private readonly encryptedSavedObjectsClient: EncryptedSavedObjectsClient
) {
this.client = this.savedObjectsClientFactory({
includedHiddenTypes: [NOTIFICATION_POLICY_SAVED_OBJECT_TYPE],
});
}
) {}

public async create({
attrs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@
* 2.0.
*/

import type { SavedObjectsClientContract } from '@kbn/core/server';
import type { ServiceIdentifier } from 'inversify';
import type { NotificationPolicySavedObjectServiceContract } from './notification_policy_saved_object_service';

/**
* Pre-configured SavedObjects client with hidden types for notification policies
*/
export const NotificationPolicySavedObjectsClientToken = Symbol.for(
'alerting_v2.NotificationPolicySavedObjectsClient'
) as ServiceIdentifier<SavedObjectsClientContract>;

/**
* NotificationPolicySavedObjectService scoped to the current request
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,9 @@ export function createRulesSavedObjectService(): {
mockSavedObjectsClient: jest.Mocked<SavedObjectsClientContract>;
} {
const mockSavedObjectsClient = savedObjectsClientMock.create();
const mockSavedObjectsClientFactory = jest.fn().mockReturnValue(mockSavedObjectsClient);
const mockSpaces = spacesMock.createStart();

const rulesSavedObjectService = new RulesSavedObjectService(
mockSavedObjectsClientFactory,
mockSpaces
);
const rulesSavedObjectService = new RulesSavedObjectService(mockSavedObjectsClient, mockSpaces);

return { rulesSavedObjectService, mockSavedObjectsClient };
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

import { PluginStart } from '@kbn/core-di';
import type { SpacesPluginStart } from '@kbn/spaces-plugin/server';
import type { ISavedObjectsClientFactory } from '@kbn/core-di-server';
import { SavedObjectsClientFactory } from '@kbn/core-di-server';
import { inject, injectable } from 'inversify';
import type { SavedObjectsClientContract } from '@kbn/core/server';
import { SavedObjectsUtils } from '@kbn/core/server';
Expand All @@ -17,6 +15,7 @@ import { RULE_SAVED_OBJECT_TYPE } from '../../../saved_objects';
import type { RuleSavedObjectAttributes } from '../../../saved_objects';
import type { AlertingServerStartDependencies } from '../../../types';
import { spaceIdToNamespace } from '../../space_id_to_namespace';
import { RuleSavedObjectsClientToken } from './tokens';

export type RulesSavedObjectsBulkGetResultItem =
| {
Expand Down Expand Up @@ -46,18 +45,12 @@ export interface RulesSavedObjectServiceContract {

@injectable()
export class RulesSavedObjectService implements RulesSavedObjectServiceContract {
private readonly client: SavedObjectsClientContract;

constructor(
@inject(SavedObjectsClientFactory)
private readonly savedObjectsClientFactory: ISavedObjectsClientFactory,
@inject(RuleSavedObjectsClientToken)
private readonly client: SavedObjectsClientContract,
@inject(PluginStart<AlertingServerStartDependencies['spaces']>('spaces'))
private readonly spaces: SpacesPluginStart
) {
this.client = this.savedObjectsClientFactory({
includedHiddenTypes: [RULE_SAVED_OBJECT_TYPE],
});
}
) {}
public async create({
attrs,
id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@
* 2.0.
*/

import type { SavedObjectsClientContract } from '@kbn/core/server';
import type { ServiceIdentifier } from 'inversify';
import type { RulesSavedObjectServiceContract } from './rules_saved_object_service';

/**
* Pre-configured SavedObjects client with hidden types for rules
*/
export const RuleSavedObjectsClientToken = Symbol.for(
'alerting_v2.RuleSavedObjectsClient'
) as ServiceIdentifier<SavedObjectsClientContract>;

/**
* RulesSavedObjectService scoped to the current request
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { PluginSetup, PluginStart } from '@kbn/core-di';
import { CoreStart, Request } from '@kbn/core-di-server';
import { CoreStart, Request, SavedObjectsClientFactory } from '@kbn/core-di-server';
import type { ContainerModuleLoadOptions } from 'inversify';
import { AlertActionsClient } from '../lib/alert_actions_client';
import { DirectorService } from '../lib/director/director';
Expand All @@ -23,6 +23,7 @@ import { EsServiceInternalToken, EsServiceScopedToken } from '../lib/services/es
import { LoggerService, LoggerServiceToken } from '../lib/services/logger_service/logger_service';
import { NotificationPolicySavedObjectService } from '../lib/services/notification_policy_saved_object_service/notification_policy_saved_object_service';
import {
NotificationPolicySavedObjectsClientToken,
NotificationPolicySavedObjectServiceInternalToken,
NotificationPolicySavedObjectServiceScopedToken,
} from '../lib/services/notification_policy_saved_object_service/tokens';
Expand All @@ -36,6 +37,7 @@ import { AlertingRetryService } from '../lib/services/retry_service';
import { RetryServiceToken } from '../lib/services/retry_service/tokens';
import { RulesSavedObjectService } from '../lib/services/rules_saved_object_service/rules_saved_object_service';
import {
RuleSavedObjectsClientToken,
RulesSavedObjectServiceInternalToken,
RulesSavedObjectServiceScopedToken,
} from '../lib/services/rules_saved_object_service/tokens';
Expand Down Expand Up @@ -90,14 +92,22 @@ export function bindServices({ bind }: ContainerModuleLoadOptions) {
})
);

bind(RuleSavedObjectsClientToken)
.toResolvedValue(
(savedObjectsClientFactory) =>
savedObjectsClientFactory({ includedHiddenTypes: [RULE_SAVED_OBJECT_TYPE] }),
[SavedObjectsClientFactory]
)
.inRequestScope();

bind(RulesSavedObjectService).toSelf().inRequestScope();
bind(RulesSavedObjectServiceScopedToken).toService(RulesSavedObjectService);
bind(RulesSavedObjectServiceInternalToken)
.toDynamicValue(({ get }) => {
const savedObjects = get(CoreStart('savedObjects'));
const spaces = get(PluginStart<AlertingServerStartDependencies['spaces']>('spaces'));
const internalClient = savedObjects.createInternalRepository([RULE_SAVED_OBJECT_TYPE]);
return new RulesSavedObjectService(() => internalClient, spaces);
return new RulesSavedObjectService(internalClient, spaces);
})
.inSingletonScope();

Expand All @@ -112,6 +122,16 @@ export function bindServices({ bind }: ContainerModuleLoadOptions) {
})
.inSingletonScope();

bind(NotificationPolicySavedObjectsClientToken)
.toResolvedValue(
(savedObjectsClientFactory) =>
savedObjectsClientFactory({
includedHiddenTypes: [NOTIFICATION_POLICY_SAVED_OBJECT_TYPE],
}),
[SavedObjectsClientFactory]
)
.inRequestScope();

bind(NotificationPolicySavedObjectService).toSelf().inRequestScope();
bind(NotificationPolicySavedObjectServiceScopedToken).toService(
NotificationPolicySavedObjectService
Expand All @@ -124,7 +144,7 @@ export function bindServices({ bind }: ContainerModuleLoadOptions) {
NOTIFICATION_POLICY_SAVED_OBJECT_TYPE,
]);
const esoClient = get(EncryptedSavedObjectsClientToken);
return new NotificationPolicySavedObjectService(() => internalClient, spaces, esoClient);
return new NotificationPolicySavedObjectService(internalClient, spaces, esoClient);
})
.inSingletonScope();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import type { EncryptedSavedObjectsService } from '../../server/crypto';
import * as EncryptedSavedObjectsModule from '../../server/saved_objects';

// This will only change if new ESOs are introduced. This number should never get smaller.
export const ESO_TYPES_COUNT = 20 as const;
export const ESO_TYPES_COUNT = 21 as const;

describe('checking changes on all registered encrypted SO types', () => {
let esServer: TestElasticsearchUtils;
Expand Down
Loading