Skip to content

Commit

Permalink
[ILM] Relax POST policy route validation (elastic#84203)
Browse files Browse the repository at this point in the history
* relax policy post route validation

* update comment
  • Loading branch information
jloleysens committed Nov 25, 2020
1 parent 096238c commit dcbe69e
Showing 1 changed file with 11 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,114 +23,20 @@ async function createPolicy(client: ElasticsearchClient, name: string, phases: a
return client.ilm.putLifecycle({ policy: name, body }, options);
}

const minAgeSchema = schema.maybe(schema.string());

const setPrioritySchema = schema.maybe(
schema.object({
priority: schema.nullable(schema.number()),
})
);

const unfollowSchema = schema.maybe(schema.object({})); // Unfollow has no options

const migrateSchema = schema.maybe(schema.object({ enabled: schema.literal(false) }));

const allocateNodeSchema = schema.maybe(schema.recordOf(schema.string(), schema.string()));
const allocateSchema = schema.maybe(
schema.object({
number_of_replicas: schema.maybe(schema.number()),
include: allocateNodeSchema,
exclude: allocateNodeSchema,
require: allocateNodeSchema,
})
);

const forcemergeSchema = schema.maybe(
schema.object({
max_num_segments: schema.number(),
index_codec: schema.maybe(schema.literal('best_compression')),
})
);

const hotPhaseSchema = schema.object({
min_age: minAgeSchema,
actions: schema.object({
set_priority: setPrioritySchema,
unfollow: unfollowSchema,
rollover: schema.maybe(
schema.object({
max_age: schema.maybe(schema.string()),
max_size: schema.maybe(schema.string()),
max_docs: schema.maybe(schema.number()),
})
),
forcemerge: forcemergeSchema,
}),
});

const warmPhaseSchema = schema.maybe(
schema.object({
min_age: minAgeSchema,
actions: schema.object({
migrate: migrateSchema,
set_priority: setPrioritySchema,
unfollow: unfollowSchema,
readonly: schema.maybe(schema.object({})), // Readonly has no options
allocate: allocateSchema,
shrink: schema.maybe(
schema.object({
number_of_shards: schema.number(),
})
),
forcemerge: forcemergeSchema,
}),
})
);

const coldPhaseSchema = schema.maybe(
schema.object({
min_age: minAgeSchema,
actions: schema.object({
migrate: migrateSchema,
set_priority: setPrioritySchema,
unfollow: unfollowSchema,
allocate: allocateSchema,
freeze: schema.maybe(schema.object({})), // Freeze has no options
searchable_snapshot: schema.maybe(
schema.object({
snapshot_repository: schema.string(),
})
),
}),
})
);

const deletePhaseSchema = schema.maybe(
schema.object({
min_age: minAgeSchema,
actions: schema.object({
wait_for_snapshot: schema.maybe(
schema.object({
policy: schema.string(),
})
),
delete: schema.maybe(
schema.object({
delete_searchable_snapshot: schema.maybe(schema.boolean()),
})
),
}),
})
);

// Per https://www.elastic.co/guide/en/elasticsearch/reference/current/_actions.html
/**
* We intentionally do not deeply validate the posted policy object to avoid erroring on valid ES
* policy configuration Kibana UI does not know or should not know about. For instance, the
* `force_merge_index` setting of the `searchable_snapshot` action.
*
* We only specify a rough structure based on https://www.elastic.co/guide/en/elasticsearch/reference/current/_actions.html.
*/
const bodySchema = schema.object({
name: schema.string(),
phases: schema.object({
hot: hotPhaseSchema,
warm: warmPhaseSchema,
cold: coldPhaseSchema,
delete: deletePhaseSchema,
hot: schema.any(),
warm: schema.maybe(schema.any()),
cold: schema.maybe(schema.any()),
delete: schema.maybe(schema.any()),
}),
});

Expand Down

0 comments on commit dcbe69e

Please sign in to comment.