1use crate::error::Error;
2
3pub const MAX_SPEC_NAME_LENGTH: usize = 128;
4pub const MAX_FACT_NAME_LENGTH: usize = 256;
5pub const MAX_RULE_NAME_LENGTH: usize = 256;
6pub const MAX_TYPE_NAME_LENGTH: usize = 256;
7
8pub fn check_max_length(name: &str, limit: usize, kind: &str) -> Result<(), Error> {
11 if name.len() > limit {
12 return Err(Error::ResourceLimitExceeded {
13 limit_name: format!("max_{kind}_name_length"),
14 limit_value: format!("{limit} characters"),
15 actual_value: format!("{} characters", name.len()),
16 suggestion: format!("Shorten the {kind} name to at most {limit} characters"),
17 spec_context: None,
18 });
19 }
20 Ok(())
21}
22
23#[derive(Debug, Clone)]
28pub struct ResourceLimits {
29 pub max_file_size_bytes: usize,
32
33 pub max_expression_depth: usize,
36
37 pub max_fact_value_bytes: usize,
41}
42
43impl Default for ResourceLimits {
44 fn default() -> Self {
45 Self {
46 max_file_size_bytes: 5 * 1024 * 1024, max_expression_depth: 100,
48 max_fact_value_bytes: 1024, }
50 }
51}