summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2020-11-18 08:47:37 +0200
committerLars Wirzenius <liw@liw.fi>2020-11-18 08:47:37 +0200
commitb5ddc105852b63651916f322ce855baf61d129d0 (patch)
treed6e6ee6ca6f0ecfbba1311879e87e77a720a49c9 /src
parent24ffcb0083750bb77963a1ab8e3205290c2c7190 (diff)
downloadobnam2-b5ddc105852b63651916f322ce855baf61d129d0.tar.gz
feat! change client config to take a base URL instead of host, port
Diffstat (limited to 'src')
-rw-r--r--src/client.rs11
-rw-r--r--src/cmd/backup.rs2
-rw-r--r--src/cmd/list.rs2
-rw-r--r--src/cmd/restore.rs5
4 files changed, 10 insertions, 10 deletions
diff --git a/src/client.rs b/src/client.rs
index ecfc42c..d7dca36 100644
--- a/src/client.rs
+++ b/src/client.rs
@@ -13,8 +13,7 @@ use std::path::{Path, PathBuf};
#[derive(Debug, Deserialize, Clone)]
pub struct ClientConfig {
- pub server_name: String,
- pub server_port: u16,
+ pub server_url: String,
pub dbname: PathBuf,
pub root: PathBuf,
}
@@ -46,12 +45,14 @@ pub struct BackupClient {
}
impl BackupClient {
- pub fn new(host: &str, port: u16) -> anyhow::Result<Self> {
+ pub fn new(base_url: &str) -> anyhow::Result<Self> {
let client = Client::builder()
.danger_accept_invalid_certs(true)
.build()?;
- let base_url = format!("http://{}:{}/chunks", host, port,);
- Ok(Self { client, base_url })
+ Ok(Self {
+ client,
+ base_url: base_url.to_string(),
+ })
}
pub fn upload_filesystem_entry(
diff --git a/src/cmd/backup.rs b/src/cmd/backup.rs
index 308eafb..71f5aac 100644
--- a/src/cmd/backup.rs
+++ b/src/cmd/backup.rs
@@ -5,7 +5,7 @@ use std::path::Path;
pub fn backup(config: &Path, buffer_size: usize) -> anyhow::Result<()> {
let config = ClientConfig::read_config(config)?;
- let client = BackupClient::new(&config.server_name, config.server_port)?;
+ let client = BackupClient::new(&config.server_url)?;
{
let mut gen = Generation::create(&config.dbname)?;
diff --git a/src/cmd/list.rs b/src/cmd/list.rs
index 1972144..1741bce 100644
--- a/src/cmd/list.rs
+++ b/src/cmd/list.rs
@@ -3,7 +3,7 @@ use std::path::Path;
pub fn list(config: &Path) -> anyhow::Result<()> {
let config = ClientConfig::read_config(&config)?;
- let client = BackupClient::new(&config.server_name, config.server_port)?;
+ let client = BackupClient::new(&config.server_url)?;
for gen_id in client.list_generations()? {
println!("{}", gen_id);
diff --git a/src/cmd/restore.rs b/src/cmd/restore.rs
index 6e2690c..8aa0345 100644
--- a/src/cmd/restore.rs
+++ b/src/cmd/restore.rs
@@ -12,7 +12,7 @@ use structopt::StructOpt;
pub fn restore(config: &Path, gen_id: &str, dbname: &Path, to: &Path) -> anyhow::Result<()> {
let config = Config::read_config(&config).unwrap();
- let client = BackupClient::new(&config.server_name, config.server_port)?;
+ let client = BackupClient::new(&config.server_url)?;
let gen_chunk = client.fetch_generation(&gen_id)?;
debug!("gen: {:?}", gen_chunk);
{
@@ -50,8 +50,7 @@ struct Opt {
#[derive(Debug, Deserialize, Clone)]
pub struct Config {
- pub server_name: String,
- pub server_port: u16,
+ pub server_url: String,
}
impl Config {