From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id B764268184 for ; Thu, 14 Jan 2021 14:41:13 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id B1D9D1BED6 for ; Thu, 14 Jan 2021 14:40:43 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id F042A1BEA4 for ; Thu, 14 Jan 2021 14:40:38 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id B66D645FD2 for ; Thu, 14 Jan 2021 14:40:38 +0100 (CET) From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= To: pbs-devel@lists.proxmox.com Date: Thu, 14 Jan 2021 14:39:54 +0100 Message-Id: <20210114133955.166852-3-f.gruenbichler@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210114133955.166852-1-f.gruenbichler@proxmox.com> References: <20210112145206.mitvvam4amnodwpj@wobu-vie.proxmox.com> <20210114133955.166852-1-f.gruenbichler@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.028 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [schema.rs, getopts.rs, router.rs, mod.rs, completion.rs, method.rs, allof.rs] Subject: [pbs-devel] [PATCH proxmox 2/3] move ParameterSchema from router to schema X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Jan 2021 13:41:13 -0000 it's the place where it belongs, and unbreaks the --no-default-features build Signed-off-by: Fabian Grünbichler --- Notes: breaking change, requires corresponding patch in proxmox-backup proxmox-api-macro/Cargo.toml | 2 +- proxmox-api-macro/src/api/method.rs | 4 +-- proxmox-api-macro/tests/allof.rs | 4 +-- proxmox/src/api/cli/completion.rs | 1 - proxmox/src/api/cli/getopts.rs | 1 - proxmox/src/api/mod.rs | 3 +- proxmox/src/api/router.rs | 55 +---------------------------- proxmox/src/api/schema.rs | 54 +++++++++++++++++++++++++++- 8 files changed, 60 insertions(+), 64 deletions(-) diff --git a/proxmox-api-macro/Cargo.toml b/proxmox-api-macro/Cargo.toml index ab6c590..fb2e842 100644 --- a/proxmox-api-macro/Cargo.toml +++ b/proxmox-api-macro/Cargo.toml @@ -19,7 +19,7 @@ syn = { version = "1.0", features = [ "full", "visit-mut" ] } [dev-dependencies] futures = "0.3" -proxmox = { path = "../proxmox", features = [ "test-harness" ] } +proxmox = { version = "0.9.1", path = "../proxmox", features = [ "test-harness" ] } serde = "1.0" serde_derive = "1.0" serde_json = "1.0" diff --git a/proxmox-api-macro/src/api/method.rs b/proxmox-api-macro/src/api/method.rs index 23501bc..a03e654 100644 --- a/proxmox-api-macro/src/api/method.rs +++ b/proxmox-api-macro/src/api/method.rs @@ -677,7 +677,7 @@ fn serialize_input_schema( pub const #input_schema_name: ::proxmox::api::schema::ObjectSchema = #ts; }, quote_spanned! { func_sig_span => - ::proxmox::api::router::ParameterSchema::Object(&#input_schema_name) + ::proxmox::api::schema::ParameterSchema::Object(&#input_schema_name) }, )); } @@ -750,7 +750,7 @@ fn serialize_input_schema( ); }, quote_spanned! { func_sig_span => - ::proxmox::api::router::ParameterSchema::AllOf(&#input_schema_name) + ::proxmox::api::schema::ParameterSchema::AllOf(&#input_schema_name) }, )) } diff --git a/proxmox-api-macro/tests/allof.rs b/proxmox-api-macro/tests/allof.rs index 1c1b9a9..9fcf979 100644 --- a/proxmox-api-macro/tests/allof.rs +++ b/proxmox-api-macro/tests/allof.rs @@ -136,7 +136,7 @@ pub fn hello(it: IndexText, nv: NameValue) -> Result<(NameValue, IndexText), Err fn hello_schema_check() { const TEST_METHOD: ::proxmox::api::ApiMethod = ::proxmox::api::ApiMethod::new_full( &::proxmox::api::ApiHandler::Sync(&api_function_hello), - ::proxmox::api::router::ParameterSchema::AllOf(&::proxmox::api::schema::AllOfSchema::new( + ::proxmox::api::schema::ParameterSchema::AllOf(&::proxmox::api::schema::AllOfSchema::new( "Hello method.", &[&IndexText::API_SCHEMA, &NameValue::API_SCHEMA], )), @@ -176,7 +176,7 @@ fn with_extra_schema_check() { const TEST_METHOD: ::proxmox::api::ApiMethod = ::proxmox::api::ApiMethod::new_full( &::proxmox::api::ApiHandler::Sync(&api_function_with_extra), - ::proxmox::api::router::ParameterSchema::AllOf(&::proxmox::api::schema::AllOfSchema::new( + ::proxmox::api::schema::ParameterSchema::AllOf(&::proxmox::api::schema::AllOfSchema::new( "Extra method.", &[ &INNER_SCHEMA, diff --git a/proxmox/src/api/cli/completion.rs b/proxmox/src/api/cli/completion.rs index 42b3915..a660473 100644 --- a/proxmox/src/api/cli/completion.rs +++ b/proxmox/src/api/cli/completion.rs @@ -1,6 +1,5 @@ use super::*; -use crate::api::router::ParameterSchema; use crate::api::schema::*; fn record_done_argument( diff --git a/proxmox/src/api/cli/getopts.rs b/proxmox/src/api/cli/getopts.rs index adf0658..6248fe5 100644 --- a/proxmox/src/api/cli/getopts.rs +++ b/proxmox/src/api/cli/getopts.rs @@ -3,7 +3,6 @@ use std::collections::HashMap; use anyhow::*; use serde_json::Value; -use crate::api::router::ParameterSchema; use crate::api::schema::*; #[derive(Debug)] diff --git a/proxmox/src/api/mod.rs b/proxmox/src/api/mod.rs index 5319cc1..8c6f597 100644 --- a/proxmox/src/api/mod.rs +++ b/proxmox/src/api/mod.rs @@ -43,8 +43,7 @@ pub mod router; #[cfg(feature = "router")] #[doc(inline)] pub use router::{ - ApiFuture, ApiHandler, ApiMethod, ApiResponseFuture, ParameterSchema, Router, SubRoute, - SubdirMap, + ApiFuture, ApiHandler, ApiMethod, ApiResponseFuture, Router, SubRoute, SubdirMap, }; #[cfg(feature = "cli")] diff --git a/proxmox/src/api/router.rs b/proxmox/src/api/router.rs index 2f4b6c4..609a89e 100644 --- a/proxmox/src/api/router.rs +++ b/proxmox/src/api/router.rs @@ -10,7 +10,7 @@ use hyper::Body; use percent_encoding::percent_decode_str; use serde_json::Value; -use crate::api::schema::{self, AllOfSchema, ObjectSchema, Schema}; +use crate::api::schema::{self, ObjectSchema, ParameterSchema, Schema}; use crate::api::RpcEnvironment; use super::Permission; @@ -430,59 +430,6 @@ impl ReturnType { } } -/// Parameters are objects, but we have two types of object schemas, the regular one and the -/// `AllOf` schema. -#[derive(Clone, Copy, Debug)] -#[cfg_attr(feature = "test-harness", derive(Eq, PartialEq))] -pub enum ParameterSchema { - Object(&'static ObjectSchema), - AllOf(&'static AllOfSchema), -} - -impl schema::ObjectSchemaType for ParameterSchema { - type PropertyIter = Box>; - - fn description(&self) -> &'static str { - match self { - ParameterSchema::Object(o) => o.description(), - ParameterSchema::AllOf(o) => o.description(), - } - } - - fn lookup(&self, key: &str) -> Option<(bool, &Schema)> { - match self { - ParameterSchema::Object(o) => o.lookup(key), - ParameterSchema::AllOf(o) => o.lookup(key), - } - } - - fn properties(&self) -> Self::PropertyIter { - match self { - ParameterSchema::Object(o) => Box::new(o.properties()), - ParameterSchema::AllOf(o) => Box::new(o.properties()), - } - } - - fn additional_properties(&self) -> bool { - match self { - ParameterSchema::Object(o) => o.additional_properties(), - ParameterSchema::AllOf(o) => o.additional_properties(), - } - } -} - -impl From<&'static ObjectSchema> for ParameterSchema { - fn from(schema: &'static ObjectSchema) -> Self { - ParameterSchema::Object(schema) - } -} - -impl From<&'static AllOfSchema> for ParameterSchema { - fn from(schema: &'static AllOfSchema) -> Self { - ParameterSchema::AllOf(schema) - } -} - /// This struct defines a synchronous API call which returns the result as json `Value` #[cfg_attr(feature = "test-harness", derive(Eq, PartialEq))] pub struct ApiMethod { diff --git a/proxmox/src/api/schema.rs b/proxmox/src/api/schema.rs index 1378d78..c2cc61e 100644 --- a/proxmox/src/api/schema.rs +++ b/proxmox/src/api/schema.rs @@ -10,7 +10,6 @@ use anyhow::{bail, format_err, Error}; use serde_json::{json, Value}; use url::form_urlencoded; -use super::router::ParameterSchema; use crate::api::const_regex::ConstRegexPattern; /// Error type for schema validation @@ -752,6 +751,59 @@ impl PartialEq for ApiStringFormat { } } +/// Parameters are objects, but we have two types of object schemas, the regular one and the +/// `AllOf` schema. +#[derive(Clone, Copy, Debug)] +#[cfg_attr(feature = "test-harness", derive(Eq, PartialEq))] +pub enum ParameterSchema { + Object(&'static ObjectSchema), + AllOf(&'static AllOfSchema), +} + +impl ObjectSchemaType for ParameterSchema { + type PropertyIter = Box>; + + fn description(&self) -> &'static str { + match self { + ParameterSchema::Object(o) => o.description(), + ParameterSchema::AllOf(o) => o.description(), + } + } + + fn lookup(&self, key: &str) -> Option<(bool, &Schema)> { + match self { + ParameterSchema::Object(o) => o.lookup(key), + ParameterSchema::AllOf(o) => o.lookup(key), + } + } + + fn properties(&self) -> Self::PropertyIter { + match self { + ParameterSchema::Object(o) => Box::new(o.properties()), + ParameterSchema::AllOf(o) => Box::new(o.properties()), + } + } + + fn additional_properties(&self) -> bool { + match self { + ParameterSchema::Object(o) => o.additional_properties(), + ParameterSchema::AllOf(o) => o.additional_properties(), + } + } +} + +impl From<&'static ObjectSchema> for ParameterSchema { + fn from(schema: &'static ObjectSchema) -> Self { + ParameterSchema::Object(schema) + } +} + +impl From<&'static AllOfSchema> for ParameterSchema { + fn from(schema: &'static AllOfSchema) -> Self { + ParameterSchema::AllOf(schema) + } +} + /// Helper function to parse boolean values /// /// - true: `1 | on | yes | true` -- 2.20.1