Skip to content

Commit

Permalink
Add HashedTokenRouter back as alias for TokenRouter (#1018)
Browse files Browse the repository at this point in the history
  • Loading branch information
XAMPPRocky authored Sep 18, 2024
1 parent 3363452 commit cd93aae
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub use self::{
registry::FilterRegistry,
set::{FilterMap, FilterSet},
timestamp::Timestamp,
token_router::TokenRouter,
token_router::{HashedTokenRouter, TokenRouter},
write::WriteContext,
};

Expand Down
1 change: 1 addition & 0 deletions src/filters/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ impl FilterSet {
filters::Debug::factory(),
filters::Drop::factory(),
filters::Firewall::factory(),
filters::HashedTokenRouter::factory(),
filters::LoadBalancer::factory(),
filters::LocalRateLimit::factory(),
filters::Match::factory(),
Expand Down
21 changes: 21 additions & 0 deletions src/filters/token_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,27 @@ impl Filter for TokenRouter {
}
}

pub struct HashedTokenRouter(TokenRouter);

impl StaticFilter for HashedTokenRouter {
const NAME: &'static str = "quilkin.filters.token_router.v1alpha1.HashedTokenRouter";
type Configuration = Config;
type BinaryConfiguration = proto::TokenRouter;

fn try_from_config(config: Option<Self::Configuration>) -> Result<Self, CreationError> {
Ok(Self(TokenRouter {
config: config.unwrap_or_default(),
}))
}
}

#[async_trait::async_trait]
impl Filter for HashedTokenRouter {
async fn read(&self, ctx: &mut ReadContext) -> Result<(), FilterError> {
self.0.sync_read(ctx)
}
}

pub enum RouterError {
NoTokenFound,
NoEndpointMatch { token: bytes::Bytes },
Expand Down
3 changes: 0 additions & 3 deletions src/xds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ impl Resource {
}
};

let len = config.value.len();

let json_value = match crate::filters::FilterRegistry::get_factory(&filter.name)
.ok_or_else(|| {
crate::filters::CreationError::NotFound(filter.name.clone())
Expand All @@ -88,7 +86,6 @@ impl Resource {
{
Ok(jv) => jv,
Err(err) => {
tracing::error!("wtf {} {len} {err:#}", filter.name);
return Err(err.into());
}
};
Expand Down

0 comments on commit cd93aae

Please sign in to comment.