-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4e6fedb
commit 7312d27
Showing
15 changed files
with
389 additions
and
127 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
upstreams: | ||
- name: default-upstream | ||
addresses: | ||
- host: 127.0.0.1 | ||
port: 8080 | ||
scheme: http | ||
|
||
backends: | ||
- type: inmemory | ||
name: StrettoBackend | ||
capacity: 10000000 | ||
|
||
endpoints: | ||
- name: all | ||
path: /{path}* | ||
method: GET | ||
key: | ||
- Method | ||
- !Path | ||
path: /{path}* | ||
predicates: | ||
request: [] | ||
response: | ||
- !StatusCode 200 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,40 @@ | ||
use std::collections::HashMap; | ||
use std::fmt::Debug; | ||
use crate::external_configuration; | ||
use hitbox::policy::PolicyConfig; | ||
use hitbox_stretto::StrettoBackend; | ||
use std::sync::Arc; | ||
|
||
use hitbox::predicate::Predicate; | ||
use hitbox::Extractor; | ||
use hitbox_http::CacheableHttpRequest; | ||
use http::method::Method; | ||
use hyper::Body; | ||
|
||
pub type BoxPredicate = Box<dyn Predicate<Subject = CacheableHttpRequest<Body>> + Send + Sync>; | ||
pub type BoxExtractor = Box<dyn Extractor<Subject = CacheableHttpRequest<Body>> + Send + Sync>; | ||
|
||
pub struct Config { | ||
pub endpoints: HashMap<String, Endpoint<BoxPredicate, BoxExtractor>>, | ||
pub endpoints: Vec<crate::Endpoint>, | ||
} | ||
|
||
impl Config { | ||
pub fn new() -> Self { | ||
Config { | ||
endpoints: HashMap::new(), | ||
endpoints: Vec::new(), | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct Endpoint<P, E> { | ||
pub name: String, | ||
pub path: String, | ||
pub methods: Vec<Method>, | ||
pub request_predicate: Arc<P>, | ||
pub extractors: Arc<E>, | ||
pub fn from_external( | ||
config: external_configuration::Config, | ||
backend: Arc<StrettoBackend>, | ||
) -> Self { | ||
let endpoints = config | ||
.endpoints | ||
.into_iter() | ||
.map(|source_endpoint| crate::Endpoint { | ||
name: source_endpoint.name, | ||
routing: crate::endpoint::Routing { | ||
path_pattern: source_endpoint.path, | ||
methods: vec![source_endpoint.method], | ||
}, | ||
backend: backend.clone(), | ||
upstreams: Vec::new(), | ||
request_predicates: source_endpoint.predicates.request, | ||
response_predicates: source_endpoint.predicates.response, | ||
extractors: source_endpoint.key, | ||
policy: PolicyConfig::default(), | ||
}) | ||
.collect(); | ||
Config { endpoints } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use hitbox::policy::PolicyConfig; | ||
use hitbox_stretto::StrettoBackend; | ||
use hitbox_tower::configuration::{RequestExtractor, RequestPredicate, ResponsePredicate}; | ||
use hitbox_tower::EndpointConfig; | ||
use hitbox_tower::Method; | ||
use std::sync::Arc; | ||
|
||
#[derive(Clone)] | ||
pub struct Routing { | ||
pub path_pattern: String, | ||
pub methods: Vec<Method>, | ||
} | ||
|
||
#[derive(Clone)] | ||
pub struct Upstream { | ||
pub address: String, | ||
pub port: u16, | ||
} | ||
|
||
#[derive(Clone)] | ||
pub struct Endpoint { | ||
pub name: String, | ||
pub routing: Routing, | ||
pub backend: Arc<StrettoBackend>, | ||
pub upstreams: Vec<Upstream>, | ||
pub request_predicates: Vec<RequestPredicate>, | ||
pub response_predicates: Vec<ResponsePredicate>, | ||
pub extractors: Vec<RequestExtractor>, | ||
pub policy: PolicyConfig, | ||
} | ||
|
||
impl Endpoint { | ||
pub fn new(backend: Arc<StrettoBackend>) -> Self { | ||
Self { | ||
name: String::new(), | ||
routing: Routing { | ||
path_pattern: String::new(), | ||
methods: Vec::new(), | ||
}, | ||
backend, | ||
upstreams: Vec::new(), | ||
request_predicates: Vec::new(), | ||
response_predicates: Vec::new(), | ||
extractors: Vec::new(), | ||
policy: Default::default(), | ||
} | ||
} | ||
|
||
pub fn to_endpoint_config(self) -> EndpointConfig { | ||
EndpointConfig { | ||
request_predicates: self.request_predicates, | ||
response_predicates: self.response_predicates, | ||
extractors: self.extractors, | ||
policy: self.policy, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
pub struct InMemory { | ||
pub name: String, | ||
pub capacity: u32, | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
#[serde(tag = "type")] | ||
#[serde(rename_all = "lowercase")] | ||
pub enum Backend { | ||
InMemory(InMemory), | ||
} | ||
|
||
impl Default for InMemory { | ||
fn default() -> Self { | ||
Self { | ||
name: String::from("StrettoBackend"), | ||
capacity: 10_000_000, | ||
} | ||
} | ||
} | ||
|
||
impl Default for Backend { | ||
fn default() -> Self { | ||
Self::InMemory(InMemory::default()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use hitbox_tower::{ | ||
configuration::serializers::method, | ||
configuration::{RequestExtractor, RequestPredicate, ResponsePredicate}, | ||
Method, StatusCode, | ||
}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
pub struct Predicates { | ||
pub request: Vec<RequestPredicate>, | ||
pub response: Vec<ResponsePredicate>, | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
pub struct Endpoint { | ||
pub name: String, | ||
pub path: String, | ||
#[serde(with = "method")] | ||
pub method: Method, | ||
pub key: Vec<RequestExtractor>, | ||
pub predicates: Predicates, | ||
} | ||
|
||
impl Default for Predicates { | ||
fn default() -> Self { | ||
Self { | ||
request: Vec::new(), | ||
response: vec![ResponsePredicate::StatusCode { | ||
code: StatusCode::OK, | ||
}], | ||
} | ||
} | ||
} | ||
|
||
impl Default for Endpoint { | ||
fn default() -> Self { | ||
let default_extractors = vec![ | ||
RequestExtractor::Method, | ||
RequestExtractor::Path { | ||
path: String::from("/{path}*"), | ||
}, | ||
]; | ||
Self { | ||
name: String::from("all"), | ||
path: String::from("/{path}*"), | ||
method: Method::GET, | ||
key: default_extractors, | ||
predicates: Predicates::default(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
mod backend; | ||
mod endpoint; | ||
mod group; | ||
mod policy; | ||
mod upstream; | ||
|
||
pub use backend::Backend; | ||
pub use endpoint::Endpoint; | ||
pub use policy::Policy; | ||
pub use upstream::Upstream; | ||
|
||
#[derive(Debug, serde::Serialize, serde::Deserialize)] | ||
pub struct Config { | ||
pub upstreams: Vec<Upstream>, | ||
pub backends: Vec<Backend>, | ||
pub endpoints: Vec<Endpoint>, | ||
} | ||
|
||
impl Default for Config { | ||
fn default() -> Self { | ||
Self { | ||
upstreams: vec![Upstream::default()], | ||
backends: vec![Backend::default()], | ||
endpoints: vec![Endpoint::default()], | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
pub struct Enabled { | ||
ttl: u16, | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
#[serde(untagged)] | ||
pub enum Policy { | ||
Enabled(Enabled), | ||
Disabled, | ||
} |
Oops, something went wrong.