diff --git a/Cargo.lock b/Cargo.lock index 8d981ca..1b14c55 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -44,6 +44,24 @@ dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "crossbeam-channel" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "crossbeam-utils" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "curl-sys" version = "0.4.16" @@ -63,6 +81,11 @@ name = "either" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "fnv" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "fuchsia-zircon" version = "0.3.3" @@ -91,6 +114,27 @@ dependencies = [ "url 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "globset" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "aho-corasick 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", + "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "memchr 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "globwalk" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "ignore 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "walkdir 2.2.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "idna" version = "0.1.5" @@ -101,6 +145,23 @@ dependencies = [ "unicode-normalization 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "ignore" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "globset 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 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)", + "memchr 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "same-file 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "walkdir 2.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "itertools" version = "0.7.8" @@ -366,6 +427,16 @@ dependencies = [ "ucd-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rpassword" +version = "2.1.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.43 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "same-file" version = "1.0.4" @@ -394,9 +465,10 @@ dependencies = [ [[package]] name = "sliderule" -version = "0.1.0" -source = "git+https://github.com/7bindustries/sliderule-rs#f71ac34753b052abb7c1d665fa20ff7262fcb927" +version = "0.2.0" +source = "git+https://github.com/7bindustries/sliderule-rs#4437dbedc8e29d1b5f7243a14fb6ff28ebafd4d7" dependencies = [ + "globwalk 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "liquid 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)", "os_info 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "walkdir 2.2.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -404,15 +476,21 @@ dependencies = [ [[package]] name = "sliderule-cli" -version = "0.1.0" +version = "0.3.0" dependencies = [ "argparse 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "git2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "os_info 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "sliderule 0.1.0 (git+https://github.com/7bindustries/sliderule-rs)", + "rpassword 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "sliderule 0.2.0 (git+https://github.com/7bindustries/sliderule-rs)", "uuid 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "smallvec" +version = "0.6.9" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "syn" version = "0.15.23" @@ -566,12 +644,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "082bb9b28e00d3c9d39cc03e64ce4cea0f1bb9b3fde493f0cbc008472d22bdf4" "checksum chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "45912881121cb26fad7c38c17ba7daa18764771836b34fab7d3fbd93ed633878" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" +"checksum crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "0f0ed1a4de2235cabda8558ff5840bffb97fcb64c97827f354a451307df5f72b" +"checksum crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f8306fcef4a7b563b76b7dd949ca48f52bc1141aa067d2ea09565f3e2652aa5c" "checksum curl-sys 0.4.16 (registry+https://github.com/rust-lang/crates.io-index)" = "ca79238a79fb294be6173b4057c95b22a718c94c4e38475d5faa82b8383f3502" "checksum either 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3be565ca5c557d7f59e7cfcf1844f9e3033650c929c6566f511e8005f205c1d0" +"checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3" "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" "checksum git2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c7339329bfa14a00223244311560d11f8f489b453fb90092af97f267a6090ab0" +"checksum globset 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4743617a7464bbda3c8aec8558ff2f9429047e025771037df561d383337ff865" +"checksum globwalk 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4be0267260c9bb4e278dfb2291de9518a595cb625cf6f5f385c4b7d8d1aa7112" "checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" +"checksum ignore 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ad03ca67dc12474ecd91fdb94d758cbd20cb4e7a78ebe831df26a9b7511e1162" "checksum itertools 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)" = "f58856976b776fedd95533137617a02fb25719f40e7d9b01c7043cd65474f450" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a374c89b9db55895453a74c1e38861d9deec0b01b405a82516e9d5de4820dea1" @@ -602,10 +686,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "c214e91d3ecf43e9a4e41e578973adeb14b474f2bee858742d127af75a0112b1" "checksum regex 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "2069749032ea3ec200ca51e4a31df41759190a88edca0d2d86ee8bedf7073341" "checksum regex-syntax 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "747ba3b235651f6e2f67dfa8bcdcd073ddb7c243cb21c442fc12395dfcac212d" +"checksum rpassword 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d37473170aedbe66ffa3ad3726939ba677d83c646ad4fd99e5b4bc38712f45ec" "checksum same-file 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8f20c4be53a8a1ff4c1f1b2bd14570d2f634628709752f0702ecdd2b3f9a5267" "checksum serde 1.0.84 (registry+https://github.com/rust-lang/crates.io-index)" = "0e732ed5a5592c17d961555e3b552985baf98d50ce418b7b655f31f6ba7eb1b7" "checksum serde_derive 1.0.84 (registry+https://github.com/rust-lang/crates.io-index)" = "b4d6115a3ca25c224e409185325afc16a0d5aaaabc15c42b09587d6f1ba39a5b" -"checksum sliderule 0.1.0 (git+https://github.com/7bindustries/sliderule-rs)" = "" +"checksum sliderule 0.2.0 (git+https://github.com/7bindustries/sliderule-rs)" = "" +"checksum smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c4488ae950c49d403731982257768f48fada354a5203fe81f9bb6f43ca9002be" "checksum syn 0.15.23 (registry+https://github.com/rust-lang/crates.io-index)" = "9545a6a093a3f0bd59adb472700acc08cad3776f860f16a897dfce8c88721cbc" "checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" "checksum time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "d825be0eb33fda1a7e68012d51e9c7f451dc1a69391e7fdc197060bb8c56667b" diff --git a/Cargo.toml b/Cargo.toml index 30f9717..2fddc4a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,14 +1,14 @@ [package] name = "sliderule-cli" -version = "0.1.0" +version = "0.3.0" authors = ["Jeremy Wright "] [dependencies] # sliderule = { path = "../sliderule-rs" } sliderule = { git = "https://github.com/7bindustries/sliderule-rs" } - argparse = "0.2.2" os_info = "1.0.3" +rpassword = "2.1.0" [dev-dependencies] git2 = "0.8" diff --git a/src/main.rs b/src/main.rs index ab3a93b..a6d0735 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,10 +1,12 @@ extern crate argparse; +extern crate rpassword; extern crate sliderule; use argparse::{ArgumentParser, List, Store, StoreTrue}; use sliderule::SROutput; use std::env; use std::io; +use std::io::prelude::*; use std::path::{Path, PathBuf}; fn main() { @@ -20,7 +22,7 @@ fn main() { // Some items for the command line help interface let app_description = "Tool to manage Sliderule projects."; - let cmd_description = "Sliderule command to run: [create | download | upload | add | remove | refactor | licenses ]"; + let cmd_description = "Sliderule command to run: [create | download | upload | add | remove | refactor | licenses | login]"; let args_description = "Arguments to Sliderule commands: create [name], download [all | dependencies | component_url], @@ -200,6 +202,8 @@ fn main() { message = message.trim().to_string(); } + let mut userinfo = (String::new(), String::new()); + // Make sure this project has already been initialized as a repository if !Path::new(".git").exists() && url.is_empty() { println!("This project has not been initialized with a repository yet. Enter a URL of an existing repository to upload this component to:"); @@ -209,9 +213,21 @@ fn main() { .expect("ERROR: Failed to read name or URL from user."); url = url.trim().to_string(); + + // Check to see if there needs to be a username and password set for this + if url.contains("https") { + userinfo = get_https_user_info(); + } + } + + let mut user = None; + let mut pass = None; + if !userinfo.0.is_empty() && !userinfo.1.is_empty() { + user = Some(userinfo.0.trim().to_string()); + pass = Some(userinfo.1.trim().to_string()); } - let output = sliderule::upload_component(&get_cwd(), message, &url); + let output = sliderule::upload_component(&get_cwd(), message, url, user, pass); // Show extra output only when the user requests it if verbose { @@ -327,6 +343,49 @@ fn main() { eprintln!("licenses subcommand not understood: {}", subcommand); std::process::exit(1); } + } else if command == "login" { + // Make sure this project has already been initialized as a repository + if url.is_empty() { + println!( + "Enter a URL of an existing repository to that this component will be uploaded to:" + ); + + io::stdin() + .read_line(&mut url) + .expect("ERROR: Failed to read name or URL from user."); + + url = url.trim().to_string(); + } + + let mut userinfo = (String::new(), String::new()); + + // Check to see if there needs to be a username and password set for this + if url.contains("https") { + userinfo = get_https_user_info(); + } + + let mut user = None; + let mut pass = None; + if !userinfo.0.is_empty() && !userinfo.1.is_empty() { + user = Some(userinfo.0.trim().to_string()); + pass = Some(userinfo.1.trim().to_string()); + } + + // If a URL is not present, it will mess up the git config + if url.is_empty() { + println!("URL cannot be empty when logging into a repository."); + std::process::exit(2); + } + + // Change/add the login information for the user + let output = sliderule::remote_login(&get_cwd(), Some(url), user, pass); + + // Show extra output only when the user requests it + if verbose { + print_stdout(&output); + } else { + println!("Finished setting username and password for remote repository."); + } } // The user has to supply a command, and it needs to be recognized @@ -336,6 +395,28 @@ fn main() { } } +/* + * Prompts the user for an https username and a password, with a warning that doing so is a security concern. + */ +fn get_https_user_info() -> (String, String) { + let mut username = String::new(); + let password: String; + + println!( + "You need to enter a username and password for using an https URL. Please do that now." + ); + println!("WARNING: Using https with sliderule-cli can lead to passwords being stored in plain text. It is better to use ssh."); + print!("User: "); + io::stdout().flush().ok().expect("Could not flush stdout"); + io::stdin() + .read_line(&mut username) + .expect("ERROR: Failed to read username from user"); + + password = rpassword::prompt_password_stdout("Password: ").unwrap(); + + (username, password) +} + /* * Prints all the lines of standard output to standard output. */