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

Commit 578e373

Browse files
authored
auth dump route (#707)
1 parent 0a42e6e commit 578e373

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

sqld/src/auth.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ impl Authenticated {
219219

220220
pub fn is_namespace_authorized(&self, namespace: &NamespaceName) -> bool {
221221
match self {
222-
Authenticated::Anonymous => true,
222+
Authenticated::Anonymous => false,
223223
Authenticated::Authorized(Authorized {
224224
namespace: Some(ns),
225225
..
@@ -230,6 +230,14 @@ impl Authenticated {
230230
}) => true,
231231
}
232232
}
233+
234+
/// Returns `true` if the authenticated is [`Anonymous`].
235+
///
236+
/// [`Anonymous`]: Authenticated::Anonymous
237+
#[must_use]
238+
pub fn is_anonymous(&self) -> bool {
239+
matches!(self, Self::Anonymous)
240+
}
233241
}
234242

235243
#[derive(Debug)]

sqld/src/http/user/dump.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use futures::StreamExt;
77
use hyper::HeaderMap;
88
use pin_project_lite::pin_project;
99

10+
use crate::auth::Authenticated;
1011
use crate::connection::dump::exporter::export_dump;
1112
use crate::error::Error;
1213
use crate::namespace::MakeNamespace;
@@ -72,16 +73,21 @@ where
7273
}
7374

7475
pub(super) async fn handle_dump<F: MakeNamespace>(
76+
auth: Authenticated,
7577
AxumState(state): AxumState<AppState<F>>,
7678
headers: HeaderMap,
77-
) -> Result<axum::body::StreamBody<impl futures::Stream<Item = Result<bytes::Bytes, Error>>>, Error>
79+
) -> crate::Result<axum::body::StreamBody<impl futures::Stream<Item = Result<bytes::Bytes, Error>>>>
7880
{
7981
let namespace = namespace_from_headers(
8082
&headers,
8183
state.disable_default_namespace,
8284
state.disable_namespaces,
8385
)?;
8486

87+
if !auth.is_namespace_authorized(&namespace) | auth.is_anonymous() {
88+
return Err(Error::NamespaceDoesntExist(namespace.to_string()));
89+
}
90+
8591
let db_path = state.path.join("dbs").join(namespace.as_str()).join("data");
8692

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

0 commit comments

Comments
 (0)