From c90a57153bb815b857a0eff7e2419b783742f429 Mon Sep 17 00:00:00 2001 From: ashthespy Date: Tue, 26 Mar 2019 17:54:47 +0100 Subject: [PATCH] Remove password prompt --- Cargo.lock | 100 ++++++---------------------------------------------- Cargo.toml | 1 - src/main.rs | 30 ++++++---------- 3 files changed, 21 insertions(+), 110 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ce7b01f..c3d3353 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -207,7 +207,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "cc" -version = "1.0.31" +version = "1.0.32" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -298,18 +298,6 @@ dependencies = [ "quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "env_logger" -version = "0.5.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "humantime 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "termcolor 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "env_logger" version = "0.6.1" @@ -617,40 +605,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "librespot" version = "0.1.0" -source = "git+https://github.com/ashthespy/librespot?branch=vollibrespot#70d71ae8dcc8cf92b52a90ad4fd23864c573edd2" +source = "git+https://github.com/ashthespy/librespot?branch=vollibrespot#79125a5c483d0318f2498d5ddb6d701b85f375ef" dependencies = [ - "base64 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", - "env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "getopts 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", - "hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "hyper 0.11.27 (registry+https://github.com/rust-lang/crates.io-index)", "librespot-audio 0.1.0 (git+https://github.com/ashthespy/librespot?branch=vollibrespot)", "librespot-connect 0.1.0 (git+https://github.com/ashthespy/librespot?branch=vollibrespot)", "librespot-core 0.1.0 (git+https://github.com/ashthespy/librespot?branch=vollibrespot)", "librespot-metadata 0.1.0 (git+https://github.com/ashthespy/librespot?branch=vollibrespot)", "librespot-playback 0.1.0 (git+https://github.com/ashthespy/librespot?branch=vollibrespot)", "librespot-protocol 0.1.0 (git+https://github.com/ashthespy/librespot?branch=vollibrespot)", - "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "num-bigint 0.1.44 (registry+https://github.com/rust-lang/crates.io-index)", - "protobuf 2.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.23 (registry+https://github.com/rust-lang/crates.io-index)", - "rpassword 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", - "sha-1 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-core 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-signal 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "vergen 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "librespot-audio" version = "0.1.0" -source = "git+https://github.com/ashthespy/librespot?branch=vollibrespot#70d71ae8dcc8cf92b52a90ad4fd23864c573edd2" +source = "git+https://github.com/ashthespy/librespot?branch=vollibrespot#79125a5c483d0318f2498d5ddb6d701b85f375ef" dependencies = [ "aes-ctr 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "bit-set 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -667,7 +637,7 @@ dependencies = [ [[package]] name = "librespot-connect" version = "0.1.0" -source = "git+https://github.com/ashthespy/librespot?branch=vollibrespot#70d71ae8dcc8cf92b52a90ad4fd23864c573edd2" +source = "git+https://github.com/ashthespy/librespot?branch=vollibrespot#79125a5c483d0318f2498d5ddb6d701b85f375ef" dependencies = [ "aes-ctr 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "base64 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -694,7 +664,7 @@ dependencies = [ [[package]] name = "librespot-core" version = "0.1.0" -source = "git+https://github.com/ashthespy/librespot?branch=vollibrespot#70d71ae8dcc8cf92b52a90ad4fd23864c573edd2" +source = "git+https://github.com/ashthespy/librespot?branch=vollibrespot#79125a5c483d0318f2498d5ddb6d701b85f375ef" dependencies = [ "aes 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "base64 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -716,7 +686,6 @@ dependencies = [ "pbkdf2 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "protobuf 2.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.23 (registry+https://github.com/rust-lang/crates.io-index)", - "rpassword 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", @@ -733,7 +702,7 @@ dependencies = [ [[package]] name = "librespot-metadata" version = "0.1.0" -source = "git+https://github.com/ashthespy/librespot?branch=vollibrespot#70d71ae8dcc8cf92b52a90ad4fd23864c573edd2" +source = "git+https://github.com/ashthespy/librespot?branch=vollibrespot#79125a5c483d0318f2498d5ddb6d701b85f375ef" dependencies = [ "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", @@ -746,7 +715,7 @@ dependencies = [ [[package]] name = "librespot-playback" version = "0.1.0" -source = "git+https://github.com/ashthespy/librespot?branch=vollibrespot#70d71ae8dcc8cf92b52a90ad4fd23864c573edd2" +source = "git+https://github.com/ashthespy/librespot?branch=vollibrespot#79125a5c483d0318f2498d5ddb6d701b85f375ef" dependencies = [ "alsa 0.2.0 (git+https://github.com/diwic/alsa-rs.git)", "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -760,7 +729,7 @@ dependencies = [ [[package]] name = "librespot-protocol" version = "0.1.0" -source = "git+https://github.com/ashthespy/librespot?branch=vollibrespot#70d71ae8dcc8cf92b52a90ad4fd23864c573edd2" +source = "git+https://github.com/ashthespy/librespot?branch=vollibrespot#79125a5c483d0318f2498d5ddb6d701b85f375ef" dependencies = [ "protobuf 2.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "protoc-rust 2.0.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -914,7 +883,7 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "cc 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.32 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1270,27 +1239,6 @@ dependencies = [ "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "rpassword" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", - "termios 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "rpassword" -version = "3.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "rustc-serialize" version = "0.3.24" @@ -1513,14 +1461,6 @@ dependencies = [ "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "termios" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "thread_local" version = "0.3.6" @@ -1672,20 +1612,6 @@ dependencies = [ "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "tokio-signal" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", - "mio-uds 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-core 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "tokio-signal" version = "0.2.7" @@ -1905,7 +1831,6 @@ dependencies = [ "hyper 0.12.25 (registry+https://github.com/rust-lang/crates.io-index)", "librespot 0.1.0 (git+https://github.com/ashthespy/librespot?branch=vollibrespot)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "rpassword 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2021,7 +1946,7 @@ dependencies = [ "checksum byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a019b10a2a7cdeb292db131fc8113e57ea2a908f6e7894b0c3c671893b65dbeb" "checksum bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)" = "206fdffcfa2df7cbe15601ef46c813fce0965eb3286db6b56c583b814b51c81c" "checksum c_linked_list 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4964518bd3b4a8190e832886cdc0da9794f12e8e6c1613a9e90ff331c4c8724b" -"checksum cc 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)" = "c9ce8bb087aacff865633f0bd5aeaed910fe2fe55b55f4739527f2e023a2e53d" +"checksum cc 1.0.32 (registry+https://github.com/rust-lang/crates.io-index)" = "ad0daef304fa0b4238f5f7ed7178774b43b06f6a9b6509f6642bef4ff1f7b9b2" "checksum cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "11d43355396e872eefb45ce6342e4374ed7bc2b3a502d1b28e36d6e23c05d1f4" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" "checksum crossbeam-deque 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b18cd2e169ad86297e6bc0ad9aa679aee9daa4f19e8163860faf7c164e4f5a71" @@ -2032,7 +1957,6 @@ dependencies = [ "checksum ctr 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "022cd691704491df67d25d006fe8eca083098253c4d43516c2206479c58c6736" "checksum digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "05f47366984d3ad862010e22c7ce81a7dbcaebbdfb37241a620f8b6596ee135c" "checksum dns-parser 0.3.2 (git+https://github.com/plietar/dns-parser)" = "" -"checksum env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)" = "15b0a4d2e39f8420210be8b27eeda28029729e2fd4291019455016c348240c38" "checksum env_logger 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b61fa891024a945da30a9581546e8cfaf5602c7b3f4c137a2805cf388f92075a" "checksum error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff511d5dc435d703f4971bc399647c9bc38e20cb41452e3b9feb4765419ed3f3" "checksum extprim 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "054bc2552b3f66fa8097e29e47255bfff583c08e737a67cbbb54b817ddaa5206" @@ -2132,8 +2056,6 @@ dependencies = [ "checksum regex-syntax 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "8c2f35eedad5295fdf00a63d7d4b238135723f92b434ec06774dad15c7ab0861" "checksum relay 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1576e382688d7e9deecea24417e350d3062d97e32e45d70b1cde65994ff1489a" "checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5" -"checksum rpassword 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ec4bdede957362ec6fdd550f7e79c6d14cad2bc26b2d062786234c6ee0cb27bb" -"checksum rpassword 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c75fff05ca18f2f4f81c10770f5d88c8176d03d4090ba6bc71bb18cc7de5a483" "checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda" "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" "checksum ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7" @@ -2164,7 +2086,6 @@ dependencies = [ "checksum tempfile 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "11ce2fe9db64b842314052e2421ac61a73ce41b898dc8e3750398b219c5fc1e0" "checksum termcolor 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4096add70612622289f2fdcdbd5086dc81c1e2675e6ae58d6c4f62a16c6d7f2f" "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" -"checksum termios 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d5d9cf598a6d7ce700a4e6a9199da127e6819a61e64b68609683cc9a01b5683a" "checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" "checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f" "checksum tokio 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)" = "65641e515a437b308ab131a82ce3042ff9795bef5d6c5a9be4eb24195c417fd9" @@ -2177,7 +2098,6 @@ dependencies = [ "checksum tokio-proto 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8fbb47ae81353c63c487030659494b295f6cb6576242f907f203473b191b0389" "checksum tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "6af16bfac7e112bea8b0442542161bfc41cbfa4466b580bdda7d18cb88b911ce" "checksum tokio-service 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "24da22d077e0f15f55162bdbdc661228c1581892f52074fb242678d015b45162" -"checksum tokio-signal 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e8f46863230f9a05cf52d173721ec391b9c5782a2465f593029922b8782b9ffe" "checksum tokio-signal 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "dd6dc5276ea05ce379a16de90083ec80836440d5ef8a6a39545a3207373b8296" "checksum tokio-sync 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "fda385df506bf7546e70872767f71e81640f1f251bdf2fd8eb81a0eaec5fe022" "checksum tokio-tcp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1d14b10654be682ac43efee27401d792507e30fd8d26389e1da3b185de2e4119" diff --git a/Cargo.toml b/Cargo.toml index 09c00ed..c2297e1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,6 @@ futures = "0.1.25" getopts = "0.2.18" hyper = "0.12.25" log = "0.4.6" -rpassword = "3.0.0" tokio-core = "0.1.17" tokio-io = "0.1.12" tokio-signal = "0.2.7" diff --git a/src/main.rs b/src/main.rs index b752b8b..b7f76aa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,6 @@ extern crate getopts; extern crate librespot; #[macro_use] extern crate log; -extern crate rpassword; extern crate tokio_core; extern crate tokio_io; extern crate tokio_signal; @@ -20,7 +19,7 @@ use env_logger::{fmt, Builder}; use futures::{Async, Future, Poll, Stream}; use sha1::{Digest, Sha1}; use std::env; -use std::io::{self, stderr, Write}; +use std::io::{self, Write}; use std::mem; use std::path::PathBuf; use std::process::exit; @@ -31,7 +30,7 @@ use tokio_core::reactor::{Core, Handle}; use tokio_io::IoStream; use url::Url; -use librespot::core::authentication::{get_credentials, Credentials}; +use librespot::core::authentication::Credentials; use librespot::core::cache::Cache; use librespot::core::config::{ConnectConfig, DeviceType, SessionConfig}; use librespot::core::session::Session; @@ -307,27 +306,20 @@ fn setup(args: &[String]) -> Setup { .unwrap_or(0); let name = matches.opt_str("name").unwrap(); - let use_audio_cache = !matches.opt_present("disable-audio-cache"); - - let cache = matches - .opt_str("c") - .map(|cache_location| Cache::new(PathBuf::from(cache_location), use_audio_cache)); let credentials = { + let username = matches.opt_str("username"); + let password = matches.opt_str("password"); let cached_credentials = cache.as_ref().and_then(Cache::credentials); - let password = |username: &String| -> String { - write!(stderr(), "Password for {}: ", username).unwrap(); - stderr().flush().unwrap(); - rpassword::read_password().unwrap() - }; + match (username, password, cached_credentials) { + (Some(username), Some(password), _) => Some(Credentials::with_password(username, password)), - get_credentials( - matches.opt_str("username"), - matches.opt_str("password"), - cached_credentials, - password, - ) + (Some(ref username), _, Some(ref credentials)) if *username == credentials.username => { + Some(credentials.clone()) + } + (None, _, None) | _ => None, + } }; let session_config = {