Skip to content

Commit

Permalink
Add headers type alias
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Cattermole <acatterm@redhat.com>
  • Loading branch information
adam-cattermole committed Jan 16, 2025
1 parent 1698f79 commit 76c7e59
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/auth_action.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::configuration::{Action, FailureMode, Service};
use crate::data::{store_metadata, Predicate, PredicateVec};
use crate::envoy::{CheckResponse, CheckResponse_oneof_http_response, HeaderValueOption};
use crate::service::{GrpcErrResponse, GrpcService};
use crate::service::{GrpcErrResponse, GrpcService, Headers};
use log::debug;
use std::rc::Rc;

Expand Down Expand Up @@ -45,7 +45,7 @@ impl AuthAction {
pub fn process_response(
&self,
check_response: CheckResponse,
) -> Result<Vec<(String, String)>, GrpcErrResponse> {
) -> Result<Headers, GrpcErrResponse> {
//todo(adam-cattermole):hostvar resolver?
// store dynamic metadata in filter state
debug!("process_response(auth): store_metadata");
Expand Down Expand Up @@ -92,7 +92,7 @@ impl AuthAction {
}
}

fn get_header_vec(headers: &[HeaderValueOption]) -> Vec<(String, String)> {
fn get_header_vec(headers: &[HeaderValueOption]) -> Headers {
headers
.iter()
.map(|header| {
Expand Down
8 changes: 4 additions & 4 deletions src/filter/operations.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::filter::operations::Operation::SendGrpcRequest;
use crate::runtime_action_set::RuntimeActionSet;
use crate::service::{GrpcErrResponse, GrpcRequest, IndexedGrpcRequest};
use crate::service::{GrpcErrResponse, GrpcRequest, Headers, IndexedGrpcRequest};
use std::rc::Rc;

pub enum Operation {
Expand Down Expand Up @@ -86,15 +86,15 @@ impl GrpcMessageReceiverOperation {
}

pub struct HeadersOperation {
headers: Vec<(String, String)>,
headers: Headers,
}

impl HeadersOperation {
pub fn new(headers: Vec<(String, String)>) -> Self {
pub fn new(headers: Headers) -> Self {
Self { headers }
}

pub fn headers(self) -> Vec<(String, String)> {
pub fn headers(self) -> Headers {
self.headers
}
}
4 changes: 2 additions & 2 deletions src/ratelimit_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::envoy::{
HeaderValue, RateLimitDescriptor, RateLimitDescriptor_Entry, RateLimitResponse,
RateLimitResponse_Code, StatusCode,
};
use crate::service::{GrpcErrResponse, GrpcService};
use crate::service::{GrpcErrResponse, GrpcService, Headers};
use cel_interpreter::Value;
use log::{debug, error};
use protobuf::RepeatedField;
Expand Down Expand Up @@ -206,7 +206,7 @@ impl RateLimitAction {
}
}

fn get_header_vec(headers: RepeatedField<HeaderValue>) -> Vec<(String, String)> {
fn get_header_vec(headers: RepeatedField<HeaderValue>) -> Headers {
headers
.iter()
.map(|header| (header.key.to_owned(), header.value.to_owned()))
Expand Down
4 changes: 2 additions & 2 deletions src/runtime_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::configuration::{Action, FailureMode, Service, ServiceType};
use crate::ratelimit_action::RateLimitAction;
use crate::service::auth::AuthService;
use crate::service::rate_limit::RateLimitService;
use crate::service::{GrpcErrResponse, GrpcService};
use crate::service::{GrpcErrResponse, GrpcService, Headers};
use log::debug;
use protobuf::Message;
use std::collections::HashMap;
Expand Down Expand Up @@ -67,7 +67,7 @@ impl RuntimeAction {
}
}

pub fn process_response(&self, msg: &[u8]) -> Result<Vec<(String, String)>, GrpcErrResponse> {
pub fn process_response(&self, msg: &[u8]) -> Result<Headers, GrpcErrResponse> {
match self {
Self::Auth(auth_action) => match Message::parse_from_bytes(msg) {
Ok(check_response) => auth_action.process_response(check_response),
Expand Down
4 changes: 2 additions & 2 deletions src/runtime_action_set.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::configuration::{ActionSet, Service};
use crate::data::{Predicate, PredicateVec};
use crate::runtime_action::RuntimeAction;
use crate::service::{GrpcErrResponse, IndexedGrpcRequest};
use crate::service::{GrpcErrResponse, Headers, IndexedGrpcRequest};
use std::collections::HashMap;
use std::rc::Rc;

Expand Down Expand Up @@ -80,7 +80,7 @@ impl RuntimeActionSet {
&self,
index: usize,
msg: &[u8],
) -> Result<(Option<IndexedGrpcRequest>, Vec<(String, String)>), GrpcErrResponse> {
) -> Result<(Option<IndexedGrpcRequest>, Headers), GrpcErrResponse> {
self.runtime_actions[index]
.process_response(msg)
.map(|headers| {
Expand Down
5 changes: 3 additions & 2 deletions src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,16 @@ impl GrpcRequest {
}
}

pub type Headers = Vec<(String, String)>;
#[derive(Debug)]
pub struct GrpcErrResponse {
status_code: u32,
response_headers: Vec<(String, String)>,
response_headers: Headers,
body: String,
}

impl GrpcErrResponse {
pub fn new(status_code: u32, response_headers: Vec<(String, String)>, body: String) -> Self {
pub fn new(status_code: u32, response_headers: Headers, body: String) -> Self {
Self {
status_code,
response_headers,
Expand Down

0 comments on commit 76c7e59

Please sign in to comment.