From 889e5b025fba521b96ac1d061e13d75977a9cf6e Mon Sep 17 00:00:00 2001 From: Benjamin Naecker Date: Thu, 1 Feb 2024 18:04:56 +0000 Subject: [PATCH] Minor fixes - Deserialize hostname from an owned string - Fix hostname in end-to-end-tests --- common/src/api/external/mod.rs | 10 +++++++++- nexus/tests/integration_tests/instances.rs | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/common/src/api/external/mod.rs b/common/src/api/external/mod.rs index d233806d06..cdc929d89b 100644 --- a/common/src/api/external/mod.rs +++ b/common/src/api/external/mod.rs @@ -701,7 +701,7 @@ impl TryFrom 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 { @@ -756,6 +756,14 @@ impl TryFrom<&str> for Hostname { } } +impl TryFrom for Hostname { + type Error = ::Err; + + fn try_from(s: String) -> Result { + s.as_str().parse() + } +} + // Custom implementation of JsonSchema for Hostname to ensure RFC-1035-style // validation impl JsonSchema for Hostname { diff --git a/nexus/tests/integration_tests/instances.rs b/nexus/tests/integration_tests/instances.rs index 376c2ce128..09f91a2288 100644 --- a/nexus/tests/integration_tests/instances.rs +++ b/nexus/tests/integration_tests/instances.rs @@ -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: