Commit bf62fe46 authored by Nugine's avatar Nugine
Browse files

s3s: ops: change check_access place

parent 949998dd
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
use super::Credentials;

use crate::path::S3Path;
use crate::S3Operation;

use hyper::http::Extensions;
use hyper::HeaderMap;
@@ -10,6 +11,7 @@ use hyper::Uri;
pub struct S3AuthContext<'a> {
    pub(crate) credentials: Option<&'a Credentials>,
    pub(crate) s3_path: &'a S3Path,
    pub(crate) s3_op: &'a S3Operation,

    pub(crate) method: &'a Method,
    pub(crate) uri: &'a Uri,
@@ -35,6 +37,12 @@ impl<'a> S3AuthContext<'a> {
        self.s3_path
    }

    /// Returns the S3 operation of current request.
    #[must_use]
    pub fn s3_op(&self) -> &S3Operation {
        self.s3_op
    }

    #[must_use]
    pub fn method(&self) -> &Method {
        self.method
+1 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ pub trait S3Auth: Send + Sync + 'static {
    /// Common fields in the context:
    /// + [`cx.credentials()`](S3AuthContext::credentials)
    /// + [`cx.s3_path()`](S3AuthContext::s3_path)
    /// + [`cx.s3_op().name()`](crate::S3Operation::name)
    /// + [`cx.extensions_mut()`](S3AuthContext::extensions_mut)
    async fn check_access(&self, cx: &mut S3AuthContext<'_>) -> S3Result<()> {
        match cx.credentials() {
+15 −12
Original line number Diff line number Diff line
@@ -259,18 +259,6 @@ async fn prepare(req: &mut Request, auth: Option<&dyn S3Auth>, base_domain: Opti
            req.s3ext.credentials = credentials;
        }

        if let Some(auth) = auth {
            let mut cx = S3AuthContext {
                credentials: req.s3ext.credentials.as_ref(),
                s3_path,
                method: &req.method,
                uri: &req.uri,
                headers: &req.headers,
                extensions: &mut req.extensions,
            };
            auth.check_access(&mut cx).await?;
        }

        if body_changed {
            // invalidate the original content length
            if let Some(val) = req.headers.get_mut(header::CONTENT_LENGTH) {
@@ -321,6 +309,21 @@ async fn prepare(req: &mut Request, auth: Option<&dyn S3Auth>, base_domain: Opti

    debug!(op = %op.name(), ?s3_path, "resolved route");

    if let Some(auth) = auth {
        let mut cx = S3AuthContext {
            credentials: req.s3ext.credentials.as_ref(),
            s3_path,
            s3_op: &crate::S3Operation { name: op.name() },
            method: &req.method,
            uri: &req.uri,
            headers: &req.headers,
            extensions: &mut req.extensions,
        };
        auth.check_access(&mut cx).await?;
    }

    debug!(op = %op.name(), ?s3_path, "checked access");

    if needs_full_body {
        extract_full_body(content_length, &mut req.body).await?;
    }