mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-05-01 17:50:03 +00:00
Improve use of github token (#1769)
* Add new dep zeroize * Use Zeroizing to avoid leaking the token * Optimize gh-auth-token Spawn it as a task, and only await it when using GhApiClient * Fix binstalk-git-repo-api unit tests
This commit is contained in:
parent
e3c8c40806
commit
fff6aa8122
13 changed files with 128 additions and 54 deletions
|
@ -1,9 +1,9 @@
|
|||
use std::{env, fs, path::PathBuf};
|
||||
|
||||
use compact_str::CompactString;
|
||||
use dirs::home_dir;
|
||||
use zeroize::Zeroizing;
|
||||
|
||||
pub fn try_from_home() -> Option<CompactString> {
|
||||
pub fn try_from_home() -> Option<Zeroizing<Box<str>>> {
|
||||
if let Some(mut home) = home_dir() {
|
||||
home.push(".git-credentials");
|
||||
if let Some(cred) = from_file(home) {
|
||||
|
@ -23,12 +23,12 @@ pub fn try_from_home() -> Option<CompactString> {
|
|||
None
|
||||
}
|
||||
|
||||
fn from_file(path: PathBuf) -> Option<CompactString> {
|
||||
fs::read_to_string(path)
|
||||
.ok()?
|
||||
fn from_file(path: PathBuf) -> Option<Zeroizing<Box<str>>> {
|
||||
Zeroizing::new(fs::read_to_string(path).ok()?)
|
||||
.lines()
|
||||
.find_map(from_line)
|
||||
.map(CompactString::from)
|
||||
.map(Box::<str>::from)
|
||||
.map(Zeroizing::new)
|
||||
}
|
||||
|
||||
fn from_line(line: &str) -> Option<&str> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue