Skip to content

Commit 6c85d17

Browse files
authored
Fixed an issue where post_config could not modify the core data structure (#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
1 parent 03f6e2a commit 6c85d17

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

src/cli/config.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ pub struct Storage {
101101
pub config: HashMap<String, Value>,
102102
}
103103

104+
static STORAGE_TYPE_KEYWORDS: &[&str] = &["file", "mysql"];
105+
104106
fn default_bool_true() -> bool {
105107
true
106108
}
@@ -182,11 +184,11 @@ where
182184
{
183185
let storage: HashMap<String, Storage> = Deserialize::deserialize(deserializer)?;
184186

185-
// for key in storage.keys() {
186-
// if key != "file" {
187-
// return Err(serde::de::Error::custom("Invalid storage key"));
188-
// }
189-
// }
187+
for key in storage.keys() {
188+
if !STORAGE_TYPE_KEYWORDS.contains(&key.as_str()) {
189+
return Err(serde::de::Error::custom("Invalid storage key"));
190+
}
191+
}
190192

191193
Ok(storage)
192194
}

src/core.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,11 @@ impl Core {
135135
let cert_module = CertModule::new(self);
136136
self.module_manager.add_module(Arc::new(RwLock::new(Box::new(cert_module))))?;
137137

138-
let handlers = self.handlers.read()?;
138+
let handlers = {
139+
self.handlers.read()?.clone()
140+
};
139141
for handler in handlers.iter() {
140-
match handler.post_config(Arc::clone(&core), config) {
142+
match handler.post_config(self, config) {
141143
Ok(_) => {
142144
continue;
143145
}

src/handler.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
//! The `Handler` trait should be implemented in other module, such as the `rusty_vault::router`
77
//! for instance.
88
9-
use std::sync::{Arc, RwLock};
10-
119
use derive_more::Display;
1210
use async_trait::async_trait;
1311

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

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

0 commit comments

Comments
 (0)