Skip to content

Commit

Permalink
add application types and schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
jcger committed Oct 9, 2024
1 parent 8420c02 commit 7855b81
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* 2.0.
*/

export { enableRuleRequestParamsSchema } from './schemas/latest';
export type { EnableRuleRequestParams } from './types/latest';
export { muteAllRuleRequestParamsSchema } from './schemas/latest';
export type { MuteAllRuleRequestParams } from './types/latest';

export { enableRuleRequestParamsSchema as enableRuleRequestParamsSchemaV1 } from './schemas/v1';
export type { EnableRuleRequestParams as EnableRuleRequestParamsV1 } from './types/v1';
export { muteAllRuleRequestParamsSchema as muteAllRuleRequestParamsSchemaV1 } from './schemas/v1';
export type { MuteAllRuleRequestParams as MuteAllRuleRequestParamsV1 } from './types/v1';
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export type { MuteAllRuleParams } from './types';
export { muteAll } from './mute_all';
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,38 @@
* 2.0.
*/

import Boom from '@hapi/boom';
import { RawRule } from '../../../../types';
import { WriteOperations, AlertingAuthorizationEntity } from '../../../../authorization';
import { retryIfConflicts } from '../../../../lib/retry_if_conflicts';
import { partiallyUpdateRule, RULE_SAVED_OBJECT_TYPE } from '../../../../saved_objects';
import { ruleAuditEvent, RuleAuditAction } from '../../../common/audit_events';
import { RulesClientContext } from '../types';
import { updateMetaAttributes } from '../lib';
import { clearUnscheduledSnoozeAttributes } from '../common';
import { RuleAttributes } from '../../data/rule/types';
import { ruleAuditEvent, RuleAuditAction } from '../../../../rules_client/common/audit_events';
import { RulesClientContext } from '../../../../rules_client/types';
import { updateMetaAttributes } from '../../../../rules_client/lib';
import { clearUnscheduledSnoozeAttributes } from '../../../../rules_client/common';
import { RuleAttributes } from '../../../../data/rule/types';
import { MuteAllRuleParams } from './types';
import { muteAllRuleParamsSchema } from './schemas';

export async function muteAll(context: RulesClientContext, { id }: { id: string }): Promise<void> {
export async function muteAll(
context: RulesClientContext,
{ id }: MuteAllRuleParams
): Promise<void> {
return await retryIfConflicts(
context.logger,
`rulesClient.muteAll('${id}')`,
async () => await muteAllWithOCC(context, { id })
);
}

async function muteAllWithOCC(context: RulesClientContext, { id }: { id: string }) {
async function muteAllWithOCC(context: RulesClientContext, params: MuteAllRuleParams) {
try {
muteAllRuleParamsSchema.validate(params);
} catch (error) {
throw Boom.badRequest(`Error validating enable rule parameters - ${error.message}`);
}

const { id } = params;
const { attributes, version } = await context.unsecuredSavedObjectsClient.get<RawRule>(
RULE_SAVED_OBJECT_TYPE,
id
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export * from './mute_all_rule_schemas';
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { schema } from '@kbn/config-schema';

export const muteAllRuleParamsSchema = schema.object({
id: schema.string(),
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export * from './mute_all_rule_types';
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import type { TypeOf } from '@kbn/config-schema';
import { muteAllRuleParamsSchema } from '../schemas';

export type MuteAllRuleParams = TypeOf<typeof muteAllRuleParamsSchema>;
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import { enableRule } from '../application/rule/methods/enable_rule/enable_rule'
import { updateRuleApiKey } from '../application/rule/methods/update_api_key/update_rule_api_key';
import { disableRule } from '../application/rule/methods/disable/disable_rule';
import { muteInstance } from '../application/rule/methods/mute_alert/mute_instance';
import { muteAll } from './methods/mute_all';
import { muteAll } from '../application/rule/methods/mute_all';
import { unmuteAll } from './methods/unmute_all';
import { unmuteInstance } from '../application/rule/methods/unmute_alert/unmute_instance';
import { runSoon } from './methods/run_soon';
Expand Down

0 comments on commit 7855b81

Please sign in to comment.