Receive user input (password)

This commit is contained in:
Adam Cooper 2021-12-13 14:23:25 -05:00
parent f020ecb6d9
commit 585b247297

View file

@ -1,16 +1,22 @@
extern crate xml; extern crate xml;
#[allow(unused)]
// use dotenv::dotenv; // use dotenv::dotenv;
use env_logger::{ Env, Target }; use env_logger::{ Env, Target };
#[allow(unused)]
use log::{debug, info, log_enabled, warn, error}; use log::{debug, info, log_enabled, warn, error};
use reqwest; use reqwest;
#[allow(unused)]
use std::io::{self, Write}; use std::io::{self, Write};
#[allow(unused)]
use xml::reader::{EventReader, XmlEvent}; use xml::reader::{EventReader, XmlEvent};
#[allow(unused)]
fn publicise() { fn publicise() {
} }
#[allow(unused)]
async fn traverse(password: &str) -> Result<reqwest::Response, Box<dyn std::error::Error>> { async fn traverse(password: &str) -> Result<reqwest::Response, Box<dyn std::error::Error>> {
let root_url = "https://theadamcooper.com"; let root_url = "https://theadamcooper.com";
let url_tail = "/nextcloud/remote.php/dav/files/adam/public"; let url_tail = "/nextcloud/remote.php/dav/files/adam/public";
@ -20,19 +26,24 @@ async fn traverse(password: &str) -> Result<reqwest::Response, Box<dyn std::erro
.basic_auth("adam", Some(password)) .basic_auth("adam", Some(password))
.send() .send()
.await?; .await?;
// env_logger::Debug(response); debug!("{:?}", response);
Ok(response) Ok(response)
} }
fn main() { fn get_password() -> Result<String, std::io::Error> {
env_logger::Builder::from_env(Env::default().default_filter_or("trace")).target(Target::Stdout).init();
println!("Publicise it!");
print!("Nextcloud password: "); print!("Nextcloud password: ");
io::stdout().flush().unwrap(); io::stdout().flush().unwrap();
let mut buffer = String::new(); let mut buffer = String::new();
let stdin = io::stdin(); let stdin = io::stdin();
match stdin.read_line(&mut buffer) { match stdin.read_line(&mut buffer) {
Ok(_) => debug!("buffer: {}", buffer), Ok(_) => Ok(buffer),
Err(error) => println!("error: {}", error), Err(error) => Err(error),
}; }
}
fn main() {
env_logger::Builder::from_env(Env::default().default_filter_or("trace")).target(Target::Stdout).init();
println!("Publicise it!");
let password = get_password().unwrap();
debug!("Received password: {}", password);
} }