Skip to content
This repository has been archived by the owner on Oct 18, 2023. It is now read-only.

Commit

Permalink
auth dump route (#707)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarinPostma authored Sep 26, 2023
1 parent 0a42e6e commit 578e373
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
10 changes: 9 additions & 1 deletion sqld/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ impl Authenticated {

pub fn is_namespace_authorized(&self, namespace: &NamespaceName) -> bool {
match self {
Authenticated::Anonymous => true,
Authenticated::Anonymous => false,
Authenticated::Authorized(Authorized {
namespace: Some(ns),
..
Expand All @@ -230,6 +230,14 @@ impl Authenticated {
}) => true,
}
}

/// Returns `true` if the authenticated is [`Anonymous`].
///
/// [`Anonymous`]: Authenticated::Anonymous
#[must_use]
pub fn is_anonymous(&self) -> bool {
matches!(self, Self::Anonymous)
}
}

#[derive(Debug)]
Expand Down
8 changes: 7 additions & 1 deletion sqld/src/http/user/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use futures::StreamExt;
use hyper::HeaderMap;
use pin_project_lite::pin_project;

use crate::auth::Authenticated;
use crate::connection::dump::exporter::export_dump;
use crate::error::Error;
use crate::namespace::MakeNamespace;
Expand Down Expand Up @@ -72,16 +73,21 @@ where
}

pub(super) async fn handle_dump<F: MakeNamespace>(
auth: Authenticated,
AxumState(state): AxumState<AppState<F>>,
headers: HeaderMap,
) -> Result<axum::body::StreamBody<impl futures::Stream<Item = Result<bytes::Bytes, Error>>>, Error>
) -> crate::Result<axum::body::StreamBody<impl futures::Stream<Item = Result<bytes::Bytes, Error>>>>
{
let namespace = namespace_from_headers(
&headers,
state.disable_default_namespace,
state.disable_namespaces,
)?;

if !auth.is_namespace_authorized(&namespace) | auth.is_anonymous() {
return Err(Error::NamespaceDoesntExist(namespace.to_string()));
}

let db_path = state.path.join("dbs").join(namespace.as_str()).join("data");

let connection = rusqlite::Connection::open(db_path)?;
Expand Down

0 comments on commit 578e373

Please sign in to comment.