Skip to content

Commit

Permalink
Add matches to auto-generated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
XAMPPRocky committed Feb 7, 2022
1 parent 369e25f commit 73adf2b
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ eyre = "0.6.5"
stable-eyre = "0.2.2"
ipnetwork = "0.18.0"
futures = "0.3.17"
schemars = "0.8.8"
schemars = { version = "0.8.8", features = ["bytes"] }

[target.'cfg(target_os = "linux")'.dependencies]
sys-info = "0.9.0"
Expand Down
5 changes: 3 additions & 2 deletions docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
- [Proxy Configuration](./proxy-configuration.md)
- [Filters](./filters.md)
- [Capture Bytes](./filters/capture_bytes.md)
- [Concatenate Bytes](./filters/concatenate_bytes.md)
- [Compress](./filters/compress.md)
- [Concatenate Bytes](./filters/concatenate_bytes.md)
- [Debug](./filters/debug.md)
- [Firewall](./filters/firewall.md)
- [Load Balancer](./filters/load_balancer.md)
- [Local Rate Limit](./filters/local_rate_limit.md)
- [Matches](./filters/matches.md)
- [Token Router](./filters/token_router.md)
- [Firewall](./filters/firewall.md)
- [Writing Custom Filters](./filters/writing_custom_filters.md)
- [Integrations](./integrations.md)
- [Administration](./admin.md)
Expand Down
6 changes: 6 additions & 0 deletions docs/src/filters/matches.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,10 @@ static:
# quilkin::Builder::from(std::sync::Arc::new(config)).validate().unwrap();
```

### Configuration Options ([Rust Doc](../../api/quilkin/filters/matches/struct.Config.html))

```yaml
{{#include ../../../target/quilkin.extensions.filters.matches.v1alpha1.yaml}}
```

View the [Matches](../../api/quilkin/filters/matches/struct.Config.html) filter documentation for more details.
4 changes: 3 additions & 1 deletion src/config/config_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ use crate::filters::{ConvertProtoConfigError, Error};

/// The configuration of a [`Filter`][crate::filters::Filter] from either a
/// static or dynamic source.
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, schemars::JsonSchema)]
pub enum ConfigType {
/// Static configuration from YAML.
#[schemars(with = "serde_json::Value")]
Static(serde_yaml::Value),
/// Dynamic configuration from Protobuf.
#[schemars(skip)]
Dynamic(prost_types::Any),
}

Expand Down
12 changes: 8 additions & 4 deletions src/filters/matches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ impl FilterFactory for MatchesFactory {
NAME
}

fn config_schema(&self) -> schemars::schema::RootSchema {
schemars::schema_for!(Config)
}

fn create_filter(&self, args: CreateFilterArgs) -> Result<FilterInstance, Error> {
let (config_json, config) = self
.require_config(args.config)?
Expand All @@ -177,7 +181,7 @@ impl FilterFactory for MatchesFactory {
}

/// Configuration for the [`factory`].
#[derive(Debug, serde::Deserialize, serde::Serialize, PartialEq)]
#[derive(Debug, serde::Deserialize, serde::Serialize, PartialEq, schemars::JsonSchema)]
#[serde(deny_unknown_fields)]
pub struct Config {
/// Configuration for [`Filter::read`].
Expand Down Expand Up @@ -231,7 +235,7 @@ impl TryFrom<proto::matches::DirectionalConfig> for DirectionalConfig {
}

/// Configuration for a specific direction.
#[derive(Debug, serde::Deserialize, serde::Serialize, PartialEq)]
#[derive(Debug, serde::Deserialize, serde::Serialize, PartialEq, schemars::JsonSchema)]
pub struct DirectionalConfig {
/// The key for the metadata to compare against.
#[serde(rename = "metadataKey")]
Expand All @@ -245,7 +249,7 @@ pub struct DirectionalConfig {

/// A specific match branch. The filter is run when `value` matches the value
/// defined in `metadata_key`.
#[derive(Debug, serde::Deserialize, serde::Serialize, PartialEq)]
#[derive(Debug, serde::Deserialize, serde::Serialize, PartialEq, schemars::JsonSchema)]
pub struct Branch {
/// The value to compare against the dynamic metadata.
pub value: crate::metadata::Value,
Expand Down Expand Up @@ -273,7 +277,7 @@ impl TryFrom<proto::matches::Branch> for Branch {
}

/// The behaviour when the none of branches match.
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, schemars::JsonSchema)]
pub enum Fallthrough {
/// The packet will be passed onto the next filter.
Pass,
Expand Down
4 changes: 3 additions & 1 deletion src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ pub type DynamicMetadata = HashMap<Arc<String>, Value>;

pub const KEY: &str = "quilkin.dev";

#[derive(Clone, Debug, PartialOrd, serde::Serialize, serde::Deserialize, Eq, Ord)]
#[derive(
Clone, Debug, PartialOrd, serde::Serialize, serde::Deserialize, Eq, Ord, schemars::JsonSchema,
)]
#[serde(untagged)]
pub enum Value {
Bool(bool),
Expand Down

0 comments on commit 73adf2b

Please sign in to comment.