Skip to content

Commit

Permalink
Fixed an issue where post_config could not modify the core data struc…
Browse files Browse the repository at this point in the history
…ture (#99)

* Add the validation of the storage keyword in the configuration file

* Fixed an issue where post_config could not modify the core data structure
  • Loading branch information
wa5i authored Jan 8, 2025
1 parent 03f6e2a commit 6c85d17
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
12 changes: 7 additions & 5 deletions src/cli/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ pub struct Storage {
pub config: HashMap<String, Value>,
}

static STORAGE_TYPE_KEYWORDS: &[&str] = &["file", "mysql"];

fn default_bool_true() -> bool {
true
}
Expand Down Expand Up @@ -182,11 +184,11 @@ where
{
let storage: HashMap<String, Storage> = Deserialize::deserialize(deserializer)?;

// for key in storage.keys() {
// if key != "file" {
// return Err(serde::de::Error::custom("Invalid storage key"));
// }
// }
for key in storage.keys() {
if !STORAGE_TYPE_KEYWORDS.contains(&key.as_str()) {
return Err(serde::de::Error::custom("Invalid storage key"));
}
}

Ok(storage)
}
Expand Down
6 changes: 4 additions & 2 deletions src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,11 @@ impl Core {
let cert_module = CertModule::new(self);
self.module_manager.add_module(Arc::new(RwLock::new(Box::new(cert_module))))?;

let handlers = self.handlers.read()?;
let handlers = {
self.handlers.read()?.clone()
};
for handler in handlers.iter() {
match handler.post_config(Arc::clone(&core), config) {
match handler.post_config(self, config) {
Ok(_) => {
continue;
}
Expand Down
4 changes: 1 addition & 3 deletions src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
//! The `Handler` trait should be implemented in other module, such as the `rusty_vault::router`
//! for instance.
use std::sync::{Arc, RwLock};

use derive_more::Display;
use async_trait::async_trait;

Expand All @@ -22,7 +20,7 @@ use crate::{
pub trait Handler: Send + Sync {
fn name(&self) -> String;

fn post_config(&self, _core: Arc<RwLock<Core>>, _config: Option<&Config>) -> Result<(), RvError> {
fn post_config(&self, _core: &mut Core, _config: Option<&Config>) -> Result<(), RvError> {
Err(RvError::ErrHandlerDefault)
}

Expand Down

0 comments on commit 6c85d17

Please sign in to comment.