From 1c8f8d997034df8b1b1ae7b0049ce91c06555e5f Mon Sep 17 00:00:00 2001 From: David Crespo Date: Wed, 16 Mar 2022 00:15:47 -0500 Subject: [PATCH 1/6] alternate impl_enum_type that owns the enum itself (compiles!) --- nexus/src/db/model.rs | 87 +++++++++++++++++++--- nexus/src/external_api/http_entrypoints.rs | 3 +- nexus/src/nexus.rs | 7 +- 3 files changed, 80 insertions(+), 17 deletions(-) diff --git a/nexus/src/db/model.rs b/nexus/src/db/model.rs index 5b5352c7f4..8818e51022 100644 --- a/nexus/src/db/model.rs +++ b/nexus/src/db/model.rs @@ -101,6 +101,67 @@ macro_rules! impl_enum_type { } } +macro_rules! impl_enum_type2 { + ( + $(#[$enum_meta:meta])* + pub struct $diesel_type:ident; + + $(#[$model_meta:meta])* + pub enum $model_type:ident; + $($enum_item:ident => $sql_value:literal)+ + ) => { + + $(#[$enum_meta])* + pub struct $diesel_type; + + $(#[$model_meta])* + pub enum $model_type { + $( + $enum_item, + )* + } + + impl ToSql<$diesel_type, DB> for $model_type + where + DB: Backend, + { + fn to_sql( + &self, + out: &mut serialize::Output, + ) -> serialize::Result { + match self { + $( + $model_type::$enum_item => { + out.write_all($sql_value)? + } + )* + } + Ok(IsNull::No) + } + } + + impl FromSql<$diesel_type, DB> for $model_type + where + DB: Backend + for<'a> BinaryRawValue<'a>, + { + fn from_sql(bytes: RawValue) -> deserialize::Result { + match DB::as_bytes(bytes) { + $( + $sql_value => { + Ok($model_type::$enum_item) + } + )* + _ => { + Err(concat!("Unrecognized enum variant for ", + stringify!{$model_type}) + .into()) + } + } + } + } + } +} + /// Newtype wrapper around [external::Name]. #[derive( Clone, @@ -1584,14 +1645,14 @@ impl From for VpcSubnetUpdate { } } -impl_enum_type!( +impl_enum_type2!( #[derive(SqlType, Debug)] #[postgres(type_name = "vpc_router_kind", type_schema = "public")] pub struct VpcRouterKindEnum; - #[derive(Clone, Debug, AsExpression, FromSqlRow)] + #[derive(Clone, Copy, Debug, AsExpression, FromSqlRow, PartialEq)] #[sql_type = "VpcRouterKindEnum"] - pub struct VpcRouterKind(pub external::VpcRouterKind); + pub enum VpcRouterKind; // Enum values System => b"system" @@ -1613,16 +1674,11 @@ impl VpcRouter { pub fn new( router_id: Uuid, vpc_id: Uuid, - kind: external::VpcRouterKind, + kind: VpcRouterKind, params: params::VpcRouterCreate, ) -> Self { let identity = VpcRouterIdentity::new(router_id, params.identity); - Self { - identity, - vpc_id, - kind: VpcRouterKind(kind), - rcgen: Generation::new(), - } + Self { identity, vpc_id, kind, rcgen: Generation::new() } } } @@ -1633,12 +1689,21 @@ impl DatastoreCollection for VpcRouter { type CollectionIdColumn = router_route::dsl::router_id; } +impl Into for VpcRouterKind { + fn into(self) -> external::VpcRouterKind { + match self { + VpcRouterKind::Custom => external::VpcRouterKind::Custom, + VpcRouterKind::System => external::VpcRouterKind::System, + } + } +} + impl Into for VpcRouter { fn into(self) -> external::VpcRouter { external::VpcRouter { identity: self.identity(), vpc_id: self.vpc_id, - kind: self.kind.0, + kind: self.kind.into(), } } } diff --git a/nexus/src/external_api/http_entrypoints.rs b/nexus/src/external_api/http_entrypoints.rs index 70448a4990..12877e29f1 100644 --- a/nexus/src/external_api/http_entrypoints.rs +++ b/nexus/src/external_api/http_entrypoints.rs @@ -60,7 +60,6 @@ use omicron_common::api::external::Saga; use omicron_common::api::external::VpcFirewallRuleUpdateParams; use omicron_common::api::external::VpcFirewallRules; use omicron_common::api::external::VpcRouter; -use omicron_common::api::external::VpcRouterKind; use ref_cast::RefCast; use schemars::JsonSchema; use serde::Deserialize; @@ -1973,7 +1972,7 @@ async fn vpc_routers_post( &path.organization_name, &path.project_name, &path.vpc_name, - &VpcRouterKind::Custom, + &db::model::VpcRouterKind::Custom, &create_params.into_inner(), ) .await?; diff --git a/nexus/src/nexus.rs b/nexus/src/nexus.rs index c9889a8589..47413313c0 100644 --- a/nexus/src/nexus.rs +++ b/nexus/src/nexus.rs @@ -50,7 +50,6 @@ use omicron_common::api::external::RouterRouteKind; use omicron_common::api::external::RouterRouteUpdateParams; use omicron_common::api::external::UpdateResult; use omicron_common::api::external::VpcFirewallRuleUpdateParams; -use omicron_common::api::external::VpcRouterKind; use omicron_common::api::internal::nexus; use omicron_common::api::internal::nexus::DiskRuntimeState; use omicron_common::api::internal::nexus::UpdateArtifact; @@ -1778,7 +1777,7 @@ impl Nexus { let router = db::model::VpcRouter::new( system_router_id, vpc_id, - VpcRouterKind::System, + db::model::VpcRouterKind::System, params::VpcRouterCreate { identity: IdentityMetadataCreateParams { name: "system".parse().unwrap(), @@ -2301,7 +2300,7 @@ impl Nexus { organization_name: &Name, project_name: &Name, vpc_name: &Name, - kind: &VpcRouterKind, + kind: &db::model::VpcRouterKind, params: ¶ms::VpcRouterCreate, ) -> CreateResult { let vpc = self @@ -2332,7 +2331,7 @@ impl Nexus { router_name, ) .await?; - if router.kind.0 == VpcRouterKind::System { + if router.kind == db::model::VpcRouterKind::System { return Err(Error::MethodNotAllowed { internal_message: "Cannot delete system router".to_string(), }); From 455f6454f9ac5d315bf6ce0f49b0a98583cb6dfc Mon Sep 17 00:00:00 2001 From: David Crespo Date: Wed, 16 Mar 2022 00:30:01 -0500 Subject: [PATCH 2/6] now move VpcRouter and VpcRouterKind into views (compiles, tests pass) --- common/src/api/external/mod.rs | 21 ---------- nexus/src/db/model.rs | 19 ---------- nexus/src/external_api/http_entrypoints.rs | 4 +- nexus/src/external_api/params.rs | 4 +- nexus/src/external_api/views.rs | 40 ++++++++++++++++++++ nexus/test-utils/src/resource_helpers.rs | 5 ++- nexus/tests/integration_tests/vpc_routers.rs | 3 +- openapi/nexus.json | 4 +- 8 files changed, 50 insertions(+), 50 deletions(-) diff --git a/common/src/api/external/mod.rs b/common/src/api/external/mod.rs index a0aec6172f..282bbd8643 100644 --- a/common/src/api/external/mod.rs +++ b/common/src/api/external/mod.rs @@ -1244,27 +1244,6 @@ impl FromStr for IpNet { } } -#[derive(Clone, Copy, Debug, Deserialize, Serialize, PartialEq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum VpcRouterKind { - System, - Custom, -} - -/// A VPC router defines a series of rules that indicate where traffic -/// should be sent depending on its destination. -#[derive(ObjectIdentity, Clone, Debug, Deserialize, Serialize, JsonSchema)] -pub struct VpcRouter { - /// common identifying metadata - #[serde(flatten)] - pub identity: IdentityMetadata, - - pub kind: VpcRouterKind, - - /// The VPC to which the router belongs. - pub vpc_id: Uuid, -} - /// A `RouteTarget` describes the possible locations that traffic matching a /// route destination can be sent. #[derive( diff --git a/nexus/src/db/model.rs b/nexus/src/db/model.rs index 8818e51022..042ac46ecb 100644 --- a/nexus/src/db/model.rs +++ b/nexus/src/db/model.rs @@ -1689,25 +1689,6 @@ impl DatastoreCollection for VpcRouter { type CollectionIdColumn = router_route::dsl::router_id; } -impl Into for VpcRouterKind { - fn into(self) -> external::VpcRouterKind { - match self { - VpcRouterKind::Custom => external::VpcRouterKind::Custom, - VpcRouterKind::System => external::VpcRouterKind::System, - } - } -} - -impl Into for VpcRouter { - fn into(self) -> external::VpcRouter { - external::VpcRouter { - identity: self.identity(), - vpc_id: self.vpc_id, - kind: self.kind.into(), - } - } -} - #[derive(AsChangeset)] #[table_name = "vpc_router"] pub struct VpcRouterUpdate { diff --git a/nexus/src/external_api/http_entrypoints.rs b/nexus/src/external_api/http_entrypoints.rs index 12877e29f1..152e3ee16f 100644 --- a/nexus/src/external_api/http_entrypoints.rs +++ b/nexus/src/external_api/http_entrypoints.rs @@ -13,7 +13,8 @@ use crate::ServerContext; use super::{ console_api, params, views::{ - Organization, Project, Rack, Role, Sled, Snapshot, User, Vpc, VpcSubnet, + Organization, Project, Rack, Role, Sled, Snapshot, User, Vpc, + VpcRouter, VpcSubnet, }, }; use crate::context::OpContext; @@ -59,7 +60,6 @@ use omicron_common::api::external::RouterRouteUpdateParams; use omicron_common::api::external::Saga; use omicron_common::api::external::VpcFirewallRuleUpdateParams; use omicron_common::api::external::VpcFirewallRules; -use omicron_common::api::external::VpcRouter; use ref_cast::RefCast; use schemars::JsonSchema; use serde::Deserialize; diff --git a/nexus/src/external_api/params.rs b/nexus/src/external_api/params.rs index 3029623a80..25a01975c2 100644 --- a/nexus/src/external_api/params.rs +++ b/nexus/src/external_api/params.rs @@ -222,14 +222,14 @@ pub struct VpcSubnetUpdate { * VPC ROUTERS */ -/// Create-time parameters for a [`VpcRouter`](omicron_common::api::external::VpcRouter) +/// Create-time parameters for a [`VpcRouter`](crate::external_api::views::VpcRouter) #[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)] pub struct VpcRouterCreate { #[serde(flatten)] pub identity: IdentityMetadataCreateParams, } -/// Updateable properties of a [`VpcRouter`](omicron_common::api::external::VpcRouter) +/// Updateable properties of a [`VpcRouter`](crate::external_api::views::VpcRouter) #[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)] pub struct VpcRouterUpdate { #[serde(flatten)] diff --git a/nexus/src/external_api/views.rs b/nexus/src/external_api/views.rs index 7d4b6b1b92..8709215527 100644 --- a/nexus/src/external_api/views.rs +++ b/nexus/src/external_api/views.rs @@ -147,6 +147,46 @@ impl Into for model::VpcSubnet { } } +#[derive(Clone, Copy, Debug, Deserialize, Serialize, PartialEq, JsonSchema)] +#[serde(rename_all = "snake_case")] +pub enum VpcRouterKind { + System, + Custom, +} + +impl Into for model::VpcRouterKind { + fn into(self) -> VpcRouterKind { + match self { + model::VpcRouterKind::Custom => VpcRouterKind::Custom, + model::VpcRouterKind::System => VpcRouterKind::System, + } + } +} + +/// A VPC router defines a series of rules that indicate where traffic +/// should be sent depending on its destination. +#[derive(ObjectIdentity, Clone, Debug, Deserialize, Serialize, JsonSchema)] +pub struct VpcRouter { + /// common identifying metadata + #[serde(flatten)] + pub identity: IdentityMetadata, + + pub kind: VpcRouterKind, + + /// The VPC to which the router belongs. + pub vpc_id: Uuid, +} + +impl Into for model::VpcRouter { + fn into(self) -> VpcRouter { + VpcRouter { + identity: self.identity(), + vpc_id: self.vpc_id, + kind: self.kind.into(), + } + } +} + /* * RACKS */ diff --git a/nexus/test-utils/src/resource_helpers.rs b/nexus/test-utils/src/resource_helpers.rs index a7c6f7e3b2..6b8b8ba86c 100644 --- a/nexus/test-utils/src/resource_helpers.rs +++ b/nexus/test-utils/src/resource_helpers.rs @@ -17,10 +17,11 @@ use omicron_common::api::external::Disk; use omicron_common::api::external::IdentityMetadataCreateParams; use omicron_common::api::external::Instance; use omicron_common::api::external::InstanceCpuCount; -use omicron_common::api::external::VpcRouter; use omicron_nexus::crucible_agent_client::types::State as RegionState; use omicron_nexus::external_api::params; -use omicron_nexus::external_api::views::{Organization, Project, Vpc}; +use omicron_nexus::external_api::views::{ + Organization, Project, Vpc, VpcRouter, +}; use omicron_sled_agent::sim::SledAgent; use std::sync::Arc; use uuid::Uuid; diff --git a/nexus/tests/integration_tests/vpc_routers.rs b/nexus/tests/integration_tests/vpc_routers.rs index 3bca9ac0a3..762cd4995d 100644 --- a/nexus/tests/integration_tests/vpc_routers.rs +++ b/nexus/tests/integration_tests/vpc_routers.rs @@ -6,9 +6,8 @@ use http::method::Method; use http::StatusCode; use omicron_common::api::external::IdentityMetadataCreateParams; use omicron_common::api::external::IdentityMetadataUpdateParams; -use omicron_common::api::external::VpcRouter; -use omicron_common::api::external::VpcRouterKind; use omicron_nexus::external_api::params; +use omicron_nexus::external_api::views::{VpcRouter, VpcRouterKind}; use dropshot::test_util::object_get; use dropshot::test_util::objects_list_page; diff --git a/openapi/nexus.json b/openapi/nexus.json index 35f9c5f5f5..45116d276f 100644 --- a/openapi/nexus.json +++ b/openapi/nexus.json @@ -6666,7 +6666,7 @@ ] }, "VpcRouterCreate": { - "description": "Create-time parameters for a [`VpcRouter`](omicron_common::api::external::VpcRouter)", + "description": "Create-time parameters for a [`VpcRouter`](crate::external_api::views::VpcRouter)", "type": "object", "properties": { "description": { @@ -6710,7 +6710,7 @@ ] }, "VpcRouterUpdate": { - "description": "Updateable properties of a [`VpcRouter`](omicron_common::api::external::VpcRouter)", + "description": "Updateable properties of a [`VpcRouter`](crate::external_api::views::VpcRouter)", "type": "object", "properties": { "description": { From 127d890947e914acd32f4065f383cb416c8e4898 Mon Sep 17 00:00:00 2001 From: David Crespo Date: Wed, 16 Mar 2022 11:21:49 -0500 Subject: [PATCH 3/6] convert DatasetKind, very simple --- nexus/src/db/datastore.rs | 28 ++++++++++++---------------- nexus/src/db/model.rs | 18 ++++++++++++++---- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/nexus/src/db/datastore.rs b/nexus/src/db/datastore.rs index dc7b684dfc..02cd327ad0 100644 --- a/nexus/src/db/datastore.rs +++ b/nexus/src/db/datastore.rs @@ -303,9 +303,7 @@ impl DataStore { // We look for valid datasets (non-deleted crucible datasets). .filter(dsl::size_used.is_not_null()) .filter(dsl::time_deleted.is_null()) - .filter(dsl::kind.eq(DatasetKind( - crate::internal_api::params::DatasetKind::Crucible, - ))) + .filter(dsl::kind.eq(DatasetKind::Crucible)) .order(dsl::size_used.asc()) // TODO: We admittedly don't actually *fail* any request for // running out of space - we try to send the request down to @@ -3270,7 +3268,9 @@ mod test { use crate::authz; use crate::db::explain::ExplainableAsync; use crate::db::identity::Resource; - use crate::db::model::{ConsoleSession, Organization, Project}; + use crate::db::model::{ + ConsoleSession, DatasetKind, Organization, Project, + }; use crate::external_api::params; use chrono::{Duration, Utc}; use nexus_test_utils::db::test_setup_database; @@ -3435,12 +3435,11 @@ mod test { let dataset_count = REGION_REDUNDANCY_THRESHOLD * 2; let bogus_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080); - let kind = - DatasetKind(crate::internal_api::params::DatasetKind::Crucible); let dataset_ids: Vec = (0..dataset_count).map(|_| Uuid::new_v4()).collect(); for id in &dataset_ids { - let dataset = Dataset::new(*id, zpool_id, bogus_addr, kind.clone()); + let dataset = + Dataset::new(*id, zpool_id, bogus_addr, DatasetKind::Crucible); datastore.dataset_upsert(dataset).await.unwrap(); } @@ -3511,12 +3510,11 @@ mod test { let dataset_count = REGION_REDUNDANCY_THRESHOLD; let bogus_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080); - let kind = - DatasetKind(crate::internal_api::params::DatasetKind::Crucible); let dataset_ids: Vec = (0..dataset_count).map(|_| Uuid::new_v4()).collect(); for id in &dataset_ids { - let dataset = Dataset::new(*id, zpool_id, bogus_addr, kind.clone()); + let dataset = + Dataset::new(*id, zpool_id, bogus_addr, DatasetKind::Crucible); datastore.dataset_upsert(dataset).await.unwrap(); } @@ -3572,12 +3570,11 @@ mod test { let dataset_count = REGION_REDUNDANCY_THRESHOLD - 1; let bogus_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080); - let kind = - DatasetKind(crate::internal_api::params::DatasetKind::Crucible); let dataset_ids: Vec = (0..dataset_count).map(|_| Uuid::new_v4()).collect(); for id in &dataset_ids { - let dataset = Dataset::new(*id, zpool_id, bogus_addr, kind.clone()); + let dataset = + Dataset::new(*id, zpool_id, bogus_addr, DatasetKind::Crucible); datastore.dataset_upsert(dataset).await.unwrap(); } @@ -3620,12 +3617,11 @@ mod test { let dataset_count = REGION_REDUNDANCY_THRESHOLD; let bogus_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080); - let kind = - DatasetKind(crate::internal_api::params::DatasetKind::Crucible); let dataset_ids: Vec = (0..dataset_count).map(|_| Uuid::new_v4()).collect(); for id in &dataset_ids { - let dataset = Dataset::new(*id, zpool_id, bogus_addr, kind.clone()); + let dataset = + Dataset::new(*id, zpool_id, bogus_addr, DatasetKind::Crucible); datastore.dataset_upsert(dataset).await.unwrap(); } diff --git a/nexus/src/db/model.rs b/nexus/src/db/model.rs index 042ac46ecb..e2797ef0b0 100644 --- a/nexus/src/db/model.rs +++ b/nexus/src/db/model.rs @@ -690,14 +690,14 @@ impl DatastoreCollection for Zpool { type CollectionIdColumn = dataset::dsl::pool_id; } -impl_enum_type!( +impl_enum_type2!( #[derive(SqlType, Debug, QueryId)] #[postgres(type_name = "dataset_kind", type_schema = "public")] pub struct DatasetKindEnum; #[derive(Clone, Debug, AsExpression, FromSqlRow, Serialize, Deserialize, PartialEq)] #[sql_type = "DatasetKindEnum"] - pub struct DatasetKind(pub internal_api::params::DatasetKind); + pub enum DatasetKind; // Enum values Crucible => b"crucible" @@ -707,7 +707,17 @@ impl_enum_type!( impl From for DatasetKind { fn from(k: internal_api::params::DatasetKind) -> Self { - Self(k) + match k { + internal_api::params::DatasetKind::Crucible => { + DatasetKind::Crucible + } + internal_api::params::DatasetKind::Cockroach => { + DatasetKind::Cockroach + } + internal_api::params::DatasetKind::Clickhouse => { + DatasetKind::Clickhouse + } + } } } @@ -750,7 +760,7 @@ impl Dataset { kind: DatasetKind, ) -> Self { let size_used = match kind { - DatasetKind(internal_api::params::DatasetKind::Crucible) => Some(0), + DatasetKind::Crucible => Some(0), _ => None, }; Self { From 636c72d7367ef739dcb4d5eff29dc66d58046ceb Mon Sep 17 00:00:00 2001 From: David Crespo Date: Wed, 16 Mar 2022 12:56:58 -0500 Subject: [PATCH 4/6] Into -> From because it's better! --- nexus/src/external_api/views.rs | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/nexus/src/external_api/views.rs b/nexus/src/external_api/views.rs index 66d9d784c3..76c18158b2 100644 --- a/nexus/src/external_api/views.rs +++ b/nexus/src/external_api/views.rs @@ -136,11 +136,11 @@ pub enum VpcRouterKind { Custom, } -impl Into for model::VpcRouterKind { - fn into(self) -> VpcRouterKind { - match self { - model::VpcRouterKind::Custom => VpcRouterKind::Custom, - model::VpcRouterKind::System => VpcRouterKind::System, +impl From for VpcRouterKind { + fn from(k: model::VpcRouterKind) -> Self { + match k { + model::VpcRouterKind::Custom => Self::Custom, + model::VpcRouterKind::System => Self::System, } } } @@ -159,13 +159,9 @@ pub struct VpcRouter { pub vpc_id: Uuid, } -impl Into for model::VpcRouter { - fn into(self) -> VpcRouter { - VpcRouter { - identity: self.identity(), - vpc_id: self.vpc_id, - kind: self.kind.into(), - } +impl From for VpcRouter { + fn from(r: model::VpcRouter) -> Self { + Self { identity: r.identity(), vpc_id: r.vpc_id, kind: r.kind.into() } } } From a51793a7debb34ece80613723b5d54ac105f37e5 Mon Sep 17 00:00:00 2001 From: David Crespo Date: Wed, 16 Mar 2022 13:24:50 -0500 Subject: [PATCH 5/6] macro rename and comments so I can merge the intermediate state --- nexus/src/db/model.rs | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/nexus/src/db/model.rs b/nexus/src/db/model.rs index 53a52889d6..ebc837db71 100644 --- a/nexus/src/db/model.rs +++ b/nexus/src/db/model.rs @@ -41,10 +41,19 @@ use uuid::Uuid; // TODO: Break up types into multiple files -/// This macro implements serialization and deserialization of an enum type -/// from our database into our model types. -/// See [`VpcRouterKindEnum`] and [`VpcRouterKind`] for a sample usage -macro_rules! impl_enum_type { +// TODO: The existence of both impl_enum_type and impl_enum_wrapper is a +// temporary state of affairs while we do the work of converting uses of +// impl_enum_wrapper to impl_enum_type. This is part of a broader initiative to +// move types out of the common crate into Nexus where possible. See +// https://github.com/oxidecomputer/omicron/issues/388 + +/// This macro implements serialization and deserialization of an enum type from +/// our database into our model types. This version wraps an enum imported from +/// the common crate in a struct so we can implement DB traits on it. We are +/// moving those enum definitions into this file and using impl_enum_type +/// instead, so eventually this macro will go away. See [`InstanceState`] for a +/// sample usage. +macro_rules! impl_enum_wrapper { ( $(#[$enum_meta:meta])* pub struct $diesel_type:ident; @@ -101,7 +110,10 @@ macro_rules! impl_enum_type { } } -macro_rules! impl_enum_type2 { +/// This macro implements serialization and deserialization of an enum type from +/// our database into our model types. See [`VpcRouterKindEnum`] and +/// [`VpcRouterKind`] for a sample usage +macro_rules! impl_enum_type { ( $(#[$enum_meta:meta])* pub struct $diesel_type:ident; @@ -688,7 +700,7 @@ impl DatastoreCollection for Zpool { type CollectionIdColumn = dataset::dsl::pool_id; } -impl_enum_type2!( +impl_enum_type!( #[derive(SqlType, Debug, QueryId)] #[postgres(type_name = "dataset_kind", type_schema = "public")] pub struct DatasetKindEnum; @@ -1138,7 +1150,7 @@ impl Into for InstanceRuntimeState { } } -impl_enum_type!( +impl_enum_wrapper!( #[derive(SqlType, Debug)] #[postgres(type_name = "instance_state", type_schema = "public")] pub struct InstanceStateEnum; @@ -1653,7 +1665,7 @@ impl From for VpcSubnetUpdate { } } -impl_enum_type2!( +impl_enum_type!( #[derive(SqlType, Debug)] #[postgres(type_name = "vpc_router_kind", type_schema = "public")] pub struct VpcRouterKindEnum; @@ -1715,7 +1727,7 @@ impl From for VpcRouterUpdate { } } -impl_enum_type!( +impl_enum_wrapper!( #[derive(SqlType, Debug)] #[postgres(type_name = "router_route_kind", type_schema = "public")] pub struct RouterRouteKindEnum; @@ -1863,7 +1875,7 @@ impl From for RouterRouteUpdate { } } -impl_enum_type!( +impl_enum_wrapper!( #[derive(SqlType, Debug)] #[postgres(type_name = "vpc_firewall_rule_status", type_schema = "public")] pub struct VpcFirewallRuleStatusEnum; @@ -1878,7 +1890,7 @@ impl_enum_type!( NewtypeFrom! { () pub struct VpcFirewallRuleStatus(external::VpcFirewallRuleStatus); } NewtypeDeref! { () pub struct VpcFirewallRuleStatus(external::VpcFirewallRuleStatus); } -impl_enum_type!( +impl_enum_wrapper!( #[derive(SqlType, Debug)] #[postgres(type_name = "vpc_firewall_rule_direction", type_schema = "public")] pub struct VpcFirewallRuleDirectionEnum; @@ -1893,7 +1905,7 @@ impl_enum_type!( NewtypeFrom! { () pub struct VpcFirewallRuleDirection(external::VpcFirewallRuleDirection); } NewtypeDeref! { () pub struct VpcFirewallRuleDirection(external::VpcFirewallRuleDirection); } -impl_enum_type!( +impl_enum_wrapper!( #[derive(SqlType, Debug)] #[postgres(type_name = "vpc_firewall_rule_action", type_schema = "public")] pub struct VpcFirewallRuleActionEnum; @@ -1908,7 +1920,7 @@ impl_enum_type!( NewtypeFrom! { () pub struct VpcFirewallRuleAction(external::VpcFirewallRuleAction); } NewtypeDeref! { () pub struct VpcFirewallRuleAction(external::VpcFirewallRuleAction); } -impl_enum_type!( +impl_enum_wrapper!( #[derive(SqlType, Debug)] #[postgres(type_name = "vpc_firewall_rule_protocol", type_schema = "public")] pub struct VpcFirewallRuleProtocolEnum; @@ -2308,7 +2320,7 @@ impl RoleAssignmentBuiltin { } } -impl_enum_type!( +impl_enum_wrapper!( #[derive(SqlType, Debug, QueryId)] #[postgres(type_name = "update_artifact_kind", type_schema = "public")] pub struct UpdateArtifactKindEnum; From 12100ed5908fc850a1fe3d59a59c97ef6c94533d Mon Sep 17 00:00:00 2001 From: David Crespo Date: Wed, 16 Mar 2022 13:39:31 -0500 Subject: [PATCH 6/6] make diff slightly nicer --- nexus/src/nexus.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/nexus/src/nexus.rs b/nexus/src/nexus.rs index 8f77f860a0..f5346cd807 100644 --- a/nexus/src/nexus.rs +++ b/nexus/src/nexus.rs @@ -13,6 +13,7 @@ use crate::db::identity::{Asset, Resource}; use crate::db::model::DatasetKind; use crate::db::model::Name; use crate::db::model::VpcRouter; +use crate::db::model::VpcRouterKind; use crate::db::model::VpcSubnet; use crate::db::subnet_allocation::NetworkInterfaceError; use crate::db::subnet_allocation::SubnetError; @@ -1712,7 +1713,7 @@ impl Nexus { let router = db::model::VpcRouter::new( system_router_id, vpc_id, - db::model::VpcRouterKind::System, + VpcRouterKind::System, params::VpcRouterCreate { identity: IdentityMetadataCreateParams { name: "system".parse().unwrap(), @@ -2237,7 +2238,7 @@ impl Nexus { organization_name: &Name, project_name: &Name, vpc_name: &Name, - kind: &db::model::VpcRouterKind, + kind: &VpcRouterKind, params: ¶ms::VpcRouterCreate, ) -> CreateResult { let authz_vpc = self @@ -2281,7 +2282,7 @@ impl Nexus { // database query? This shouldn't affect correctness, assuming that a // router kind cannot be changed, but it might be able to save us a // database round-trip. - if db_router.kind == db::model::VpcRouterKind::System { + if db_router.kind == VpcRouterKind::System { return Err(Error::MethodNotAllowed { internal_message: "Cannot delete system router".to_string(), });