use envoy_types::ext_authz::v3::CheckResponseExt; use envoy_types::ext_authz::v3::pb::{CheckRequest, CheckResponse}; use std::sync::Arc; use tonic::{Request, Response, Status}; use super::authorizer::Authorizer; #[derive(Debug)] pub struct CheckService { authorizer: Arc, } impl CheckService { pub fn new(authorizer: Arc) -> Self { Self { authorizer } } } #[tonic::async_trait] impl envoy_types::ext_authz::v3::pb::Authorization for CheckService { async fn check( &self, request: Request, ) -> Result, Status> { if self.authorizer.authorize(request.into_inner()) { log::info!("OK"); Ok(Response::new(CheckResponse::with_status(Status::ok("OK")))) } else { log::info!("Unauthorized"); Ok(Response::new(CheckResponse::with_status( Status::unauthenticated("Unauthorized"), ))) } } }