Skip to content

Commit 584ab21

Browse files
authored
Add github PAT auth (#24)
1 parent 412877e commit 584ab21

File tree

4 files changed

+115
-5
lines changed

4 files changed

+115
-5
lines changed

Cargo.lock

+90-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

paws_install/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ edition = "2021"
88
[dependencies]
99
envtestkit = "1.1.2"
1010
minreq = { version = "2.11.1", features = ["rustls", "rustls-native-certs", "rustls-webpki", "https-rustls"] }
11+
rpassword = "7.3.1"
1112
zip = "0.6.6"
1213

1314
[dev-dependencies]

paws_install/src/lib.rs

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use rpassword::read_password;
12
use std::{
23
env,
34
ffi::OsStr,
@@ -74,7 +75,25 @@ pub fn install_from_github(
7475
let uri = format!("https://github.com/{}/archive/{}.zip", repo_spec, branch);
7576

7677
println!("Getting repo at {}...", uri);
77-
let response = minreq::get(uri).send()?;
78+
let mut response = minreq::get(&uri).send().unwrap();
79+
80+
if response.status_code == 404 {
81+
println!("Seems like it's not a public Github repository...");
82+
print!("Github Access Token: ");
83+
std::io::stdout().flush().unwrap();
84+
let mut request = minreq::get(&uri);
85+
let token = read_password();
86+
if let Ok(token) = token {
87+
request = request.with_header("Authorization", format!("token {}", token));
88+
}
89+
response = request.send().unwrap();
90+
}
91+
92+
if response.status_code == 404 {
93+
println!("Access token is invalid or repository does not exist");
94+
return Ok(());
95+
}
96+
7897
let temp_file_path = "./.tmp.zip";
7998

8099
std::fs::remove_file(temp_file_path).ok();

src/main.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ pub enum Command {
3030
name: String,
3131
},
3232
Install {
33-
name: String,
33+
github_path: String,
34+
#[arg(short, long, default_value = "master")]
3435
branch: String,
36+
#[arg(short, long)]
3537
save_as: Option<String>,
3638
},
3739
}
@@ -53,7 +55,7 @@ fn main() {
5355
start_main_loop(config);
5456
},
5557
Command::List => list_plugins().unwrap(),
56-
Command::Install { name, branch, save_as } => install_from_github(&name, &branch, save_as).unwrap(),
58+
Command::Install { github_path, branch, save_as } => install_from_github(&github_path, &branch, save_as).unwrap(),
5759
Command::Uninstall { name } => remove_plugin(name).unwrap(),
5860
}
5961
}

0 commit comments

Comments
 (0)