Skip to content

Commit

Permalink
v0.1.1: Add --user option
Browse files Browse the repository at this point in the history
  • Loading branch information
limitedeternity committed Aug 8, 2020
1 parent eae7515 commit 1792745
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 182 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/target

.DS_Store
186 changes: 15 additions & 171 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "squidclient"
version = "0.1.0"
version = "0.1.1"
authors = ["Marise Hayashi <[email protected]>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = "3.0.0-beta.1"
clap = "2.33.0"
base64 = "0.12.3"
27 changes: 18 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,28 @@ fn main() {
.author(crate_authors!())
.about("Executes Squid proxy cachemgr commands")
.arg(Arg::with_name("command")
.about("A command to execute")
.help("A command to execute (e.g: \"menu\")")
.required(true))
.arg(Arg::with_name("host")
.about("Squid proxy address")
.short('h')
.help("Squid proxy IP address")
.short("h")
.long("host")
.required(true)
.takes_value(true))
.arg(Arg::with_name("port")
.about("Squid proxy port")
.short('p')
.help("Squid proxy port")
.short("p")
.long("port")
.default_value("3128")
.takes_value(true))
.arg(Arg::with_name("user")
.help("Squid proxy cachemgr username")
.short("u")
.long("user")
.takes_value(true))
.arg(Arg::with_name("with_password")
.about("Squid proxy cachemgr password")
.short('w')
.help("Squid proxy cachemgr password")
.short("w")
.long("with_password")
.takes_value(true))
.get_matches();
Expand All @@ -43,8 +48,12 @@ fn main() {
let host = format!("Host: {}\r\n", matches.value_of("host").unwrap());
let accept = "Accept: */*\r\n";

let auth = if matches.is_present("with_password") {
format!("Authorization: Basic {}\r\n", encode([":", matches.value_of("with_password").unwrap()].concat()))
let auth = if matches.is_present("user") || matches.is_present("with_password") {
format!("Authorization: Basic {}\r\n", encode([
if let Some(user) = matches.value_of("user") { user } else { "" },
":",
if let Some(password) = matches.value_of("with_password") { password } else { "" }
].concat()))
} else {
"\r\n".to_string()
};
Expand Down

0 comments on commit 1792745

Please sign in to comment.