forked from hyperledger-iroha/iroha
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fix] hyperledger-iroha#4063: update configuration endpoints
Signed-off-by: Dmitry Balashov <[email protected]>
- Loading branch information
Showing
6 changed files
with
107 additions
and
102 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
//! Functionality related to working with the configuration through client API. | ||
//! | ||
//! Intended usage: | ||
//! | ||
//! - Create [`Root`] from [`crate::iroha::Configuration`] and serialize it for the client | ||
//! - Deserialize [`Root`] from the client and use [`Root::apply_update()`] to update the configuration | ||
// TODO: Currently logic here is not generalised and handles only `logger.max_log_level` parameter. In future, when | ||
// other parts of configuration are refactored and there is a solid foundation e.g. as a general | ||
// configuration-related crate, this part should be re-written in a clean way. | ||
// Track configuration refactoring here: https://github.com/hyperledger/iroha/issues/2585 | ||
|
||
use iroha_config_base::runtime_upgrades::{Reload, ReloadError}; | ||
use iroha_data_model::Level; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use super::{iroha::Configuration as BaseConfiguration, logger::Configuration as BaseLogger}; | ||
|
||
/// Subset of [`super::iroha`] configuration. | ||
#[derive(Debug, Serialize, Deserialize, Clone, Copy)] | ||
pub struct ConfigurationSubset { | ||
logger: Logger, | ||
} | ||
|
||
impl From<&'_ BaseConfiguration> for ConfigurationSubset { | ||
fn from(value: &'_ BaseConfiguration) -> Self { | ||
Self { | ||
logger: value.logger.as_ref().into(), | ||
} | ||
} | ||
} | ||
|
||
impl ConfigurationSubset { | ||
/// Update the base configuration with the values stored in [`Self`]. | ||
pub fn update_base(&self, target: &BaseConfiguration) -> Result<(), ReloadError> { | ||
target | ||
.logger | ||
.max_log_level | ||
.reload(self.logger.max_log_level) | ||
} | ||
} | ||
|
||
/// Subset of [`super::logger`] configuration. | ||
#[derive(Debug, Serialize, Deserialize, Clone, Copy)] | ||
struct Logger { | ||
#[allow(missing_docs)] | ||
max_log_level: Level, | ||
} | ||
|
||
impl From<&'_ BaseLogger> for Logger { | ||
fn from(value: &'_ BaseLogger) -> Self { | ||
Self { | ||
max_log_level: value.max_log_level.value(), | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use super::*; | ||
|
||
#[test] | ||
fn snapshot_serialized_form() { | ||
let value = ConfigurationSubset { | ||
logger: Logger { | ||
max_log_level: Level::TRACE, | ||
}, | ||
}; | ||
|
||
let actual = serde_json::to_string_pretty(&value).expect("The value is a valid JSON"); | ||
|
||
// NOTE: whenever this is updated, make sure to update the documentation accordingly: | ||
// https://hyperledger.github.io/iroha-2-docs/reference/torii-endpoints.html | ||
// -> Configuration endpoints | ||
let expected = expect_test::expect![[r#" | ||
{ | ||
"logger": { | ||
"max_log_level": "TRACE" | ||
} | ||
}"#]]; | ||
expected.assert_eq(&actual); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters