From 2872e4f431abecf5e690f3b213237c1a363ae0a4 Mon Sep 17 00:00:00 2001
From: l0r1s <contact@lorismoulin.com>
Date: Mon, 18 Sep 2023 19:42:37 +0300
Subject: [PATCH] feat: added new methods on Provider traits to retrieve
 node/namespace dirs/log paths, and added methods to retrieve all
 nodes/namespaces

---
 crates/provider/src/lib.rs | 28 ++++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)

diff --git a/crates/provider/src/lib.rs b/crates/provider/src/lib.rs
index 822c2c7..3646ef9 100644
--- a/crates/provider/src/lib.rs
+++ b/crates/provider/src/lib.rs
@@ -1,7 +1,7 @@
-mod native;
-mod shared;
+pub mod native;
+pub mod shared;
 
-use std::{net::IpAddr, path::PathBuf, process::ExitStatus, sync::Arc, time::Duration};
+use std::{net::IpAddr, path::PathBuf, process::ExitStatus, sync::Arc, time::Duration, collections::HashMap};
 
 use async_trait::async_trait;
 use shared::types::{
@@ -51,7 +51,9 @@ pub enum ProviderError {
 
 #[async_trait]
 pub trait Provider {
-    fn capabilities(&self) -> ProviderCapabilities;
+    fn capabilities(&self) -> &ProviderCapabilities;
+
+    async fn namespaces(&self) -> HashMap<String, DynNamespace>;
 
     async fn create_namespace(&self) -> Result<DynNamespace, ProviderError>;
 }
@@ -60,7 +62,11 @@ pub type DynProvider = Arc<dyn Provider>;
 
 #[async_trait]
 pub trait ProviderNamespace {
-    fn id(&self) -> String;
+    fn id(&self) -> &str;
+
+    fn base_dir(&self) -> &PathBuf;
+
+    async fn nodes(&self) -> HashMap<String, DynNode>;
 
     async fn spawn_node(&self, options: SpawnNodeOptions) -> Result<DynNode, ProviderError>;
 
@@ -77,7 +83,17 @@ type ExecutionResult = Result<String, (ExitStatus, String)>;
 
 #[async_trait]
 pub trait ProviderNode {
-    fn name(&self) -> String;
+    fn name(&self) -> &str;
+
+    fn base_dir(&self) -> &PathBuf;
+
+    fn config_dir(&self) -> &PathBuf;
+
+    fn data_dir(&self) -> &PathBuf;
+
+    fn scripts_dir(&self) -> &PathBuf;
+
+    fn log_path(&self) -> &PathBuf;
 
     async fn endpoint(&self) -> Result<(IpAddr, Port), ProviderError>;
 
-- 
GitLab