Skip to content

Commit

Permalink
Wireframe
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Snaps <[email protected]>
  • Loading branch information
alexsnaps committed Nov 28, 2024
1 parent 8e4faa9 commit 589232d
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/filter.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub(crate) mod http_context;
pub(crate) mod proposal_context;
mod root_context;

#[cfg_attr(
Expand Down
109 changes: 109 additions & 0 deletions src/filter/proposal_context.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
use crate::action_set_index::ActionSetIndex;
use crate::filter::proposal_context::no_implicit_dep::{EndRequestOperation, HeadersOperation};
use log::warn;
use proxy_wasm::traits::{Context, HttpContext};
use proxy_wasm::types::{Action, Status};
use std::mem;

pub mod no_implicit_dep {
use proxy_wasm::traits::HttpContext;

#[allow(dead_code)]
pub enum Operation {
AwaitGrpcResponse(GrpcMessageReceiverOperation),
AddHeaders(HeadersOperation),
Die(EndRequestOperation),
}
pub struct GrpcMessageReceiverOperation {}

impl GrpcMessageReceiverOperation {
pub fn process<T: HttpContext>(self, _msg: &[u8], _ctx: &mut T) -> Operation {

Check warning on line 20 in src/filter/proposal_context.rs

View workflow job for this annotation

GitHub Actions / Check

methods `process` and `fail` are never used

Check warning on line 20 in src/filter/proposal_context.rs

View workflow job for this annotation

GitHub Actions / Rustfmt

methods `process` and `fail` are never used

Check warning on line 20 in src/filter/proposal_context.rs

View workflow job for this annotation

GitHub Actions / Basic integration test

methods `process` and `fail` are never used

Check warning on line 20 in src/filter/proposal_context.rs

View workflow job for this annotation

GitHub Actions / Parallel requests integration test

methods `process` and `fail` are never used

Check warning on line 20 in src/filter/proposal_context.rs

View workflow job for this annotation

GitHub Actions / Remote address integration test

methods `process` and `fail` are never used

Check failure on line 20 in src/filter/proposal_context.rs

View workflow job for this annotation

GitHub Actions / Clippy

methods `process` and `fail` are never used

Check warning on line 20 in src/filter/proposal_context.rs

View workflow job for this annotation

GitHub Actions / Missing cluster integration test

methods `process` and `fail` are never used

Check warning on line 20 in src/filter/proposal_context.rs

View workflow job for this annotation

GitHub Actions / Unreachable service integration test

methods `process` and `fail` are never used

Check warning on line 20 in src/filter/proposal_context.rs

View workflow job for this annotation

GitHub Actions / Test Suite

methods `process` and `fail` are never used

Check warning on line 20 in src/filter/proposal_context.rs

View workflow job for this annotation

GitHub Actions / Test Suite

methods `process` and `fail` are never used
todo!()
}

pub fn fail<T: HttpContext>(self, _ctx: &mut T) -> Operation {
Operation::Die(EndRequestOperation { status: 500 })
}
}

pub struct HeadersOperation {}

pub struct EndRequestOperation {
pub status: u32,

Check warning on line 32 in src/filter/proposal_context.rs

View workflow job for this annotation

GitHub Actions / Check

field `status` is never read

Check warning on line 32 in src/filter/proposal_context.rs

View workflow job for this annotation

GitHub Actions / Rustfmt

field `status` is never read

Check warning on line 32 in src/filter/proposal_context.rs

View workflow job for this annotation

GitHub Actions / Basic integration test

field `status` is never read

Check warning on line 32 in src/filter/proposal_context.rs

View workflow job for this annotation

GitHub Actions / Parallel requests integration test

field `status` is never read

Check warning on line 32 in src/filter/proposal_context.rs

View workflow job for this annotation

GitHub Actions / Remote address integration test

field `status` is never read

Check failure on line 32 in src/filter/proposal_context.rs

View workflow job for this annotation

GitHub Actions / Clippy

field `status` is never read

Check warning on line 32 in src/filter/proposal_context.rs

View workflow job for this annotation

GitHub Actions / Missing cluster integration test

field `status` is never read

Check warning on line 32 in src/filter/proposal_context.rs

View workflow job for this annotation

GitHub Actions / Unreachable service integration test

field `status` is never read

Check warning on line 32 in src/filter/proposal_context.rs

View workflow job for this annotation

GitHub Actions / Test Suite

field `status` is never read

Check warning on line 32 in src/filter/proposal_context.rs

View workflow job for this annotation

GitHub Actions / Test Suite

field `status` is never read
}
}

struct Filter {

Check warning on line 36 in src/filter/proposal_context.rs

View workflow job for this annotation

GitHub Actions / Check

struct `Filter` is never constructed

Check warning on line 36 in src/filter/proposal_context.rs

View workflow job for this annotation

GitHub Actions / Rustfmt

struct `Filter` is never constructed

Check warning on line 36 in src/filter/proposal_context.rs

View workflow job for this annotation

GitHub Actions / Basic integration test

struct `Filter` is never constructed

Check warning on line 36 in src/filter/proposal_context.rs

View workflow job for this annotation

GitHub Actions / Parallel requests integration test

struct `Filter` is never constructed

Check warning on line 36 in src/filter/proposal_context.rs

View workflow job for this annotation

GitHub Actions / Remote address integration test

struct `Filter` is never constructed

Check failure on line 36 in src/filter/proposal_context.rs

View workflow job for this annotation

GitHub Actions / Clippy

struct `Filter` is never constructed

Check warning on line 36 in src/filter/proposal_context.rs

View workflow job for this annotation

GitHub Actions / Missing cluster integration test

struct `Filter` is never constructed

Check warning on line 36 in src/filter/proposal_context.rs

View workflow job for this annotation

GitHub Actions / Unreachable service integration test

struct `Filter` is never constructed

Check warning on line 36 in src/filter/proposal_context.rs

View workflow job for this annotation

GitHub Actions / Test Suite

struct `Filter` is never constructed

Check warning on line 36 in src/filter/proposal_context.rs

View workflow job for this annotation

GitHub Actions / Test Suite

struct `Filter` is never constructed
index: ActionSetIndex,

grpc_message_receiver_operation: Option<no_implicit_dep::GrpcMessageReceiverOperation>,
headers_operations: Vec<HeadersOperation>,
}

impl Context for Filter {
fn on_grpc_call_response(&mut self, _token_id: u32, status_code: u32, _resp_size: usize) {
let receiver = mem::take(&mut self.grpc_message_receiver_operation)
.expect("We need an operation pending a gRPC response");
let next = if status_code != Status::Ok as u32 {
receiver.process(&[], self)
} else {
receiver.fail(self)
};
self.handle_operation(next);
}
}

impl HttpContext for Filter {
fn on_http_request_headers(&mut self, _: usize, _: bool) -> Action {
if let Some(action_sets) = self
.index
.get_longest_match_action_sets(self.request_authority().as_ref())
{
if let Some(action_set) = action_sets
.iter()
.find(|action_set| action_set.conditions_apply(/* self */))
{
self.handle_operation(action_set.start_flow(self))
}
}
Action::Continue
}

fn on_http_response_headers(&mut self, _num_headers: usize, _end_of_stream: bool) -> Action {
for _op in self.headers_operations.drain(..) {
todo!("Add the headers")
}
Action::Continue
}
}

impl Filter {
fn handle_operation(&mut self, operation: no_implicit_dep::Operation) {

Check warning on line 81 in src/filter/proposal_context.rs

View workflow job for this annotation

GitHub Actions / Check

methods `handle_operation`, `die`, and `request_authority` are never used

Check warning on line 81 in src/filter/proposal_context.rs

View workflow job for this annotation

GitHub Actions / Rustfmt

methods `handle_operation`, `die`, and `request_authority` are never used

Check warning on line 81 in src/filter/proposal_context.rs

View workflow job for this annotation

GitHub Actions / Basic integration test

methods `handle_operation`, `die`, and `request_authority` are never used

Check warning on line 81 in src/filter/proposal_context.rs

View workflow job for this annotation

GitHub Actions / Parallel requests integration test

methods `handle_operation`, `die`, and `request_authority` are never used

Check warning on line 81 in src/filter/proposal_context.rs

View workflow job for this annotation

GitHub Actions / Remote address integration test

methods `handle_operation`, `die`, and `request_authority` are never used

Check failure on line 81 in src/filter/proposal_context.rs

View workflow job for this annotation

GitHub Actions / Clippy

methods `handle_operation`, `die`, and `request_authority` are never used

Check warning on line 81 in src/filter/proposal_context.rs

View workflow job for this annotation

GitHub Actions / Missing cluster integration test

methods `handle_operation`, `die`, and `request_authority` are never used

Check warning on line 81 in src/filter/proposal_context.rs

View workflow job for this annotation

GitHub Actions / Unreachable service integration test

methods `handle_operation`, `die`, and `request_authority` are never used

Check warning on line 81 in src/filter/proposal_context.rs

View workflow job for this annotation

GitHub Actions / Test Suite

methods `handle_operation`, `die`, and `request_authority` are never used

Check warning on line 81 in src/filter/proposal_context.rs

View workflow job for this annotation

GitHub Actions / Test Suite

methods `handle_operation`, `die`, and `request_authority` are never used
match operation {
no_implicit_dep::Operation::AwaitGrpcResponse(msg) => {
self.grpc_message_receiver_operation = Some(msg)
}
no_implicit_dep::Operation::AddHeaders(headers) => {
self.headers_operations.push(headers)
}
no_implicit_dep::Operation::Die(die) => self.die(die),
}
}

fn die(&mut self, die: EndRequestOperation) {
self.send_http_response(die.status, Vec::default(), None);
}

fn request_authority(&self) -> String {
match self.get_http_request_header(":authority") {
None => {
warn!(":authority header not found");
String::new()
}
Some(host) => {
let split_host = host.split(':').collect::<Vec<_>>();
split_host[0].to_owned()
}
}
}
}
7 changes: 7 additions & 0 deletions src/runtime_action_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ impl RuntimeActionSet {
}
})
}

pub fn start_flow<T: proxy_wasm::traits::HttpContext>(

Check warning on line 71 in src/runtime_action_set.rs

View workflow job for this annotation

GitHub Actions / Check

method `start_flow` is never used

Check warning on line 71 in src/runtime_action_set.rs

View workflow job for this annotation

GitHub Actions / Rustfmt

method `start_flow` is never used

Check warning on line 71 in src/runtime_action_set.rs

View workflow job for this annotation

GitHub Actions / Basic integration test

method `start_flow` is never used

Check warning on line 71 in src/runtime_action_set.rs

View workflow job for this annotation

GitHub Actions / Parallel requests integration test

method `start_flow` is never used

Check warning on line 71 in src/runtime_action_set.rs

View workflow job for this annotation

GitHub Actions / Remote address integration test

method `start_flow` is never used

Check failure on line 71 in src/runtime_action_set.rs

View workflow job for this annotation

GitHub Actions / Clippy

method `start_flow` is never used

Check warning on line 71 in src/runtime_action_set.rs

View workflow job for this annotation

GitHub Actions / Missing cluster integration test

method `start_flow` is never used

Check warning on line 71 in src/runtime_action_set.rs

View workflow job for this annotation

GitHub Actions / Unreachable service integration test

method `start_flow` is never used

Check warning on line 71 in src/runtime_action_set.rs

View workflow job for this annotation

GitHub Actions / Test Suite

method `start_flow` is never used

Check warning on line 71 in src/runtime_action_set.rs

View workflow job for this annotation

GitHub Actions / Test Suite

method `start_flow` is never used
&self,
_ctx: &T,
) -> crate::filter::proposal_context::no_implicit_dep::Operation {
todo!("implement me!")
}
}

#[cfg(test)]
Expand Down

0 comments on commit 589232d

Please sign in to comment.