Skip to content

Commit

Permalink
use param prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasneirynck committed Oct 14, 2021
1 parent 56ae701 commit 9daaa1f
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 13 deletions.
2 changes: 0 additions & 2 deletions x-pack/plugins/alerting/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ export {
AlertingAuthorizationEntity,
} from './authorization';

export { extractEntityAndBoundaryReferences } from './saved_objects/geo_containment/migrations';

export const plugin = (initContext: PluginInitializerContext) => new AlertingPlugin(initContext);

export const config: PluginConfigDescriptor<AlertsConfigType> = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ describe('geo_containment migration utilities', () => {
references: [
{
id: 'foobar',
name: 'tracked_index_foobar',
name: 'param:tracked_index_foobar',
type: 'index-pattern',
},
{
id: 'boundaryid',
name: 'boundary_index_boundaryid',
name: 'param:boundary_index_boundaryid',
type: 'index-pattern',
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,28 @@ export function extractEntityAndBoundaryReferences(params: GeoContainmentParams)
references: SavedObjectReference[];
} {
const { indexId, boundaryIndexId, ...otherParams } = params;

const indexRefNamePrefix = 'tracked_index_';
const boundaryRefNamePrefix = 'boundary_index_';

// Since these are stack-alerts, we need to prefix with the `param:`-namespace
const references = [
{
name: `tracked_index_${indexId}`,
type: 'index-pattern',
name: `param:${indexRefNamePrefix}${indexId}`,
type: `index-pattern`,
id: indexId as string,
},
{
name: `boundary_index_${boundaryIndexId}`,
name: `param:${boundaryRefNamePrefix}${boundaryIndexId}`,
type: 'index-pattern',
id: boundaryIndexId as string,
},
];
return {
params: {
...otherParams,
indexRefName: `tracked_index_${indexId}`,
boundaryIndexRefName: `boundary_index_${boundaryIndexId}`,
indexRefName: `${indexRefNamePrefix}${indexId}`,
boundaryIndexRefName: `${boundaryRefNamePrefix}${boundaryIndexId}`,
},
references,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1929,8 +1929,8 @@ describe('successful migrations', () => {
const migratedAlert = migration7160(alert, migrationContext);

expect(migratedAlert.references).toEqual([
{ id: 'foo', name: 'tracked_index_foo', type: 'index-pattern' },
{ id: 'bar', name: 'boundary_index_bar', type: 'index-pattern' },
{ id: 'foo', name: 'param:tracked_index_foo', type: 'index-pattern' },
{ id: 'bar', name: 'param:boundary_index_bar', type: 'index-pattern' },
]);

expect(migratedAlert.attributes.params).toEqual({
Expand Down Expand Up @@ -1969,8 +1969,8 @@ describe('successful migrations', () => {
id: '999',
type: 'foreign-name',
},
{ id: 'foo', name: 'tracked_index_foo', type: 'index-pattern' },
{ id: 'bar', name: 'boundary_index_bar', type: 'index-pattern' },
{ id: 'foo', name: 'param:tracked_index_foo', type: 'index-pattern' },
{ id: 'bar', name: 'param:boundary_index_bar', type: 'index-pattern' },
]);

expect(migratedAlert.attributes.params).toEqual({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,35 @@ export type GeoContainmentAlertType = AlertType<
typeof RecoveryActionGroupId
>;

export function extractEntityAndBoundaryReferences(params: GeoContainmentParams): {
params: GeoContainmentExtractedParams;
references: SavedObjectReference[];
} {
const { indexId, boundaryIndexId, ...otherParams } = params;

// Reference names omit the `param:`-prefix. This is handled by the alerting framework already
const references = [
{
name: `tracked_index_${indexId}`,
type: 'index-pattern',
id: indexId as string,
},
{
name: `boundary_index_${boundaryIndexId}`,
type: 'index-pattern',
id: boundaryIndexId as string,
},
];
return {
params: {
...otherParams,
indexRefName: `tracked_index_${indexId}`,
boundaryIndexRefName: `boundary_index_${boundaryIndexId}`,
},
references,
};
}

export function injectEntityAndBoundaryIds(
params: GeoContainmentExtractedParams,
references: SavedObjectReference[]
Expand Down

0 comments on commit 9daaa1f

Please sign in to comment.