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 0b9f311
Show file tree
Hide file tree
Showing 19 changed files with 495 additions and 360 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
19 changes: 10 additions & 9 deletions docs/src/filters/capture_bytes.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
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 0b9f311

Please sign in to comment.