Skip to content

Commit

Permalink
use GITHUB_TOKEN enviroment var for authorization on github api requests
Browse files Browse the repository at this point in the history
  • Loading branch information
matcool committed Aug 7, 2023
1 parent a691489 commit 6423806
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "geode"
version = "2.4.3"
version = "2.4.4"
authors = ["HJfod <dreadrollmusic@gmail.com>", "Camila314 <ilaca314@gmail.com>"]
edition = "2021"
build = "build.rs"
Expand Down
4 changes: 3 additions & 1 deletion src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::{done, info, warn, fatal, NiceUnwrap};
use sha3::{Digest, Sha3_256};
use serde::{Serialize, Deserialize};
use serde_json::json;
use reqwest::header::{USER_AGENT, AUTHORIZATION};
use std::collections::HashSet;
use std::fs;
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -68,7 +69,8 @@ pub fn update_index(config: &Config) {
let response = client.get("https://api.github.com/repos/geode-sdk/mods/commits/main")
.header("Accept", "application/vnd.github.sha")
.header("If-None-Match", format!("\"{}\"", current_sha))
.header("User-Agent", "GeodeCli")
.header(USER_AGENT, "GeodeCli")
.header(AUTHORIZATION, std::env::var("GITHUB_TOKEN").map_or("".into(), |token| format!("Bearer {token}")))
.send()
.nice_unwrap("Unable to fetch index version");

Expand Down
17 changes: 7 additions & 10 deletions src/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::config::Config;
use crate::util::logging::ask_confirm;
use git2::build::RepoBuilder;
use git2::{FetchOptions, RemoteCallbacks, Repository, SubmoduleUpdateOptions};
use reqwest::header::{HeaderMap, HeaderValue, USER_AGENT};
use reqwest::header::{USER_AGENT, AUTHORIZATION};
use semver::{Version, Prerelease};
use serde::Deserialize;
use std::fs;
Expand Down Expand Up @@ -399,17 +399,14 @@ fn install_binaries(config: &mut Config) {
stripped_ver.pre = Prerelease::EMPTY;
target_dir = Config::sdk_path().join(format!("bin/{}", stripped_ver));
}
let url = format!(
"https://api.github.com/repos/geode-sdk/geode/releases/tags/{}",
release_tag
);

let mut headers = HeaderMap::new();
headers.insert(USER_AGENT, HeaderValue::from_static("github_api/1.0"));

let res = reqwest::blocking::Client::new()
.get(&url)
.headers(headers)
.get(&format!(
"https://api.github.com/repos/geode-sdk/geode/releases/tags/{}",
release_tag
))
.header(USER_AGENT, "github_api/1.0")
.header(AUTHORIZATION, std::env::var("GITHUB_TOKEN").map_or("".into(), |token| format!("Bearer {token}")))
.send()
.nice_unwrap("Unable to get download info from GitHub")
.json::<GithubReleaseResponse>()
Expand Down

0 comments on commit 6423806

Please sign in to comment.