Skip to content

Commit

Permalink
rust: add BootstrapConfiguration struct
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas Buffon <[email protected]>
  • Loading branch information
nbuffon committed Nov 8, 2024
1 parent a962a88 commit 2b1bee0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions rust/src/client/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ use crate::client::configuration::{
#[cfg(feature = "geo_routing")]
use crate::client::configuration::geo_configuration::{GeoConfiguration, GEO_SECTION};

pub(crate) mod bootstrap_configuration;
pub mod configuration_error;
#[cfg(feature = "geo_routing")]
pub mod geo_configuration;
Expand Down
34 changes: 34 additions & 0 deletions rust/src/client/configuration/bootstrap_configuration.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use crate::client::configuration::configuration_error::ConfigurationError;
use crate::client::configuration::get_mandatory_field;
use ini::Properties;

pub struct BootstrapConfiguration {
pub endpoint: String,
pub station_id: String,
pub username: String,
pub password: String,
pub role: String,
}

impl TryFrom<&Properties> for BootstrapConfiguration {
type Error = ConfigurationError;

fn try_from(properties: &Properties) -> Result<Self, Self::Error> {
let section = ("bootstrap", properties);

let endpoint = format!(
"http://{}:{}{}",
get_mandatory_field::<String>("host", section)?,
get_mandatory_field::<u16>("port", section)?,
get_mandatory_field::<String>("path", section)?,
);

Ok(Self {
endpoint,
station_id: get_mandatory_field::<String>("station_id", section)?,
username: get_mandatory_field::<String>("username", section)?,
password: get_mandatory_field::<String>("password", section)?,
role: get_mandatory_field::<String>("role", section)?,
})
}
}

0 comments on commit 2b1bee0

Please sign in to comment.