mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-04-04 14:29:45 +00:00
Update compatibility image (#440)
* backup create compiling * backup restore compiling * wip * wip * backups compiling * wip * wip update set result * fix config set * wip remove async * make synchronous * add build steps * remove tokio * add restore subcommand * fix set to read stdin * add package properties key * proper error handle * create config path if it doesnt exist * fix merge conflict * make config a path and koin config file when needed * update cargo lock * fix cargo lock * update properties sub command * fix dependency check and auto configure; clean up error handling * fix errors * fix properties subcommand order * fix cargo lock * update cargo.lock * update appmgr cargo lock with build-portable * fix error strings and input dependency config in dependency commands * rename temp file instead * read dependent config file * fix temp config file creation * create config file regardless if it exists * add curl * wip refactor config * wip refactor config * update rules to use embassyos config type Co-authored-by: Chris Guida <chrisguida@gmail.com>
This commit is contained in:
83
compat/src/config/mod.rs
Normal file
83
compat/src/config/mod.rs
Normal file
@@ -0,0 +1,83 @@
|
||||
use std::borrow::Cow;
|
||||
use std::path::Path;
|
||||
|
||||
use beau_collector::BeauCollector;
|
||||
use embassy::config::action::SetResult;
|
||||
use embassy::config::{Config, spec};
|
||||
use linear_map::LinearMap;
|
||||
|
||||
pub mod rules;
|
||||
|
||||
use anyhow::anyhow;
|
||||
pub use rules::{ConfigRuleEntry, ConfigRuleEntryWithSuggestions};
|
||||
|
||||
pub fn validate_configuration(
|
||||
name: &str,
|
||||
config: Config,
|
||||
rules_path: &Path,
|
||||
config_path: &Path,
|
||||
) -> Result<SetResult, anyhow::Error> {
|
||||
let rules: Vec<ConfigRuleEntry> = serde_yaml::from_reader(std::fs::File::open(rules_path)?)?;
|
||||
let mut cfgs = LinearMap::new();
|
||||
cfgs.insert(name, Cow::Borrowed(&config));
|
||||
let rule_check = rules
|
||||
.into_iter()
|
||||
.map(|r| r.check(&config, &cfgs))
|
||||
.bcollect::<Vec<_>>();
|
||||
match rule_check {
|
||||
Ok(_) => {
|
||||
// create temp config file
|
||||
serde_yaml::to_writer(std::fs::File::create(config_path.with_extension("tmp"))?, &config)?;
|
||||
std::fs::rename(config_path.with_extension("tmp"), config_path)?;
|
||||
// return set result
|
||||
Ok(SetResult {
|
||||
depends_on: indexmap::IndexMap::new(),
|
||||
// sending sigterm so service is restarted - in 0.3.x services, this is whatever signal is needed to send to the process to pick up the configuration
|
||||
signal: Some(nix::sys::signal::SIGTERM),
|
||||
})
|
||||
}
|
||||
Err(e) => Err(anyhow!("{}", e))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn validate_dependency_configuration(
|
||||
name: &str,
|
||||
config: Config,
|
||||
rules_path: &Path,
|
||||
dependent_config: Config,
|
||||
) -> Result<(), anyhow::Error> {
|
||||
let rules: Vec<ConfigRuleEntry> = serde_yaml::from_reader(std::fs::File::open(rules_path)?)?;
|
||||
let mut cfgs = LinearMap::new();
|
||||
cfgs.insert(name, Cow::Borrowed(&config));
|
||||
cfgs.insert(name, Cow::Borrowed(&dependent_config));
|
||||
let rule_check = rules
|
||||
.into_iter()
|
||||
.map(|r| r.check(&config, &cfgs))
|
||||
.bcollect::<Vec<_>>();
|
||||
match rule_check {
|
||||
Ok(_) => Ok(()),
|
||||
Err(e) => Err(anyhow!("{}", e))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn apply_dependency_configuration(
|
||||
name: &str,
|
||||
mut config: Config,
|
||||
rules_path: &Path,
|
||||
dependent_config: Config,
|
||||
) -> Result<Config, anyhow::Error> {
|
||||
let rules: Vec<ConfigRuleEntryWithSuggestions> =
|
||||
serde_yaml::from_reader(std::fs::File::open(rules_path)?)?;
|
||||
let mut cfgs = LinearMap::new();
|
||||
cfgs.insert(name, Cow::Owned(config.clone()));
|
||||
cfgs.insert(name, Cow::Owned(dependent_config.clone()));
|
||||
let rule_check = rules
|
||||
.into_iter()
|
||||
.map(|r| r.apply(name, &mut config, &mut cfgs))
|
||||
.bcollect::<Vec<_>>();
|
||||
|
||||
match rule_check {
|
||||
Ok(_) => Ok(config),
|
||||
Err(e) => Err(anyhow!("{}", e))
|
||||
}
|
||||
}
|
||||
76
compat/src/config/rule_parser.pest
Normal file
76
compat/src/config/rule_parser.pest
Normal file
@@ -0,0 +1,76 @@
|
||||
num = @{ int ~ ("." ~ ASCII_DIGIT*)? ~ (^"e" ~ int)? }
|
||||
int = @{ ("+" | "-")? ~ ASCII_DIGIT+ }
|
||||
|
||||
raw_string = @{ (!("\\" | "\"") ~ ANY)+ }
|
||||
predefined = @{ "n" | "r" | "t" | "\\" | "0" | "\"" | "'" }
|
||||
escape = @{ "\\" ~ predefined }
|
||||
str = @{ "\"" ~ (raw_string | escape)* ~ "\"" }
|
||||
|
||||
ident_char = @{ ASCII_ALPHANUMERIC | "-" }
|
||||
sub_ident = _{ sub_ident_regular | sub_ident_index | sub_ident_any | sub_ident_all | sub_ident_fn }
|
||||
sub_ident_regular = { sub_ident_regular_base | sub_ident_regular_expr }
|
||||
sub_ident_regular_base = @{ ASCII_ALPHA ~ ident_char* }
|
||||
sub_ident_regular_expr = ${ "[" ~ str_expr ~ "]" }
|
||||
sub_ident_index = { sub_ident_index_base | sub_ident_index_expr }
|
||||
sub_ident_index_base = @{ ASCII_DIGIT+ }
|
||||
sub_ident_index_expr = ${ "[" ~ num_expr ~ "]" }
|
||||
sub_ident_any = @{ "*" }
|
||||
sub_ident_all = @{ "&" }
|
||||
sub_ident_fn = ${ "[" ~ list_access_function ~ "]"}
|
||||
list_access_function = _{ list_access_function_first | list_access_function_last | list_access_function_any | list_access_function_all }
|
||||
list_access_function_first = !{ "first" ~ "(" ~ sub_ident_regular ~ "=>" ~ bool_expr ~ ")" }
|
||||
list_access_function_last = !{ "last" ~ "(" ~ sub_ident_regular ~ "=>" ~ bool_expr ~ ")" }
|
||||
list_access_function_any = !{ "any" ~ "(" ~ sub_ident_regular ~ "=>" ~ bool_expr ~ ")" }
|
||||
list_access_function_all = !{ "all" ~ "(" ~ sub_ident_regular ~ "=>" ~ bool_expr ~ ")" }
|
||||
|
||||
app_id = ${ "[" ~ sub_ident_regular ~ "]" }
|
||||
ident = _{ (app_id ~ ".")? ~ sub_ident_regular ~ ("." ~ sub_ident)* }
|
||||
bool_var = ${ ident ~ "?" }
|
||||
num_var = ${ "#" ~ ident }
|
||||
str_var = ${ "'" ~ ident }
|
||||
any_var = ${ ident }
|
||||
|
||||
bool_op = _{ and | or | xor }
|
||||
and = { "AND" }
|
||||
or = { "OR" }
|
||||
xor = { "XOR" }
|
||||
|
||||
num_cmp_op = _{ lt | lte | eq | neq | gt | gte }
|
||||
str_cmp_op = _{ lt | lte | eq | neq | gt | gte }
|
||||
lt = { "<" }
|
||||
lte = { "<=" }
|
||||
eq = { "=" }
|
||||
neq = { "!=" }
|
||||
gt = { ">" }
|
||||
gte = { ">=" }
|
||||
|
||||
num_op = _{ add | sub | mul | div | pow }
|
||||
str_op = _{ add }
|
||||
add = { "+" }
|
||||
sub = { "-" }
|
||||
mul = { "*" }
|
||||
div = { "/" }
|
||||
pow = { "^" }
|
||||
|
||||
num_expr = !{ num_term ~ (num_op ~ num_term)* }
|
||||
num_term = _{ num | num_var | "(" ~ num_expr ~ ")" }
|
||||
|
||||
str_expr = !{ str_term ~ (str_op ~ str_term)* }
|
||||
str_term = _{ str | str_var | "(" ~ str_expr ~ ")" }
|
||||
|
||||
num_cmp_expr = { num_expr ~ num_cmp_op ~ num_expr }
|
||||
str_cmp_expr = { str_expr ~ str_cmp_op ~ str_expr }
|
||||
|
||||
bool_expr = !{ bool_term ~ (bool_op ~ bool_term)* }
|
||||
inv_bool_expr = { "!(" ~ bool_expr ~ ")" }
|
||||
bool_term = _{ bool_var | "(" ~ bool_expr ~ ")" | inv_bool_expr | num_cmp_expr | str_cmp_expr }
|
||||
|
||||
val_expr = _{ any_var | str_expr | num_expr | bool_expr }
|
||||
|
||||
rule = _{ SOI ~ bool_expr ~ EOI }
|
||||
reference = _{ SOI ~ any_var ~ EOI }
|
||||
value = _{ SOI ~ val_expr ~ EOI }
|
||||
del_action = _{ SOI ~ "FROM" ~ any_var ~ "AS" ~ sub_ident_regular ~ "WHERE" ~ bool_expr ~ EOI }
|
||||
obj_key = _{ SOI ~ sub_ident_regular ~ EOI }
|
||||
|
||||
WHITESPACE = _{ " " | "\t" }
|
||||
1259
compat/src/config/rules.rs
Normal file
1259
compat/src/config/rules.rs
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user