-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(config): layer uses generic Configurable
- Loading branch information
1 parent
1665df9
commit 07d8482
Showing
10 changed files
with
194 additions
and
94 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,88 @@ | ||
use crate::configuration::{ | ||
ExtractorBuilder, RequestExtractor, RequestPredicate, RequestPredicateBuilder, | ||
ResponsePredicate, ResponsePredicateBuilder, | ||
}; | ||
use crate::EndpointConfig; | ||
use hitbox::policy::PolicyConfig; | ||
|
||
#[derive(Debug)] | ||
pub struct EndpointConfigBuilder { | ||
pub request_predicates: Vec<RequestPredicate>, | ||
pub response_predicates: Vec<ResponsePredicate>, | ||
pub extractors: Vec<RequestExtractor>, | ||
pub policy: PolicyConfig, | ||
} | ||
|
||
impl EndpointConfigBuilder { | ||
pub fn new() -> Self { | ||
Self { | ||
request_predicates: Vec::new(), | ||
response_predicates: Vec::new(), | ||
extractors: Vec::new(), | ||
policy: Default::default(), | ||
} | ||
} | ||
|
||
pub fn disable(self) -> Self { | ||
Self { | ||
request_predicates: self.request_predicates, | ||
response_predicates: self.response_predicates, | ||
extractors: self.extractors, | ||
policy: PolicyConfig::Disabled, | ||
} | ||
} | ||
|
||
pub fn request(self, predicates: RequestPredicateBuilder) -> Self { | ||
Self { | ||
request_predicates: predicates.build(), | ||
response_predicates: self.response_predicates, | ||
extractors: self.extractors, | ||
policy: self.policy, | ||
} | ||
} | ||
|
||
pub fn response(self, predicates: ResponsePredicateBuilder) -> Self { | ||
Self { | ||
request_predicates: self.request_predicates, | ||
response_predicates: predicates.build(), | ||
extractors: self.extractors, | ||
policy: self.policy, | ||
} | ||
} | ||
|
||
pub fn cache_key(self, extractors: ExtractorBuilder) -> Self { | ||
Self { | ||
request_predicates: self.request_predicates, | ||
response_predicates: self.response_predicates, | ||
extractors: extractors.build(), | ||
policy: self.policy, | ||
} | ||
} | ||
|
||
pub fn build(self) -> EndpointConfig { | ||
EndpointConfig { | ||
request_predicates: self.request_predicates, | ||
response_predicates: self.response_predicates, | ||
extractors: self.extractors, | ||
policy: self.policy, | ||
} | ||
} | ||
} | ||
|
||
impl Default for EndpointConfigBuilder { | ||
fn default() -> Self { | ||
Self { | ||
request_predicates: Vec::new(), | ||
response_predicates: vec![ResponsePredicate::StatusCode { | ||
code: http::StatusCode::OK, | ||
}], | ||
extractors: vec![ | ||
RequestExtractor::Path { | ||
path: String::from("{path}*"), | ||
}, | ||
RequestExtractor::Method, | ||
], | ||
policy: Default::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
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,3 +1,4 @@ | ||
pub mod builder; | ||
mod endpoint; | ||
mod extractors; | ||
mod predicates; | ||
|
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
Oops, something went wrong.