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 {
219
219
220
220
pub fn is_namespace_authorized ( & self , namespace : & NamespaceName ) -> bool {
221
221
match self {
222
- Authenticated :: Anonymous => true ,
222
+ Authenticated :: Anonymous => false ,
223
223
Authenticated :: Authorized ( Authorized {
224
224
namespace : Some ( ns) ,
225
225
..
@@ -230,6 +230,14 @@ impl Authenticated {
230
230
} ) => true ,
231
231
}
232
232
}
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
+ }
233
241
}
234
242
235
243
#[ derive( Debug ) ]
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ use futures::StreamExt;
7
7
use hyper:: HeaderMap ;
8
8
use pin_project_lite:: pin_project;
9
9
10
+ use crate :: auth:: Authenticated ;
10
11
use crate :: connection:: dump:: exporter:: export_dump;
11
12
use crate :: error:: Error ;
12
13
use crate :: namespace:: MakeNamespace ;
@@ -72,16 +73,21 @@ where
72
73
}
73
74
74
75
pub ( super ) async fn handle_dump < F : MakeNamespace > (
76
+ auth : Authenticated ,
75
77
AxumState ( state) : AxumState < AppState < F > > ,
76
78
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 > > > >
78
80
{
79
81
let namespace = namespace_from_headers (
80
82
& headers,
81
83
state. disable_default_namespace ,
82
84
state. disable_namespaces ,
83
85
) ?;
84
86
87
+ if !auth. is_namespace_authorized ( & namespace) | auth. is_anonymous ( ) {
88
+ return Err ( Error :: NamespaceDoesntExist ( namespace. to_string ( ) ) ) ;
89
+ }
90
+
85
91
let db_path = state. path . join ( "dbs" ) . join ( namespace. as_str ( ) ) . join ( "data" ) ;
86
92
87
93
let connection = rusqlite:: Connection :: open ( db_path) ?;
You can’t perform that action at this time.
0 commit comments