forked from Orange-OpenSource/its-client
-
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.
rust: add BootstrapConfiguration struct
Signed-off-by: Nicolas Buffon <[email protected]>
- Loading branch information
Showing
2 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
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,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)?, | ||
}) | ||
} | ||
} |