Skip to content

Commit

Permalink
relax policy post route validation
Browse files Browse the repository at this point in the history
  • Loading branch information
jloleysens committed Nov 24, 2020
1 parent 423888c commit 969f79d
Showing 1 changed file with 4 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,114 +23,14 @@ 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
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 969f79d

Please sign in to comment.