Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
- Deserialize hostname from an owned string
- Fix hostname in end-to-end-tests
  • Loading branch information
bnaecker committed Feb 1, 2024
1 parent f8ae341 commit 889e5b0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion common/src/api/external/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ impl TryFrom<i64> for Generation {
Clone, Debug, Deserialize, Display, Eq, PartialEq, SerializeDisplay,
)]
#[display("{0}")]
#[serde(try_from = "&str", into = "String")]
#[serde(try_from = "String", into = "String")]
pub struct Hostname(String);

impl Hostname {
Expand Down Expand Up @@ -756,6 +756,14 @@ impl TryFrom<&str> for Hostname {
}
}

impl TryFrom<String> for Hostname {
type Error = <Hostname as FromStr>::Err;

fn try_from(s: String) -> Result<Self, Self::Error> {
s.as_str().parse()
}
}

// Custom implementation of JsonSchema for Hostname to ensure RFC-1035-style
// validation
impl JsonSchema for Hostname {
Expand Down
2 changes: 1 addition & 1 deletion nexus/tests/integration_tests/instances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ async fn test_instances_create_reboot_halt(
},
ncpus: instance.ncpus,
memory: instance.memory,
hostname: instance.hostname.clone(),
hostname: instance.hostname.parse().unwrap(),
user_data: vec![],
ssh_public_keys: None,
network_interfaces:
Expand Down

0 comments on commit 889e5b0

Please sign in to comment.