Skip to content

#17876: Rust Server: Update dependency versions -- hyper 1.6, tokio 1.45, etc. #21332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public RustServerCodegen() {
*/
supportingFiles.add(new SupportingFile("openapi.mustache", "api", "openapi.yaml"));
supportingFiles.add(new SupportingFile("Cargo.mustache", "", "Cargo.toml"));
supportingFiles.add(new SupportingFile("cargo-config", ".cargo", "config"));
supportingFiles.add(new SupportingFile("cargo-config", ".cargo", "config.toml"));
supportingFiles.add(new SupportingFile("gitignore", "", ".gitignore"));
supportingFiles.add(new SupportingFile("lib.mustache", "src", "lib.rs"));
supportingFiles.add(new SupportingFile("context.mustache", "src", "context.rs"));
Expand All @@ -233,6 +233,7 @@ public RustServerCodegen() {
supportingFiles.add(new SupportingFile("server-server_auth.mustache", "src/server", "server_auth.rs"));
supportingFiles.add(new SupportingFile("client-mod.mustache", "src/client", "mod.rs"));
supportingFiles.add(new SupportingFile("example-server-main.mustache", "examples/server", "main.rs"));
supportingFiles.add(new SupportingFile("example-server-tokio-io.rs", "examples/server", "tokio_io.rs"));
supportingFiles.add(new SupportingFile("example-server-server.mustache", "examples/server", "server.rs"));
supportingFiles.add(new SupportingFile("example-server-auth.mustache", "examples/server", "server_auth.rs"));
supportingFiles.add(new SupportingFile("example-client-main.mustache", "examples/client", "main.rs"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ client = [
"serde_ignored", "regex", "percent-encoding", "lazy_static",
{{/hasCallbacks}}
{{! Anything added to the list below, should probably be added to the callbacks list below }}
"hyper", "hyper-openssl", "hyper-tls", "native-tls", "openssl", "url"
"hyper", "hyper-util/http1", "hyper-util/http2", "hyper-openssl", "hyper-tls", "native-tls", "openssl", "url"
]
server = [
{{#apiUsesMultipart}}
Expand All @@ -72,30 +72,30 @@ cli = [
{{#apiHasDeleteMethods}}
"dialoguer",
{{/apiHasDeleteMethods}}
"anyhow", "clap-verbosity-flag", "simple_logger", "structopt", "tokio"
"anyhow", "clap", "clap-verbosity-flag", "simple_logger", "tokio"
]
conversion = ["frunk", "frunk_derives", "frunk_core", "frunk-enum-core", "frunk-enum-derive"]

[target.'cfg(any(target_os = "macos", target_os = "windows", target_os = "ios"))'.dependencies]
native-tls = { version = "0.2", optional = true }
hyper-tls = { version = "0.5", optional = true }
hyper-tls = { version = "0.6", optional = true }

[target.'cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))'.dependencies]
hyper-openssl = { version = "0.9", optional = true }
openssl = {version = "0.10", optional = true }
hyper-openssl = { version = "0.10", optional = true }
openssl = { version = "0.10", optional = true }

[dependencies]
# Common
async-trait = "0.1.24"
async-trait = "0.1.88"
chrono = { version = "0.4", features = ["serde"] }
futures = "0.3"
swagger = { version = "6.1", features = ["serdejson", "server", "client", "tls", "tcp"] }
log = "0.4.0"
swagger = { version = "7.0.0-rc1", features = ["serdejson", "server", "client", "tls"] }
log = "0.4.27"
mime = "0.3"

serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
validator = { version = "0.16", features = ["derive"] }
validator = { version = "0.20", features = ["derive"] }

# Crates included if required by the API definition
{{#usesXml}}
Expand All @@ -110,53 +110,58 @@ mime_0_2 = { package = "mime", version = "0.2.6", optional = true }
multipart = { version = "0.16", default-features = false, optional = true }
{{/apiUsesMultipartFormData}}
{{#apiUsesUuid}}
uuid = {version = "1.3.1", features = ["serde", "v4"]}
uuid = { version = "1.17.0", features = ["serde", "v4"]}
{{/apiUsesUuid}}

# Common between server and client features
hyper = {version = "0.14", features = ["full"], optional = true}
bytes = "1.10.1"
http-body-util = "0.1.3"
hyper = { version = "1.6", features = ["full"], optional = true }
hyper-util = { version = "0.1.12", features = ["service"] }
{{#apiUsesMultipartRelated}}
mime_multipart = {version = "0.5", optional = true}
hyper_0_10 = {package = "hyper", version = "0.10", default-features = false, optional=true}
mime_multipart = { version = "0.5", optional = true }
hyper_0_10 = {package = "hyper", version = "0.10", default-features = false, optional=true }
{{/apiUsesMultipartRelated}}
serde_ignored = {version = "0.1.1", optional = true}
url = {version = "2.1", optional = true}
serde_ignored = { version = "0.1.12", optional = true }
url = { version = "2.5", optional = true }

# Client-specific
{{#usesUrlEncodedForm}}
serde_urlencoded = {version = "0.6.1", optional = true}
serde_urlencoded = { version = "0.6.1", optional = true }
{{/usesUrlEncodedForm}}
tower-service = "0.3.3"

# Server, and client callback-specific
lazy_static = { version = "1.4", optional = true }
percent-encoding = {version = "2.1.0", optional = true}
regex = {version = "1.3", optional = true}
lazy_static = { version = "1.5", optional = true }
percent-encoding = { version = "2.3.1", optional = true }
regex = { version = "1.11", optional = true }

# CLI-specific
anyhow = { version = "1", optional = true }
clap-verbosity-flag = { version = "0.3", optional = true }
simple_logger = { version = "2.0", features = ["stderr"], optional = true }
structopt = { version = "0.3", optional = true }
tokio = { version = "0.2", features = ["rt-threaded", "macros", "stream"], optional = true }
clap-verbosity-flag = { version = "3.0", optional = true }
simple_logger = { version = "5.0", features = ["stderr"], optional = true }
tokio = { version = "1.45", features = ["rt-multi-thread", "macros"], optional = true }
{{#apiHasDeleteMethods}}
dialoguer = { version = "0.8", optional = true }
{{/apiHasDeleteMethods}}

# Conversion
frunk = { version = "0.4.0", optional = true }
frunk_derives = { version = "0.4.0", optional = true }
frunk_core = { version = "0.4.0", optional = true }
frunk = { version = "0.4.3", optional = true }
frunk_derives = { version = "0.4.3", optional = true }
frunk_core = { version = "0.4.3", optional = true }
frunk-enum-derive = { version = "0.3.0", optional = true }
frunk-enum-core = { version = "0.3.0", optional = true }

# Bearer authentication
jsonwebtoken = { version = "9.3.0", optional = false }
jsonwebtoken = { version = "9.3.1", optional = false }

[dev-dependencies]
clap = "2.25"
always_send = "0.1.1"
clap = "4.5"
env_logger = "0.11"
tokio = { version = "1.14", features = ["full"] }
tokio = { version = "1.45", features = ["full"] }
native-tls = "0.2"
pin-project = "1.1.10"

[target.'cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))'.dev-dependencies]
tokio-openssl = "0.6"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::BTreeSet;
use crate::server::Authorization;
use serde::{Deserialize, Serialize};
use swagger::{ApiError, auth::{Basic, Bearer}};
use swagger::{ApiError, auth::AuthData};

#[derive(Debug, Serialize, Deserialize)]
pub struct Claims {
Expand All @@ -17,14 +17,14 @@ pub struct Claims {
pub trait AuthenticationApi {

/// Method should be implemented (see example-code) to map Bearer-token to an Authorization
fn bearer_authorization(&self, token: &Bearer) -> Result<Authorization, ApiError>;
fn bearer_authorization(&self, token: &str) -> Result<Authorization, ApiError>;

/// Method should be implemented (see example-code) to map ApiKey to an Authorization
fn apikey_authorization(&self, token: &str) -> Result<Authorization, ApiError>;

/// Method should be implemented (see example-code) to map Basic (Username:password) to an Authorization
fn basic_authorization(&self, basic: &Basic) -> Result<Authorization, ApiError>;
}
fn basic_authorization(&self, username: &str, password: &str) -> Result<Authorization, ApiError>;
}

// Implement it for AllowAllAuthenticator (dummy is needed, but should not used as we have Bearer authorization)
use swagger::auth::{AllowAllAuthenticator, RcBound, Scopes};
Expand All @@ -46,7 +46,7 @@ where
RC::Result: Send + 'static {

/// Get method to map Bearer-token to an Authorization
fn bearer_authorization(&self, _token: &Bearer) -> Result<Authorization, ApiError> {
fn bearer_authorization(&self, _token: &str) -> Result<Authorization, ApiError> {
Ok(dummy_authorization())
}

Expand All @@ -56,7 +56,7 @@ where
}

/// Get method to map basic token to an Authorization
fn basic_authorization(&self, _basic: &Basic) -> Result<Authorization, ApiError> {
fn basic_authorization(&self, _username: &str, _password: &str) -> Result<Authorization, ApiError> {
Ok(dummy_authorization())
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! CLI tool driving the API client
use anyhow::{anyhow, Context, Result};
use clap::Parser;
{{#apiHasDeleteMethods}}
use dialoguer::Confirm;
{{/apiHasDeleteMethods}}
Expand All @@ -19,7 +20,6 @@ use {{{externCrateName}}}::{
{{/apiInfo}}
};
use simple_logger::SimpleLogger;
use structopt::StructOpt;
use swagger::{AuthData, ContextBuilder, EmptyContext, Push, XSpanIdString};

type ClientContext = swagger::make_context_ty!(
Expand All @@ -30,65 +30,65 @@ type ClientContext = swagger::make_context_ty!(
);

{{! See code in RustServerCodegen if you are adding additional short option usage here. }}
#[derive(StructOpt, Debug)]
#[structopt(
#[derive(Parser, Debug)]
#[clap(
name = "{{appName}}",
version = "{{version}}",
about = "CLI access to {{appName}}"
)]
struct Cli {
#[structopt(subcommand)]
#[clap(subcommand)]
operation: Operation,

/// Address or hostname of the server hosting this API, including optional port
#[structopt(short = "a", long, default_value = "http://localhost")]
#[clap(short = 'a', long, default_value = "http://localhost")]
server_address: String,

/// Path to the client private key if using client-side TLS authentication
#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))]
#[structopt(long, requires_all(&["client-certificate", "server-certificate"]))]
#[clap(long, requires_all(&["client-certificate", "server-certificate"]))]
client_key: Option<String>,

/// Path to the client's public certificate associated with the private key
#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))]
#[structopt(long, requires_all(&["client-key", "server-certificate"]))]
#[clap(long, requires_all(&["client-key", "server-certificate"]))]
client_certificate: Option<String>,

/// Path to CA certificate used to authenticate the server
#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))]
#[structopt(long)]
#[clap(long)]
server_certificate: Option<String>,

/// If set, write output to file instead of stdout
#[structopt(short, long)]
#[clap(short, long)]
output_file: Option<String>,

#[structopt(flatten)]
#[command(flatten)]
verbosity: clap_verbosity_flag::Verbosity,
{{#apiHasDeleteMethods}}

/// Don't ask for any confirmation prompts
#[allow(dead_code)]
#[structopt(short, long)]
#[clap(short, long)]
force: bool,
{{/apiHasDeleteMethods}}
{{#hasHttpBearerMethods}}

/// Bearer token if used for authentication
#[structopt(env = "{{#lambda.uppercase}}{{externCrateName}}{{/lambda.uppercase}}_BEARER_TOKEN", hide_env_values = true)]
#[clap(env = "{{#lambda.uppercase}}{{externCrateName}}{{/lambda.uppercase}}_BEARER_TOKEN", hide_env_values = true)]
bearer_token: Option<String>,
{{/hasHttpBearerMethods}}
{{^hasHttpBearerMethods}}
{{#hasOAuthMethods}}

/// Bearer token if used for authentication
#[structopt(env = "{{#lambda.uppercase}}{{externCrateName}}{{/lambda.uppercase}}_BEARER_TOKEN", hide_env_values = true)]
#[clap(env = "{{#lambda.uppercase}}{{externCrateName}}{{/lambda.uppercase}}_BEARER_TOKEN", hide_env_values = true)]
bearer_token: Option<String>,
{{/hasOAuthMethods}}
{{/hasHttpBearerMethods}}
}

#[derive(StructOpt, Debug)]
#[derive(Parser, Debug)]
enum Operation {
{{#apiInfo}}
{{#apis}}
Expand All @@ -103,21 +103,21 @@ enum Operation {
/// {{{description}}}
{{/description}}
{{^isPrimitiveType}}
#[structopt(parse(try_from_str = parse_json){{#isArray}}, long{{/isArray}})]
#[clap(value_parser = parse_json::<{{{dataType}}}>){{#isArray}}, long{{/isArray}}]
{{/isPrimitiveType}}
{{#isByteArray}}
#[structopt(parse(try_from_str = parse_json))]
#[clap(value_parser = parse_json::<{{{dataType}}}>)]
{{/isByteArray}}
{{#isBinary}}
#[structopt(parse(try_from_str = parse_json))]
#[clap(value_parser = parse_json::<{{{dataType}}}>)]
{{/isBinary}}
{{#isBoolean}}
{{#isPrimitiveType}}
{{#vendorExtensions.x-provide-cli-short-opt}}
#[structopt(short, long)]
#[clap(short, long)]
{{/vendorExtensions.x-provide-cli-short-opt}}
{{^vendorExtensions.x-provide-cli-short-opt}}
#[structopt(long)]
#[clap(long)]
{{/vendorExtensions.x-provide-cli-short-opt}}
{{/isPrimitiveType}}
{{/isBoolean}}
Expand Down Expand Up @@ -165,7 +165,7 @@ fn create_client(args: &Cli, context: ClientContext) -> Result<Box<dyn ApiNoCont

#[tokio::main]
async fn main() -> Result<()> {
let args = Cli::from_args();
let args = Cli::parse();
if let Some(log_level) = args.verbosity.log_level() {
SimpleLogger::new().with_level(log_level.to_level_filter()).init()?;
}
Expand Down Expand Up @@ -312,6 +312,6 @@ fn prompt(force: bool, text: &str) -> Result<()> {

// May be unused if all inputs are primitive types
#[allow(dead_code)]
fn parse_json<'a, T: serde::de::Deserialize<'a>>(json_string: &'a str) -> Result<T> {
fn parse_json<T: serde::de::DeserializeOwned>(json_string: &str) -> Result<T> {
serde_json::from_str(json_string).map_err(|err| anyhow!("Error parsing input: {}", err))
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ rustflags = [

"-W", "trivial_numeric_casts", # detects trivial casts of numeric types which could be removed

"-W", "unsafe_code", # usage of `unsafe` code
# unsafe is used in `TokioIo` bridging code copied from `hyper`.
# "-W", "unsafe_code", # usage of `unsafe` code

"-W", "unused_qualifications", # detects unnecessarily qualified names

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use async_trait::async_trait;
use bytes::Bytes;
use futures::{Stream, future, future::BoxFuture, stream, future::TryFutureExt, future::FutureExt, stream::StreamExt};
use http_body_util::{combinators::BoxBody, Full};
use hyper::header::{HeaderName, HeaderValue, CONTENT_TYPE};
use hyper::{Body, Request, Response, service::Service, Uri};
use hyper::{body::{Body, Incoming}, Request, Response, service::Service, Uri};
use percent_encoding::{utf8_percent_encode, AsciiSet};
use std::borrow::Cow;
use std::convert::TryInto;
Expand All @@ -18,6 +20,7 @@ use std::string::ToString;
use std::task::{Context, Poll};
use swagger::{ApiError, AuthData, BodyExt, Connector, DropContextService, Has, XSpanIdString};
use url::form_urlencoded;
use tower_service::Service as _;

{{#apiUsesMultipartFormData}}
use mime::Mime;
Expand Down
Loading
Loading