@@ -32,6 +32,12 @@ enum ClientCommand {
3232 /// The base_url of the upstream cache
3333 base_url : String ,
3434 } ,
35+ /// List all configured upstream caches
36+ ListUpstreamCaches {
37+ /// The authentication token
38+ #[ arg( short, long, env = "SNARF_CLIENT_TOKEN" , required = true ) ]
39+ token : String ,
40+ } ,
3541}
3642
3743/// CLI arguments for the client
@@ -61,11 +67,14 @@ async fn main() -> anyhow::Result<(), Box<dyn std::error::Error + Send + Sync>>
6167
6268 let client_cli = ClientCli :: parse ( ) ;
6369
64- Ok ( match & client_cli. command {
70+ match & client_cli. command {
6571 ClientCommand :: AddClosure { .. } => add_closure ( & client_cli) . await ?,
6672 ClientCommand :: CreateToken => create_token ( & client_cli) . await ?,
6773 ClientCommand :: AddUpstreamCache { .. } => add_upstream_cache ( & client_cli) . await ?,
68- } )
74+ ClientCommand :: ListUpstreamCaches { .. } => list_upstream_caches ( & client_cli) . await ?,
75+ } ;
76+
77+ Ok ( ( ) )
6978}
7079
7180/// Add the closure of a path in the store to the cache. The path can be of arbitrary depth, in any case
@@ -243,6 +252,23 @@ async fn add_upstream_cache(client_cli: &ClientCli) -> anyhow::Result<()> {
243252 Ok ( ( ) )
244253}
245254
255+ async fn list_upstream_caches ( client_cli : & ClientCli ) -> anyhow:: Result < ( ) > {
256+ let ClientCommand :: ListUpstreamCaches { token } = & client_cli. command else {
257+ bail ! ( "Upstream cache called with the wrong command" ) ;
258+ } ;
259+
260+ let response = get_client ( & client_cli. server_address , Some ( token) )
261+ . await ?
262+ . list_upstream_caches ( tonic:: Request :: new ( ListUpstreamCachesRequest { } ) )
263+ . await ?;
264+
265+ for base_url in response. into_inner ( ) . base_urls {
266+ println ! ( "{}" , base_url) ;
267+ }
268+
269+ Ok ( ( ) )
270+ }
271+
246272/// Get a client to connect to the server at server_address.
247273///
248274/// An optional token can be passed to authenticate the requests.
0 commit comments