Verified Commit 3659dbea authored by Ole Martin Ruud's avatar Ole Martin Ruud
Browse files

Add prompt for password

parent 906149a2
......@@ -579,6 +579,7 @@ dependencies = [
"fern 0.5.8 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"reqwest 0.9.20 (registry+https://github.com/rust-lang/crates.io-index)",
"rpassword 4.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_yaml 0.8.9 (registry+https://github.com/rust-lang/crates.io-index)",
"snafu 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -1353,6 +1354,15 @@ name = "rgb"
version = "0.8.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "rpassword"
version = "4.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rust-argon2"
version = "0.5.1"
......@@ -2249,6 +2259,7 @@ dependencies = [
"checksum remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4a83fa3702a688b9359eccba92d153ac33fd2e8462f9e0e3fdf155239ea7792e"
"checksum reqwest 0.9.20 (registry+https://github.com/rust-lang/crates.io-index)" = "0f6d896143a583047512e59ac54a215cb203c29cc941917343edea3be8df9c78"
"checksum rgb 0.8.14 (registry+https://github.com/rust-lang/crates.io-index)" = "2089e4031214d129e201f8c3c8c2fe97cd7322478a0d1cdf78e7029b0042efdb"
"checksum rpassword 4.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f072d931f11a96546efd97642e1e75e807345aced86b947f9239102f262d0fcd"
"checksum rust-argon2 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4ca4eaef519b494d1f2848fc602d18816fed808a981aedf4f1f00ceb7c9d32cf"
"checksum rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783"
"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
......
......@@ -19,3 +19,4 @@ serde_yaml = "0.8.9"
snafu = "0.5.0"
structopt = "0.3.0"
unhtml = { version = "0.7.3", features = ["derive"] }
rpassword = "4.0.1"
......@@ -3,6 +3,7 @@ use reqwest::Url;
use serde::{Deserialize, Serialize};
use snafu::{OptionExt, ResultExt};
use std::fs::File;
use std::io::{prelude::*, stdin, stdout};
use crate::error::*;
use crate::Opts;
......@@ -28,14 +29,12 @@ pub struct Config {
impl Config {
pub fn try_new(opts: &Opts, project_dirs: Option<ProjectDirs>) -> Result<Self> {
match (opts.username.as_ref(), opts.password) {
(Some(username), true) => {
Ok(Config {
username: username.clone(),
password: "".into(), // TODO prompt for password
base_url: opts.base_url.clone(),
project_dirs,
})
}
(Some(username), true) => Ok(Config {
username: username.clone(),
password: rpassword::prompt_password_stdout("Password: ").context(InputError)?,
base_url: opts.base_url.clone(),
project_dirs,
}),
_ => {
let project_dirs = project_dirs
.context(ConfigError { msg: "Project dirs have to exist to fetch username and/or password from config file" })?;
......@@ -64,7 +63,7 @@ impl Config {
msg: "Username was not specified",
})?,
password: if opts.password {
"".into() /* TODO prompt */
rpassword::prompt_password_stdout("Password: ").context(InputError)?
} else {
config.password.context(ConfigError {
msg: "Password was not specified",
......
......@@ -33,6 +33,8 @@ pub enum Error {
path: std::path::PathBuf,
source: std::io::Error,
},
#[snafu(display("Unable to take input: {}", source))]
InputError { source: std::io::Error },
#[snafu(display("Unable to {{de,}}serialize '{}' to file: {}", name, source))]
YamlError {
name: String,
......
......@@ -2,13 +2,6 @@ use derive_builder::Builder;
use serde::{Deserialize, Serialize};
use unhtml::FromHtml;
#[derive(Debug, Builder)]
pub struct OrderTimeInfo<'a> {
pub day: &'a str,
pub hour: &'a str,
pub duration: &'a str,
}
#[derive(FromHtml, Serialize, Debug, Builder)]
#[html(selector = "[name=origform]")]
pub struct QueryRoomForm {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment