summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-12-10 16:00:50 +0200
committerLars Wirzenius <liw@liw.fi>2021-12-10 16:00:50 +0200
commitc37e4ef0a08613e1b70aaec7232fda8ef6b21c0c (patch)
tree84f815188b1468c7d6c32fda4cd3577680aed738
parentccb7fa7febbd8b44cff03d2cc55eb65ba387d576 (diff)
downloadobnam-benchmark-c37e4ef0a08613e1b70aaec7232fda8ef6b21c0c.tar.gz
add start of Obnam
Sponsored-by: author
-rw-r--r--src/lib.rs1
-rw-r--r--src/obnam.rs129
2 files changed, 130 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 22d7184..db53aac 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -28,6 +28,7 @@
//! This crate only collects data from a set of benchmarks. It does
//! not analyze the data. The data can be stored for later analysis.
+pub mod obnam;
pub mod result;
pub mod specification;
pub mod step;
diff --git a/src/obnam.rs b/src/obnam.rs
new file mode 100644
index 0000000..8100797
--- /dev/null
+++ b/src/obnam.rs
@@ -0,0 +1,129 @@
+//! Manage and execute Obnam.
+
+use serde::Serialize;
+use std::path::{Path, PathBuf};
+use tempfile::{tempdir, TempDir};
+
+const SERVER_PORT: u16 = 8888;
+
+
+/// An Obnam system.
+///
+/// Manage an Obnam server and run the Obnam client.
+pub struct Obnam {
+ configs: TempDir,
+ root: TempDir,
+ chunks: TempDir,
+}
+
+/// Possible errors from managing an Obnam system.
+#[derive(Debug, thiserror::Error)]
+pub enum ObnamError {
+ /// Error creating a temporary directory.
+ #[error(transparent)]
+ TempDir(#[from] std::io::Error),
+}
+
+impl Obnam {
+ pub fn new() -> Result<Self, ObnamError> {
+ let o = Self{
+ configs: tempdir()?,
+ root: tempdir()?,
+ chunks: tempdir()?,
+ };
+ o.configure()?;
+ Ok(o)
+ }
+
+ pub fn root(&self) -> &Path {
+ self.root.path()
+ }
+
+ fn chunks(&self) -> &Path {
+ self.chunks.path()
+ }
+
+ fn configs(&self) -> &Path {
+ self.configs.path()
+ }
+
+ fn server_config(&self) -> PathBuf {
+ self.configs().join("server.yaml")
+ }
+
+ fn client_config(&self) -> PathBuf {
+ self.configs().join("client.yaml")
+ }
+
+ fn configure(&self) -> Result<(), ObnamError> {
+ ServerConfig::new(SERVER_PORT, self.chunks()).write(&self.server_config())?;
+ ClientConfig::new(SERVER_PORT, self.root()).write(&self.client_config())?;
+ Ok(())
+ }
+
+ pub fn start_server(&mut self) -> Result<(), ObnamError> {
+ Ok(())
+ }
+
+ pub fn stop_server(&mut self) -> Result<(), ObnamError> {
+ Ok(())
+ }
+
+ pub fn backup(&mut self) -> Result<(), ObnamError>
+ {
+ Ok(())
+ }
+
+ pub fn restore(&mut self) -> Result<(), ObnamError>
+ {
+ Ok(())
+ }
+}
+
+#[derive(Debug, Serialize)]
+struct ServerConfig {
+ address: String,
+ chunks: PathBuf,
+ tls_key: PathBuf,
+ tls_cert: PathBuf,
+}
+
+impl ServerConfig {
+ fn new(port: u16, chunks: &Path) -> Self {
+ Self {
+ address: format!("localhost:{}", port),
+ chunks: chunks.to_path_buf(),
+ tls_key: PathBuf::from("tls.key"),
+ tls_cert: PathBuf::from("tls.pem"),
+ }
+ }
+
+ fn write(&self, filename: &Path) -> Result<(), ObnamError> {
+ std::fs::write(filename, serde_yaml::to_string(self).unwrap())?;
+ Ok(())
+ }
+}
+
+#[derive(Debug, Serialize)]
+struct ClientConfig {
+ server_url: String,
+ verify_tls_cert: bool,
+ roots: Vec<PathBuf>,
+ log: Option<PathBuf>,
+}
+
+impl ClientConfig {
+ fn new(port: u16, root: &Path) -> Self {
+ Self {
+ server_url: format!("https://localhost:{}", port),
+ verify_tls_cert: false,
+ roots: vec![root.to_path_buf()],
+ log: None,
+ }
+ }
+
+ fn write(&self, filename: &Path) -> Result<(), ObnamError> {
+ std::fs::write(filename, serde_yaml::to_string(self).unwrap())?;
+ Ok(())
+ }
+}