fix: 🛂 properly handle missing api token entry

This commit is contained in:
daimond113 2024-03-04 22:01:02 +01:00
parent 60760d07c4
commit 7cb08e7dcd
No known key found for this signature in database
GPG key ID: 3A8ECE51328B513C

View file

@ -1,3 +1,4 @@
use anyhow::bail;
use std::{ use std::{
fs::{create_dir_all, read}, fs::{create_dir_all, read},
hash::{DefaultHasher, Hash, Hasher}, hash::{DefaultHasher, Hash, Hasher},
@ -184,12 +185,20 @@ fn main() -> anyhow::Result<()> {
let mut header_map = reqwest::header::HeaderMap::new(); let mut header_map = reqwest::header::HeaderMap::new();
header_map.insert(ACCEPT, "application/json".parse()?); header_map.insert(ACCEPT, "application/json".parse()?);
header_map.insert(
AUTHORIZATION,
format!("Bearer {}", api_token_entry.get_password()?).parse()?,
);
header_map.insert("X-GitHub-Api-Version", "2022-11-28".parse()?); header_map.insert("X-GitHub-Api-Version", "2022-11-28".parse()?);
match api_token_entry.get_password() {
Ok(api_token) => {
header_map.insert(AUTHORIZATION, format!("Bearer {api_token}").parse()?);
}
Err(err) => match err {
keyring::Error::NoEntry => {}
_ => {
bail!("error getting api token from keyring: {err}")
}
},
};
let reqwest_client = reqwest::blocking::Client::builder() let reqwest_client = reqwest::blocking::Client::builder()
.user_agent(concat!( .user_agent(concat!(
env!("CARGO_PKG_NAME"), env!("CARGO_PKG_NAME"),