Merge remote-tracking branch 'origin/master' into 4.0.x

This commit is contained in:
William Cheng
2018-07-28 01:12:00 +08:00
76 changed files with 313 additions and 194 deletions

View File

@@ -27,6 +27,6 @@ fi
# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
ags="generate -t modules/openapi-generator/src/main/resources/cpp-qt5-server -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g cpp-qt5-server -o samples/server/petstore/cpp-qt5-server $@"
ags="generate -t modules/openapi-generator/src/main/resources/cpp-qt5-qhttpengine-server -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g cpp-qt5-qhttpengine-server -o samples/server/petstore/cpp-qt5-qhttpengine-server $@"
java $JAVA_OPTS -jar $executable $ags

View File

@@ -0,0 +1,32 @@
#!/bin/sh
SCRIPT="$0"
echo "# START SCRIPT: $SCRIPT"
while [ -h "$SCRIPT" ] ; do
ls=`ls -ld "$SCRIPT"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
SCRIPT="$link"
else
SCRIPT=`dirname "$SCRIPT"`/"$link"
fi
done
if [ ! -d "${APP_DIR}" ]; then
APP_DIR=`dirname "$SCRIPT"`/..
APP_DIR=`cd "${APP_DIR}"; pwd`
fi
executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar"
if [ ! -f "$executable" ]
then
mvn clean package
fi
# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
ags="generate -t modules/openapi-generator/src/main/resources/cpp-qt5-qhttpengine-server -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g cpp-qt5-qhttpengine-server -o samples/client/petstore/cpp-qt5-qhttpengine-server $@"
java $JAVA_OPTS -jar $executable $ags

View File

@@ -40,16 +40,13 @@ declare -a files=("CI/pom.xml.bash"
"CI/pom.xml.circleci.java7"
"CI/pom.xml.ios"
"modules/openapi-generator-cli/pom.xml"
"modules/openapi-generator-gradle-plugin/README.adoc"
"modules/openapi-generator-gradle-plugin/gradle.properties"
"modules/openapi-generator-gradle-plugin/pom.xml"
"modules/openapi-generator-gradle-plugin/samples/local-spec/build.gradle"
"modules/openapi-generator-maven-plugin/pom.xml"
"modules/openapi-generator-online/pom.xml"
"modules/openapi-generator/pom.xml"
"modules/openapi-generator-online/Dockerfile"
"pom.xml"
"README.md")
"pom.xml")
for filename in "${files[@]}"; do
# e.g. sed -i '' "s/3.0.1-SNAPSHOT/3.0.1/g" CI/pom.xml.bash

View File

@@ -0,0 +1,54 @@
#!/bin/bash
#
# usage: ./bin/utils/release_version_update.sh 3.0.1-SNAPSHOT 3.0.1
#
# Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
if [[ "$1" != "" ]]; then
FROM="$1"
else
echo "Missing argument. Usage e.g.: ./bin/utils/release_version_update.sh 3.0.1-SNAPSHOT 3.0.1"
exit 1;
fi
if [[ "$2" != "" ]]; then
TO="$2"
else
echo "Missing argument. Usage e.g.: ./bin/utils/release_version_update.sh 3.0.1-SNAPSHOT 3.0.1"
exit 1;
fi
echo "IMPORTANT: this script works on Mac only"
echo "Release preparation: replacing $FROM with $TO in different files"
declare -a files=("modules/openapi-generator-maven-plugin/README.md"
"modules/openapi-generator-gradle-plugin/README.adoc"
"modules/openapi-generator-gradle-plugin/samples/local-spec/gradle.properties"
"modules/openapi-generator-gradle-plugin/samples/local-spec/build.gradle"
"modules/openapi-generator-gradle-plugin/samples/local-spec/README.md"
"README.md")
for filename in "${files[@]}"; do
# e.g. sed -i '' "s/3.0.1-SNAPSHOT/3.0.1/g" CI/pom.xml.bash
#echo "Running command: sed -i '' "s/$FROM/$TO/g" $filename"
if sed -i '' "s/$FROM/$TO/g" $filename; then
echo "Updated $filename successfully!"
else
echo "ERROR: Failed to update $filename with the following command"
echo "sed -i '' \"s/$FROM/$TO/g\" $filename"
fi
done

View File

@@ -0,0 +1,10 @@
set executable=.\modules\openapi-generator-cli\target\openapi-generator-cli.jar
If Not Exist %executable% (
mvn clean package
)
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g cpp-qt5-qhttpengine-server -o samples\server\petstore\cpp-qt5-qhttpengine-server
java %JAVA_OPTS% -jar %executable% %ags%

View File

@@ -33,8 +33,8 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
public class CppQt5ServerCodegen extends AbstractCppCodegen implements CodegenConfig {
private static final Logger LOGGER = LoggerFactory.getLogger(CppQt5ServerCodegen.class);
public class CppQt5QHttpEngineServerCodegen extends AbstractCppCodegen implements CodegenConfig {
private static final Logger LOGGER = LoggerFactory.getLogger(CppQt5QHttpEngineServerCodegen.class);
public static final String CPP_NAMESPACE = "cppNamespace";
public static final String CPP_NAMESPACE_DESC = "C++ namespace (convention: name::space::for::api).";
@@ -52,13 +52,13 @@ public class CppQt5ServerCodegen extends AbstractCppCodegen implements CodegenCo
protected Set<String> systemIncludes = new HashSet<String>();
protected String cppNamespace = "OpenAPI";
public CppQt5ServerCodegen() {
public CppQt5QHttpEngineServerCodegen() {
super();
// set the output folder here
outputFolder = "generated-code/cpp-qt5-server";
outputFolder = "generated-code/cpp-qt5-qhttpengine-server";
// set modelNamePrefix as default for QT5CPP
// set modelNamePrefix as default for QHttpEngine Server
if (StringUtils.isEmpty(modelNamePrefix)) {
modelNamePrefix = PREFIX;
}
@@ -102,7 +102,7 @@ public class CppQt5ServerCodegen extends AbstractCppCodegen implements CodegenCo
* Template Location. This is the location which templates will be read from. The generator
* will use the resource stream to attempt to read the templates.
*/
embeddedTemplateDir = templateDir = "cpp-qt5-server";
embeddedTemplateDir = templateDir = "cpp-qt5-qhttpengine-server";
// CLI options
addOption(CPP_NAMESPACE, CPP_NAMESPACE_DESC, this.cppNamespace);
@@ -230,7 +230,7 @@ public class CppQt5ServerCodegen extends AbstractCppCodegen implements CodegenCo
*/
@Override
public String getName() {
return "cpp-qt5-server";
return "cpp-qt5-qhttpengine-server";
}
/**
@@ -241,7 +241,7 @@ public class CppQt5ServerCodegen extends AbstractCppCodegen implements CodegenCo
*/
@Override
public String getHelp() {
return "Generates a Qt5 C++ Server using the QHTTPEngine HTTP Library.";
return "Generates a Qt5 C++ Server (beta) using the QHTTPEngine HTTP Library.";
}
@Override

View File

@@ -198,7 +198,7 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig {
supportingFiles.add(new SupportingFile("lib.mustache", "src", "lib.rs"));
supportingFiles.add(new SupportingFile("models.mustache", "src", "models.rs"));
supportingFiles.add(new SupportingFile("server-mod.mustache", "src/server", "mod.rs"));
supportingFiles.add(new SupportingFile("server-auth.mustache", "src/server", "auth.rs"));
supportingFiles.add(new SupportingFile("server-context.mustache", "src/server", "context.rs"));
supportingFiles.add(new SupportingFile("client-mod.mustache", "src/client", "mod.rs"));
supportingFiles.add(new SupportingFile("mimetypes.mustache", "src", "mimetypes.rs"));
supportingFiles.add(new SupportingFile("example-server.mustache", "examples", "server.rs"));

View File

@@ -36,6 +36,7 @@
<webAppSourceDirectory>target/${project.artifactId}-${project.version}</webAppSourceDirectory>
<stopPort>8079</stopPort>
<stopKey>stopit</stopKey>
<stopWait>10</stopWait>
<httpConnector>
<port>{{serverPort}}</port>
<idleTimeout>60000</idleTimeout>

View File

@@ -8,7 +8,7 @@ org.openapitools.codegen.languages.BashClientCodegen
org.openapitools.codegen.languages.ClojureClientCodegen
org.openapitools.codegen.languages.ConfluenceWikiCodegen
org.openapitools.codegen.languages.CppQt5ClientCodegen
org.openapitools.codegen.languages.CppQt5ServerCodegen
org.openapitools.codegen.languages.CppQt5QHttpEngineServerCodegen
org.openapitools.codegen.languages.CppPistacheServerCodegen
org.openapitools.codegen.languages.CppRestbedServerCodegen
org.openapitools.codegen.languages.CppRestSdkClientCodegen

View File

@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
project(cpp-qt5-server)
project(cpp-qt5-qhttpengine-server)
include(ExternalProject)

View File

@@ -19,7 +19,7 @@ chrono = { version = "0.4", features = ["serde"] }
futures = "0.1"
hyper = {version = "0.11", optional = true}
hyper-tls = {version = "0.1.2", optional = true}
swagger = "0.12.1"
swagger = "1.0.1"
# Not required by example server.
#

View File

@@ -55,7 +55,7 @@ fn main() {
.get_matches();
let service_fn =
{{{externCrateName}}}::server::auth::NewService::<_, EmptyContext>::new(
{{{externCrateName}}}::server::context::NewAddContext::<_, EmptyContext>::new(
AllowAllAuthenticator::new(
server_lib::NewService::new(),
"cosmo"

View File

@@ -8,76 +8,72 @@ use swagger::auth::{Authorization, AuthData, Scopes};
use swagger::{Has, Pop, Push, XSpanIdString};
use Api;
pub struct NewService<T, C>
where
C: Default + Push<XSpanIdString>,
C::Result: Push<Option<AuthData>>,
T: hyper::server::NewService<Request = (Request, <C::Result as Push<Option<AuthData>>>::Result), Response = Response, Error = Error>,
pub struct NewAddContext<T, A>
{
inner: T,
marker: PhantomData<C>,
marker: PhantomData<A>,
}
impl<T, C> NewService<T, C>
impl<T, A, B, C, D> NewAddContext<T, A>
where
C: Default + Push<XSpanIdString>,
C::Result: Push<Option<AuthData>>,
T: hyper::server::NewService<Request = (Request, <C::Result as Push<Option<AuthData>>>::Result), Response = Response, Error = Error> + 'static,
A: Default + Push<XSpanIdString, Result=B>,
B: Push<Option<AuthData>, Result=C>,
C: Push<Option<Authorization>, Result=D>,
T: hyper::server::NewService<Request = (Request, D), Response = Response, Error = Error> + 'static,
{
pub fn new(inner: T) -> NewService<T, C> {
NewService {
pub fn new(inner: T) -> NewAddContext<T, A> {
NewAddContext {
inner,
marker: PhantomData,
}
}
}
impl<T, C> hyper::server::NewService for NewService<T, C>
impl<T, A, B, C, D> hyper::server::NewService for NewAddContext<T, A>
where
C: Default + Push<XSpanIdString>,
C::Result: Push<Option<AuthData>>,
T: hyper::server::NewService<Request = (Request, <C::Result as Push<Option<AuthData>>>::Result), Response = Response, Error = Error> + 'static,
A: Default + Push<XSpanIdString, Result=B>,
B: Push<Option<AuthData>, Result=C>,
C: Push<Option<Authorization>, Result=D>,
T: hyper::server::NewService<Request = (Request, D), Response = Response, Error = Error> + 'static,
{
type Request = Request;
type Response = Response;
type Error = Error;
type Instance = Service<T::Instance, C>;
type Instance = AddContext<T::Instance, A>;
fn new_service(&self) -> Result<Self::Instance, io::Error> {
self.inner.new_service().map(|s| Service::new(s))
self.inner.new_service().map(|s| AddContext::new(s))
}
}
/// Middleware to extract authentication data from request
pub struct Service<T, C>
where
C: Default + Push<XSpanIdString>,
C::Result: Push<Option<AuthData>>,
T: hyper::server::Service<Request = (Request, <C::Result as Push<Option<AuthData>>>::Result), Response = Response, Error = Error>,
pub struct AddContext<T, A>
{
inner: T,
marker: PhantomData<C>,
marker: PhantomData<A>,
}
impl<T, C> Service<T, C>
impl<T, A, B, C, D> AddContext<T, A>
where
C: Default + Push<XSpanIdString>,
C::Result: Push<Option<AuthData>>,
T: hyper::server::Service<Request = (Request, <C::Result as Push<Option<AuthData>>>::Result), Response = Response, Error = Error>,
A: Default + Push<XSpanIdString, Result=B>,
B: Push<Option<AuthData>, Result=C>,
C: Push<Option<Authorization>, Result=D>,
T: hyper::server::Service<Request = (Request, D), Response = Response, Error = Error>,
{
pub fn new(inner: T) -> Service<T, C> {
Service {
pub fn new(inner: T) -> AddContext<T, A> {
AddContext {
inner,
marker: PhantomData,
}
}
}
impl<T, C> hyper::server::Service for Service<T, C>
impl<T, A, B, C, D> hyper::server::Service for AddContext<T, A>
where
C: Default + Push<XSpanIdString>,
C::Result: Push<Option<AuthData>>,
T: hyper::server::Service<Request = (Request, <C::Result as Push<Option<AuthData>>>::Result), Response = Response, Error = Error>,
A: Default + Push<XSpanIdString, Result=B>,
B: Push<Option<AuthData>, Result=C>,
C: Push<Option<Authorization>, Result=D>,
T: hyper::server::Service<Request = (Request, D), Response = Response, Error = Error>,
{
type Request = Request;
type Response = Response;
@@ -85,27 +81,29 @@ impl<T, C> hyper::server::Service for Service<T, C>
type Future = T::Future;
fn call(&self, req: Self::Request) -> Self::Future {
let context = C::default().push(XSpanIdString::get_or_generate(&req));
let context = A::default().push(XSpanIdString::get_or_generate(&req));
{{#authMethods}}
{{#isBasic}}
{
use hyper::header::{Authorization, Basic, Bearer};
use hyper::header::{Authorization as HyperAuth, Basic, Bearer};
use std::ops::Deref;
if let Some(basic) = req.headers().get::<Authorization<Basic>>().cloned() {
if let Some(basic) = req.headers().get::<HyperAuth<Basic>>().cloned() {
let auth_data = AuthData::Basic(basic.deref().clone());
let context = context.push(Some(auth_data));
let context = context.push(None::<Authorization>);
return self.inner.call((req, context));
}
}
{{/isBasic}}
{{#isOAuth}}
{
use hyper::header::{Authorization, Basic, Bearer};
use hyper::header::{Authorization as HyperAuth, Basic, Bearer};
use std::ops::Deref;
if let Some(bearer) = req.headers().get::<Authorization<Bearer>>().cloned() {
if let Some(bearer) = req.headers().get::<HyperAuth<Bearer>>().cloned() {
let auth_data = AuthData::Bearer(bearer.deref().clone());
let context = context.push(Some(auth_data));
let context = context.push(None::<Authorization>);
return self.inner.call((req, context));
}
}
@@ -117,6 +115,7 @@ impl<T, C> hyper::server::Service for Service<T, C>
if let Some(header) = req.headers().get::<ApiKey{{-index}}>().cloned() {
let auth_data = AuthData::ApiKey(header.0);
let context = context.push(Some(auth_data));
let context = context.push(None::<Authorization>);
return self.inner.call((req, context));
}
}
@@ -130,6 +129,7 @@ impl<T, C> hyper::server::Service for Service<T, C>
if let Some(key) = key {
let auth_data = AuthData::ApiKey(key);
let context = context.push(Some(auth_data));
let context = context.push(None::<Authorization>);
return self.inner.call((req, context));
}
}
@@ -137,7 +137,8 @@ impl<T, C> hyper::server::Service for Service<T, C>
{{/isApiKey}}
{{/authMethods}}
let context = context.push(None);
let context = context.push(None::<AuthData>);
let context = context.push(None::<Authorization>);
return self.inner.call((req, context));
}
}

View File

@@ -42,7 +42,7 @@ use {Api{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}},
#[allow(unused_imports)]
use models;
pub mod auth;
pub mod context;
header! { (Warning, "Warning") => [String] }
@@ -370,3 +370,13 @@ where
}
}
}
impl<T, C> Clone for Service<T, C>
{
fn clone(&self) -> Self {
Service {
api_impl: self.api_impl.clone(),
marker: self.marker.clone(),
}
}
}

View File

@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
project(cpp-qt5-server)
project(cpp-qt5-qhttpengine-server)
include(ExternalProject)

View File

@@ -17,7 +17,7 @@ chrono = { version = "0.4", features = ["serde"] }
futures = "0.1"
hyper = {version = "0.11", optional = true}
hyper-tls = {version = "0.1.2", optional = true}
swagger = "0.12.1"
swagger = "1.0.1"
# Not required by example server.
#

View File

@@ -55,7 +55,7 @@ fn main() {
.get_matches();
let service_fn =
petstore_api::server::auth::NewService::<_, EmptyContext>::new(
petstore_api::server::context::NewAddContext::<_, EmptyContext>::new(
AllowAllAuthenticator::new(
server_lib::NewService::new(),
"cosmo"

View File

@@ -1,131 +0,0 @@
use std::io;
use std::marker::PhantomData;
use std::default::Default;
use hyper;
use hyper::{Request, Response, Error, StatusCode};
use server::url::form_urlencoded;
use swagger::auth::{Authorization, AuthData, Scopes};
use swagger::{Has, Pop, Push, XSpanIdString};
use Api;
pub struct NewService<T, C>
where
C: Default + Push<XSpanIdString>,
C::Result: Push<Option<AuthData>>,
T: hyper::server::NewService<Request = (Request, <C::Result as Push<Option<AuthData>>>::Result), Response = Response, Error = Error>,
{
inner: T,
marker: PhantomData<C>,
}
impl<T, C> NewService<T, C>
where
C: Default + Push<XSpanIdString>,
C::Result: Push<Option<AuthData>>,
T: hyper::server::NewService<Request = (Request, <C::Result as Push<Option<AuthData>>>::Result), Response = Response, Error = Error> + 'static,
{
pub fn new(inner: T) -> NewService<T, C> {
NewService {
inner,
marker: PhantomData,
}
}
}
impl<T, C> hyper::server::NewService for NewService<T, C>
where
C: Default + Push<XSpanIdString>,
C::Result: Push<Option<AuthData>>,
T: hyper::server::NewService<Request = (Request, <C::Result as Push<Option<AuthData>>>::Result), Response = Response, Error = Error> + 'static,
{
type Request = Request;
type Response = Response;
type Error = Error;
type Instance = Service<T::Instance, C>;
fn new_service(&self) -> Result<Self::Instance, io::Error> {
self.inner.new_service().map(|s| Service::new(s))
}
}
/// Middleware to extract authentication data from request
pub struct Service<T, C>
where
C: Default + Push<XSpanIdString>,
C::Result: Push<Option<AuthData>>,
T: hyper::server::Service<Request = (Request, <C::Result as Push<Option<AuthData>>>::Result), Response = Response, Error = Error>,
{
inner: T,
marker: PhantomData<C>,
}
impl<T, C> Service<T, C>
where
C: Default + Push<XSpanIdString>,
C::Result: Push<Option<AuthData>>,
T: hyper::server::Service<Request = (Request, <C::Result as Push<Option<AuthData>>>::Result), Response = Response, Error = Error>,
{
pub fn new(inner: T) -> Service<T, C> {
Service {
inner,
marker: PhantomData,
}
}
}
impl<T, C> hyper::server::Service for Service<T, C>
where
C: Default + Push<XSpanIdString>,
C::Result: Push<Option<AuthData>>,
T: hyper::server::Service<Request = (Request, <C::Result as Push<Option<AuthData>>>::Result), Response = Response, Error = Error>,
{
type Request = Request;
type Response = Response;
type Error = Error;
type Future = T::Future;
fn call(&self, req: Self::Request) -> Self::Future {
let context = C::default().push(XSpanIdString::get_or_generate(&req));
{
header! { (ApiKey1, "api_key") => [String] }
if let Some(header) = req.headers().get::<ApiKey1>().cloned() {
let auth_data = AuthData::ApiKey(header.0);
let context = context.push(Some(auth_data));
return self.inner.call((req, context));
}
}
{
let key = form_urlencoded::parse(req.query().unwrap_or_default().as_bytes())
.filter(|e| e.0 == "api_key_query")
.map(|e| e.1.clone().into_owned())
.nth(0);
if let Some(key) = key {
let auth_data = AuthData::ApiKey(key);
let context = context.push(Some(auth_data));
return self.inner.call((req, context));
}
}
{
use hyper::header::{Authorization, Basic, Bearer};
use std::ops::Deref;
if let Some(basic) = req.headers().get::<Authorization<Basic>>().cloned() {
let auth_data = AuthData::Basic(basic.deref().clone());
let context = context.push(Some(auth_data));
return self.inner.call((req, context));
}
}
{
use hyper::header::{Authorization, Basic, Bearer};
use std::ops::Deref;
if let Some(bearer) = req.headers().get::<Authorization<Bearer>>().cloned() {
let auth_data = AuthData::Bearer(bearer.deref().clone());
let context = context.push(Some(auth_data));
return self.inner.call((req, context));
}
}
let context = context.push(None);
return self.inner.call((req, context));
}
}

View File

@@ -0,0 +1,132 @@
use std::io;
use std::marker::PhantomData;
use std::default::Default;
use hyper;
use hyper::{Request, Response, Error, StatusCode};
use server::url::form_urlencoded;
use swagger::auth::{Authorization, AuthData, Scopes};
use swagger::{Has, Pop, Push, XSpanIdString};
use Api;
pub struct NewAddContext<T, A>
{
inner: T,
marker: PhantomData<A>,
}
impl<T, A, B, C, D> NewAddContext<T, A>
where
A: Default + Push<XSpanIdString, Result=B>,
B: Push<Option<AuthData>, Result=C>,
C: Push<Option<Authorization>, Result=D>,
T: hyper::server::NewService<Request = (Request, D), Response = Response, Error = Error> + 'static,
{
pub fn new(inner: T) -> NewAddContext<T, A> {
NewAddContext {
inner,
marker: PhantomData,
}
}
}
impl<T, A, B, C, D> hyper::server::NewService for NewAddContext<T, A>
where
A: Default + Push<XSpanIdString, Result=B>,
B: Push<Option<AuthData>, Result=C>,
C: Push<Option<Authorization>, Result=D>,
T: hyper::server::NewService<Request = (Request, D), Response = Response, Error = Error> + 'static,
{
type Request = Request;
type Response = Response;
type Error = Error;
type Instance = AddContext<T::Instance, A>;
fn new_service(&self) -> Result<Self::Instance, io::Error> {
self.inner.new_service().map(|s| AddContext::new(s))
}
}
/// Middleware to extract authentication data from request
pub struct AddContext<T, A>
{
inner: T,
marker: PhantomData<A>,
}
impl<T, A, B, C, D> AddContext<T, A>
where
A: Default + Push<XSpanIdString, Result=B>,
B: Push<Option<AuthData>, Result=C>,
C: Push<Option<Authorization>, Result=D>,
T: hyper::server::Service<Request = (Request, D), Response = Response, Error = Error>,
{
pub fn new(inner: T) -> AddContext<T, A> {
AddContext {
inner,
marker: PhantomData,
}
}
}
impl<T, A, B, C, D> hyper::server::Service for AddContext<T, A>
where
A: Default + Push<XSpanIdString, Result=B>,
B: Push<Option<AuthData>, Result=C>,
C: Push<Option<Authorization>, Result=D>,
T: hyper::server::Service<Request = (Request, D), Response = Response, Error = Error>,
{
type Request = Request;
type Response = Response;
type Error = Error;
type Future = T::Future;
fn call(&self, req: Self::Request) -> Self::Future {
let context = A::default().push(XSpanIdString::get_or_generate(&req));
{
header! { (ApiKey1, "api_key") => [String] }
if let Some(header) = req.headers().get::<ApiKey1>().cloned() {
let auth_data = AuthData::ApiKey(header.0);
let context = context.push(Some(auth_data));
let context = context.push(None::<Authorization>);
return self.inner.call((req, context));
}
}
{
let key = form_urlencoded::parse(req.query().unwrap_or_default().as_bytes())
.filter(|e| e.0 == "api_key_query")
.map(|e| e.1.clone().into_owned())
.nth(0);
if let Some(key) = key {
let auth_data = AuthData::ApiKey(key);
let context = context.push(Some(auth_data));
let context = context.push(None::<Authorization>);
return self.inner.call((req, context));
}
}
{
use hyper::header::{Authorization as HyperAuth, Basic, Bearer};
use std::ops::Deref;
if let Some(basic) = req.headers().get::<HyperAuth<Basic>>().cloned() {
let auth_data = AuthData::Basic(basic.deref().clone());
let context = context.push(Some(auth_data));
let context = context.push(None::<Authorization>);
return self.inner.call((req, context));
}
}
{
use hyper::header::{Authorization as HyperAuth, Basic, Bearer};
use std::ops::Deref;
if let Some(bearer) = req.headers().get::<HyperAuth<Bearer>>().cloned() {
let auth_data = AuthData::Bearer(bearer.deref().clone());
let context = context.push(Some(auth_data));
let context = context.push(None::<Authorization>);
return self.inner.call((req, context));
}
}
let context = context.push(None::<AuthData>);
let context = context.push(None::<Authorization>);
return self.inner.call((req, context));
}
}

View File

@@ -73,7 +73,7 @@ use {Api,
#[allow(unused_imports)]
use models;
pub mod auth;
pub mod context;
header! { (Warning, "Warning") => [String] }
@@ -2939,3 +2939,13 @@ where
}
}
}
impl<T, C> Clone for Service<T, C>
{
fn clone(&self) -> Self {
Service {
api_impl: self.api_impl.clone(),
marker: self.marker.clone(),
}
}
}

View File

@@ -36,6 +36,7 @@
<webAppSourceDirectory>target/${project.artifactId}-${project.version}</webAppSourceDirectory>
<stopPort>8079</stopPort>
<stopKey>stopit</stopKey>
<stopWait>10</stopWait>
<httpConnector>
<port>8002</port>
<idleTimeout>60000</idleTimeout>

View File

@@ -36,6 +36,7 @@
<webAppSourceDirectory>target/${project.artifactId}-${project.version}</webAppSourceDirectory>
<stopPort>8079</stopPort>
<stopKey>stopit</stopKey>
<stopWait>10</stopWait>
<httpConnector>
<port>8002</port>
<idleTimeout>60000</idleTimeout>

View File

@@ -36,6 +36,7 @@
<webAppSourceDirectory>target/${project.artifactId}-${project.version}</webAppSourceDirectory>
<stopPort>8079</stopPort>
<stopKey>stopit</stopKey>
<stopWait>10</stopWait>
<httpConnector>
<port>8002</port>
<idleTimeout>60000</idleTimeout>