aws_config/environment/
mod.rs
1use std::error::Error;
9use std::fmt;
10
11pub mod credentials;
13pub use credentials::EnvironmentVariableCredentialsProvider;
14
15pub mod region;
17pub use region::EnvironmentVariableRegionProvider;
18
19#[derive(Debug)]
20pub(crate) struct InvalidBooleanValue {
21 value: String,
22}
23
24impl fmt::Display for InvalidBooleanValue {
25 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26 write!(f, "{} is not a valid boolean", self.value)
27 }
28}
29
30impl Error for InvalidBooleanValue {}
31
32pub(crate) fn parse_bool(value: &str) -> Result<bool, InvalidBooleanValue> {
33 if value.eq_ignore_ascii_case("false") {
34 Ok(false)
35 } else if value.eq_ignore_ascii_case("true") {
36 Ok(true)
37 } else {
38 Err(InvalidBooleanValue {
39 value: value.to_string(),
40 })
41 }
42}
43
44#[derive(Debug)]
45pub(crate) struct InvalidUrlValue {
46 value: String,
47}
48
49impl fmt::Display for InvalidUrlValue {
50 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
51 write!(f, "{} is not a valid URL", self.value)
52 }
53}
54
55impl Error for InvalidUrlValue {}
56
57pub(crate) fn parse_url(value: &str) -> Result<String, InvalidUrlValue> {
58 match url::Url::parse(value) {
59 Ok(_) => Ok(value.to_string()),
61 Err(_) => Err(InvalidUrlValue {
62 value: value.to_string(),
63 }),
64 }
65}