Skip to content

Commit

Permalink
Add regex capture and rename capture_bytes to capture
Browse files Browse the repository at this point in the history
  • Loading branch information
XAMPPRocky committed Dec 29, 2021
1 parent a31ec4a commit e899e2d
Show file tree
Hide file tree
Showing 23 changed files with 508 additions and 371 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ tryhard = "0.4.0"
eyre = "0.6.5"
stable-eyre = "0.2.2"
ipnetwork = "0.18.0"
regex = "1.5.4"
serde_regex = "1.1.0"

[target.'cfg(target_os = "linux")'.dependencies]
sys-info = "0.9.0"
Expand Down
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
"proto/data-plane-api/envoy/type/tracing/v3/custom_tag.proto",
"proto/udpa/xds/core/v3/resource_name.proto",
"proto/quilkin/extensions/filters/debug/v1alpha1/debug.proto",
"proto/quilkin/extensions/filters/capture_bytes/v1alpha1/capture_bytes.proto",
"proto/quilkin/extensions/filters/capture/v1alpha1/capture.proto",
"proto/quilkin/extensions/filters/compress/v1alpha1/compress.proto",
"proto/quilkin/extensions/filters/concatenate_bytes/v1alpha1/concatenate_bytes.proto",
"proto/quilkin/extensions/filters/load_balancer/v1alpha1/load_balancer.proto",
Expand Down
2 changes: 1 addition & 1 deletion docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
- [Proxy](./proxy.md)
- [Proxy Configuration](./proxy-configuration.md)
- [Filters](./filters.md)
- [Capture Bytes](./filters/capture_bytes.md)
- [Capture Bytes](./filters/capture.md)
- [Concatenate Bytes](./filters/concatenate_bytes.md)
- [Compress](./filters/compress.md)
- [Debug](./filters/debug.md)
Expand Down
4 changes: 2 additions & 2 deletions docs/src/filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ The following metadata are currently used by Quilkin core and built-in filters.

| Name | Type | Description |
|------|------|-------------|
| `quilkin.dev/captured_bytes` | `Bytes` | The default key under which the [CaptureBytes] filter puts the byte slices it extracts from each packet. |
| `quilkin.dev/captured` | `Bytes` | The default key under which the [CaptureBytes] filter puts the byte slices it extracts from each packet. |

### Built-in filters <a name="built-in-filters"></a>
Quilkin includes several filters out of the box.
Expand Down Expand Up @@ -132,7 +132,7 @@ properties:
required: [ 'name', 'config' ]
```
[CaptureBytes]: ./filters/capture_bytes.md
[CaptureBytes]: ./filters/capture.md
[TokenRouter]: ./filters/token_router.md
[Debug]: ./filters/debug.md
[LocalRateLimit]: ./filters/local_rate_limit.md
Expand Down
19 changes: 10 additions & 9 deletions docs/src/filters/capture_bytes.md → docs/src/filters/capture.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This is often used as a way of retrieving authentication tokens from a packet, a

#### Filter name
```text
quilkin.extensions.filters.capture_bytes.v1alpha1.CaptureBytes
quilkin.extensions.filters.capture.v1alpha1.Capture
```

### Configuration Examples
Expand All @@ -19,12 +19,13 @@ quilkin.extensions.filters.capture_bytes.v1alpha1.CaptureBytes
version: v1alpha1
static:
filters:
- name: quilkin.extensions.filters.capture_bytes.v1alpha1.CaptureBytes
- name: quilkin.extensions.filters.capture.v1alpha1.Capture
config:
strategy: PREFIX
metadataKey: myapp.com/myownkey
size: 3
remove: false
strategy:
kind: PREFIX
size: 3
remove: false
endpoints:
- address: 127.0.0.1:7001
# ";
Expand All @@ -33,12 +34,12 @@ static:
# quilkin::Builder::from(std::sync::Arc::new(config)).validate().unwrap();
```

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

```yaml
properties:
strategy:
type: string
type: map
description: |
The selected strategy for capturing the series of bytes from the incoming packet.
- SUFFIX: Retrieve bytes from the end of the packet.
Expand All @@ -47,7 +48,7 @@ properties:
enum: ['PREFIX', 'SUFFIX']
metadataKey:
type: string
default: quilkin.dev/captured_bytes
default: quilkin.dev/captured
description: |
The key under which the captured bytes are stored in the Filter invocation values.
size:
Expand All @@ -65,7 +66,7 @@ properties:
### Metrics
* `quilkin_filter_CaptureBytes_packets_dropped`
* `quilkin_filter_Capture_packets_dropped`
A counter of the total number of packets that have been dropped due to their length being less than the configured
`size`.

Expand Down
14 changes: 8 additions & 6 deletions docs/src/filters/token_router.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ static:
# quilkin::Builder::from(std::sync::Arc::new(config)).validate().unwrap();
```

View the [CaptureBytes](./capture_bytes.md) filter documentation for more details.
View the [CaptureBytes](./capture.md) filter documentation for more details.

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

```yaml
properties:
metadataKey:
type: string
default: quilkin.dev/captured_bytes
default: quilkin.dev/captured
description: |
The key under which the token is stored in the Filter dynamic metadata.
```
Expand All @@ -68,7 +68,7 @@ properties:
In combination with several other filters, the `TokenRouter` can be utilised as an authentication and access control
mechanism for all incoming packets.

Capturing the authentication token from an incoming packet can be implemented via the [CaptureByte](./capture_bytes.md)
Capturing the authentication token from an incoming packet can be implemented via the [CaptureByte](./capture.md)
filter, with an example outlined below, or any other filter that populates the configured dynamic metadata key for the
authentication token to reside.

Expand All @@ -82,10 +82,12 @@ For example, a configuration would look like:
version: v1alpha1
static:
filters:
- name: quilkin.extensions.filters.capture_bytes.v1alpha1.CaptureBytes # Capture and remove the authentication token
- name: quilkin.extensions.filters.capture.v1alpha1.Capture # Capture and remove the authentication token
config:
size: 3
remove: true
strategy:
kind: SUFFIX
size: 3
remove: true
- name: quilkin.extensions.filters.token_router.v1alpha1.TokenRouter
endpoints:
- address: 127.0.0.1:26000
Expand Down
7 changes: 2 additions & 5 deletions macros/src/include.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,9 @@ impl ToTokens for IncludeProto {
fn to_tokens(&self, tokens: &mut TokenStream) {
let id = &self.id;

let doc_hidden: syn::Attribute = syn::parse_quote!(#![doc(hidden)]);
let tonic_include_proto: syn::Stmt = syn::parse_quote!(tonic::include_proto!(#id););
let items: Vec<syn::Item> = vec![
syn::Item::Verbatim(doc_hidden.to_token_stream()),
syn::Item::Verbatim(tonic_include_proto.to_token_stream()),
];
let items: Vec<syn::Item> =
vec![syn::Item::Verbatim(tonic_include_proto.to_token_stream())];

let module = id.split('.').rev().fold::<Vec<_>, _>(items, |acc, module| {
let module = syn::Ident::new(module, Span::mixed_site());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,30 @@

syntax = "proto3";

package quilkin.extensions.filters.capture_bytes.v1alpha1;
package quilkin.extensions.filters.capture.v1alpha1;

import "google/protobuf/wrappers.proto";

message CaptureBytes {
enum Strategy {
Prefix = 0;
Suffix = 1;
message Capture {
message Suffix {
uint32 size = 1;
google.protobuf.BoolValue remove = 2;
}

message StrategyValue {
Strategy value = 1;
message Prefix {
uint32 size = 1;
google.protobuf.BoolValue remove = 2;
}

StrategyValue strategy = 1;
uint32 size = 2;
google.protobuf.StringValue metadata_key = 3;
google.protobuf.BoolValue remove = 4;
message Regex {
google.protobuf.StringValue regex = 1;
}

google.protobuf.StringValue metadata_key = 1;
oneof strategy {
Prefix prefix = 2;
Suffix suffix = 3;
Regex regex = 4;
}
}

2 changes: 1 addition & 1 deletion src/filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ mod write;
pub(crate) mod chain;
pub(crate) mod manager;

pub mod capture_bytes;
pub mod capture;
pub mod compress;
pub mod concatenate_bytes;
pub mod debug;
Expand Down
Loading

0 comments on commit e899e2d

Please sign in to comment.