Skip to content

Commit bf9b093

Browse files
committed
Add GET /v1/namespaces endpoint to admin API
The new endpoint will return the list of all namespaces currently available. This is required for building a proper UI for the admin portion of the application. Before this change, this was only doable by listing directories in the DB storage directory.
1 parent 395b2ca commit bf9b093

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

libsql-server/src/http/admin/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ where
142142
};
143143
let router = axum::Router::new()
144144
.route("/", get(handle_get_index))
145+
.route("/v1/namespaces", get(handle_get_namespaces))
145146
.route(
146147
"/v1/namespaces/:namespace/config",
147148
get(handle_get_config).post(handle_post_config),
@@ -238,6 +239,19 @@ async fn handle_get_index() -> &'static str {
238239
"Welcome to the sqld admin API"
239240
}
240241

242+
async fn handle_get_namespaces<C: Connector>(
243+
State(app_state): State<Arc<AppState<C>>>,
244+
) -> Json<Vec<String>> {
245+
let store = app_state.namespaces.meta_store();
246+
let namespaces = store
247+
.list_names()
248+
.await
249+
.iter()
250+
.map(|n| n.to_string())
251+
.collect();
252+
Json(namespaces)
253+
}
254+
241255
async fn handle_metrics(State(metrics): State<Metrics>) -> String {
242256
metrics.render()
243257
}

libsql-server/src/namespace/meta_store.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,10 @@ impl MetaStore {
562562
self.inner.configs.lock().await.contains_key(namespace)
563563
}
564564

565+
pub async fn list_names(&self) -> Vec<NamespaceName> {
566+
self.inner.configs.lock().await.keys().cloned().collect()
567+
}
568+
565569
pub(crate) async fn shutdown(&self) -> crate::Result<()> {
566570
let replicator = self.inner.wal_manager.wrapper().as_ref();
567571

0 commit comments

Comments
 (0)