Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ubuntu/app-center-ratings
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1a672016ca8e1cdaf3864cfd650bb45dadcd771d
Choose a base ref
..
head repository: ubuntu/app-center-ratings
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: a5ca5b255ded79bab327a61a2ece09ad41dbc52e
Choose a head ref
Showing with 5 additions and 19 deletions.
  1. +0 −7 src/app/context.rs
  2. +2 −8 src/app/interfaces/middleware.rs
  3. +2 −3 src/app/interfaces/servers/grpc/authentication.rs
  4. +1 −1 src/app/mod.rs
7 changes: 0 additions & 7 deletions src/app/context.rs
Original file line number Diff line number Diff line change
@@ -41,10 +41,3 @@ struct AppContextInner {
/// App configuration settings.
config: Config,
}

/// Contains the context for a given request
#[derive(Debug, Clone)]
pub struct RequestContext {
/// The URI this request is from.
pub uri: String,
}
10 changes: 2 additions & 8 deletions src/app/interfaces/middleware.rs
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ use hyper::{service::Service, Body};
use tonic::body::BoxBody;
use tower::Layer;

use crate::app::context::{AppContext, RequestContext};
use crate::app::context::AppContext;

/// Passthrough [`Layer`] containing the [`AppContext`], this is mainly used to construct
/// [`ContextMiddleware`].
@@ -88,17 +88,11 @@ where
}
}

fn call(&mut self, req: hyper::Request<Body>) -> Self::Future {
fn call(&mut self, mut req: hyper::Request<Body>) -> Self::Future {
assert!(self.ready);
self.ready = false;

let req_ctx = RequestContext {
uri: req.uri().to_string(),
};

let mut req = req;
req.extensions_mut().insert(self.app_ctx.clone());
req.extensions_mut().insert(req_ctx);

let future = self.inner.call(req);

5 changes: 2 additions & 3 deletions src/app/interfaces/servers/grpc/authentication.rs
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ use hyper::Request;
use tonic::Status;
use tracing::error;

use crate::app::{context::AppContext, RequestContext};
use crate::app::context::AppContext;

/// Authentication for a GRPC Server, it validates any passed in Grpc JWT client token
#[derive(Default, Debug, Copy, Clone)]
@@ -27,8 +27,7 @@ impl GrpcAuthenticator {
pub fn authenticate(&self, req: &mut Request<hyper::Body>) -> Result<(), Status> {
let app_ctx = req.extensions().get::<AppContext>().unwrap().clone();

let req_ctx = req.extensions().get::<RequestContext>().unwrap().clone();
let uri = &req_ctx.uri;
let uri = req.uri().to_string();

if Self::PUBLIC_PATHS.iter().any(|&s| uri.contains(s)) {
return Ok(());
2 changes: 1 addition & 1 deletion src/app/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Contains all definitions of the main application interface part of the program.
pub use context::{AppContext, RequestContext};
pub use context::AppContext;
pub use run::run;

mod context;