[wip] Grab configuration file
This commit is contained in:
parent
fc275d1bc9
commit
a7d5962d30
3 changed files with 86 additions and 4 deletions
55
Cargo.lock
generated
55
Cargo.lock
generated
|
@ -86,6 +86,26 @@ version = "0.8.3"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc"
|
||||
|
||||
[[package]]
|
||||
name = "dirs"
|
||||
version = "4.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059"
|
||||
dependencies = [
|
||||
"dirs-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dirs-sys"
|
||||
version = "0.3.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "03d86534ed367a67548dc68113a0f5db55432fdfbb6e6f9d77704397d95d5780"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"redox_users",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dotenv"
|
||||
version = "0.15.0"
|
||||
|
@ -585,8 +605,11 @@ dependencies = [
|
|||
"env_logger",
|
||||
"log",
|
||||
"reqwest",
|
||||
"serde",
|
||||
"tokio",
|
||||
"toml",
|
||||
"url",
|
||||
"xdg",
|
||||
"yaserde",
|
||||
"yaserde_derive",
|
||||
]
|
||||
|
@ -649,6 +672,16 @@ dependencies = [
|
|||
"bitflags",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_users"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "528532f3d801c87aec9def2add9ca802fe569e44a544afe633765267840abe64"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
"redox_syscall",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.5.4"
|
||||
|
@ -757,9 +790,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.131"
|
||||
version = "1.0.136"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b4ad69dfbd3e45369132cc64e6748c2d65cdfb001a2b1c232d128b4ad60561c1"
|
||||
checksum = "ce31e24b01e1e524df96f1c2fdd054405f8d7376249a5110886fb4b658484789"
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
|
@ -919,6 +952,15 @@ dependencies = [
|
|||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml"
|
||||
version = "0.5.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tower-service"
|
||||
version = "0.3.1"
|
||||
|
@ -1128,6 +1170,15 @@ dependencies = [
|
|||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "xdg"
|
||||
version = "2.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0c4583db5cbd4c4c0303df2d15af80f0539db703fa1c68802d4cbbd2dd0f88f6"
|
||||
dependencies = [
|
||||
"dirs",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "xml-rs"
|
||||
version = "0.8.4"
|
||||
|
|
|
@ -11,7 +11,10 @@ dotenv = "0.15.0"
|
|||
env_logger = "0.8.4"
|
||||
log = "0.4.0"
|
||||
reqwest = { version = "0.11", features = ["json"] }
|
||||
serde = "1.0.136"
|
||||
tokio = { version = "1", features = ["full"] }
|
||||
toml = "0.5.8"
|
||||
url = "2.2.2"
|
||||
xdg = "2.4.1"
|
||||
yaserde = "0.7.1"
|
||||
yaserde_derive = "0.7.1"
|
||||
|
|
32
src/main.rs
32
src/main.rs
|
@ -1,15 +1,37 @@
|
|||
extern crate xdg;
|
||||
|
||||
#[allow(unused)]
|
||||
use env_logger::{Env, Target};
|
||||
#[allow(unused)]
|
||||
use log::{debug, error, info, log_enabled, warn};
|
||||
use reqwest;
|
||||
use serde::Deserialize;
|
||||
use std::collections::HashMap;
|
||||
use std::io::{self, Write};
|
||||
use toml;
|
||||
use url::Url;
|
||||
#[allow(unused)]
|
||||
use yaserde_derive::{YaDeserialize, YaSerialize};
|
||||
use yaserde::de::from_str;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct Config {
|
||||
credentials: Credentials,
|
||||
paths: NextcloudPaths,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct Credentials {
|
||||
username: String,
|
||||
password: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct NextcloudPaths {
|
||||
root: Url,
|
||||
target: String,
|
||||
}
|
||||
|
||||
#[derive(Default, PartialEq, Debug, YaDeserialize)]
|
||||
#[yaserde(
|
||||
rename = "multistatus",
|
||||
|
@ -87,6 +109,12 @@ pub struct Collection {
|
|||
collection: String,
|
||||
}
|
||||
|
||||
fn init() -> Result<Config, Box<dyn std::error::Error>> {
|
||||
let xdg_dirs = xdg::BaseDirectories::with_prefix("publicise-rs").unwrap();
|
||||
let config_file = xdg_dirs.find_config_file("config.toml").unwrap();
|
||||
return Error{};
|
||||
}
|
||||
|
||||
async fn get_folder_contents(url_tail: &str, password: &str) -> Result<String, Box<dyn std::error::Error>> {
|
||||
debug!("[get_folder_contents] Entering function...");
|
||||
let root_url = Url::parse("https://cloud.theadamcooper.com")?;
|
||||
|
@ -223,13 +251,13 @@ fn indent(size: usize) -> String {
|
|||
|
||||
#[tokio::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
// use yaserde::de::from_str;
|
||||
|
||||
env_logger::Builder::from_env(Env::default().default_filter_or("trace"))
|
||||
env_logger::Builder::from_env(Env::default().default_filter_or("debug"))
|
||||
.target(Target::Stdout)
|
||||
.init();
|
||||
println!("Publicise it!\n\n");
|
||||
|
||||
let config = init().unwrap();
|
||||
let password: String = get_password().unwrap().trim().to_string();
|
||||
let folder_contents: String =
|
||||
get_folder_contents("/remote.php/dav/files/adam/test_public", &password)
|
||||
|
|
Loading…
Reference in a new issue