This repository was archived by the owner on Oct 18, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff 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 ) ]
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ use futures::StreamExt;
77use hyper:: HeaderMap ;
88use pin_project_lite:: pin_project;
99
10+ use crate :: auth:: Authenticated ;
1011use crate :: connection:: dump:: exporter:: export_dump;
1112use crate :: error:: Error ;
1213use crate :: namespace:: MakeNamespace ;
@@ -72,16 +73,21 @@ where
7273}
7374
7475pub ( 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) ?;
You can’t perform that action at this time.
0 commit comments