File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11use std:: fmt:: Display ;
22use std:: pin:: Pin ;
3+ use std:: str:: FromStr ;
34
45use bytes:: Bytes ;
56use dialoguer:: BasicHistory ;
67use rusqlite:: types:: ValueRef ;
78use tokio_stream:: { Stream , StreamExt as _} ;
8- use tonic:: metadata:: BinaryMetadataValue ;
9+ use tonic:: metadata:: { AsciiMetadataValue , BinaryMetadataValue } ;
910
1011use crate :: connection:: Connection as _;
1112use crate :: database:: Connection ;
@@ -139,11 +140,12 @@ impl AdminShellService for AdminShell {
139140
140141pub struct AdminShellClient {
141142 remote_url : String ,
143+ auth : Option < String > ,
142144}
143145
144146impl AdminShellClient {
145- pub fn new ( remote_url : String ) -> Self {
146- Self { remote_url }
147+ pub fn new ( remote_url : String , auth : Option < String > ) -> Self {
148+ Self { remote_url, auth }
147149 }
148150
149151 pub async fn run_namespace ( & self , namespace : & str ) -> anyhow:: Result < ( ) > {
@@ -160,6 +162,14 @@ impl AdminShellClient {
160162 "x-namespace-bin" ,
161163 BinaryMetadataValue :: from_bytes ( namespace. as_slice ( ) ) ,
162164 ) ;
165+
166+ if let Some ( ref auth) = self . auth {
167+ req. metadata_mut ( ) . insert (
168+ "authorization" ,
169+ AsciiMetadataValue :: from_str ( & format ! ( "basic {auth}" ) ) . unwrap ( ) ,
170+ ) ;
171+ }
172+
163173 let mut resp_stream = client. shell ( req) . await ?. into_inner ( ) ;
164174
165175 let mut history = BasicHistory :: new ( ) ;
Original file line number Diff line number Diff line change @@ -181,16 +181,17 @@ where
181181 . level ( tracing:: Level :: DEBUG )
182182 . latency_unit ( tower_http:: LatencyUnit :: Micros ) ,
183183 ) ,
184- )
185- . layer ( axum:: middleware:: from_fn_with_state ( auth, auth_middleware) ) ;
184+ ) ;
186185
187186 let admin_shell = crate :: admin_shell:: make_svc ( namespaces. clone ( ) ) ;
188187 let grpc_router = tonic:: transport:: Server :: builder ( )
189188 . accept_http1 ( true )
190189 . add_service ( tonic_web:: enable ( admin_shell) )
191190 . into_router ( ) ;
192191
193- let router = router. merge ( grpc_router) ;
192+ let router = router
193+ . merge ( grpc_router)
194+ . layer ( axum:: middleware:: from_fn_with_state ( auth, auth_middleware) ) ;
194195
195196 hyper:: server:: Server :: builder ( acceptor)
196197 . serve ( router. into_make_service ( ) )
Original file line number Diff line number Diff line change @@ -313,6 +313,8 @@ enum UtilsSubcommands {
313313 admin_api_url : String ,
314314 #[ clap( long) ]
315315 namespace : Option < String > ,
316+ #[ clap( long) ]
317+ auth : Option < String > ,
316318 } ,
317319}
318320
@@ -719,9 +721,12 @@ async fn main() -> Result<()> {
719721 UtilsSubcommands :: AdminShell {
720722 admin_api_url,
721723 namespace,
724+ auth,
722725 } => {
723- let client =
724- libsql_server:: admin_shell:: AdminShellClient :: new ( admin_api_url. clone ( ) ) ;
726+ let client = libsql_server:: admin_shell:: AdminShellClient :: new (
727+ admin_api_url. clone ( ) ,
728+ auth. clone ( ) ,
729+ ) ;
725730 if let Some ( ns) = namespace {
726731 client. run_namespace ( ns) . await ?;
727732 }
You can’t perform that action at this time.
0 commit comments