Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed an issue where post_config could not modify the core data structure #99

Merged
merged 2 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading