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 13, 2024
1 parent a962a88 commit ad22f89
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
8 changes: 8 additions & 0 deletions rust/examples/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
id="ora_opensource"
type="mec_application"

#[bootstrap]
#host="mydomain.com"
#port="8080"
#path="/bootstrap"
#role="external-app"
#username="login"
#password="password"

[mqtt]
host="test.mosquitto.org"
port=8886
Expand Down
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 ad22f89

Please sign in to comment.