Skip to content

Commit 6423806

Browse files
committed
use GITHUB_TOKEN enviroment var for authorization on github api requests
1 parent a691489 commit 6423806

File tree

4 files changed

+12
-13
lines changed

4 files changed

+12
-13
lines changed

Cargo.lock

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

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "geode"
3-
version = "2.4.3"
3+
version = "2.4.4"
44
authors = ["HJfod <[email protected]>", "Camila314 <[email protected]>"]
55
edition = "2021"
66
build = "build.rs"

src/index.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::{done, info, warn, fatal, NiceUnwrap};
99
use sha3::{Digest, Sha3_256};
1010
use serde::{Serialize, Deserialize};
1111
use serde_json::json;
12+
use reqwest::header::{USER_AGENT, AUTHORIZATION};
1213
use std::collections::HashSet;
1314
use std::fs;
1415
use std::path::{Path, PathBuf};
@@ -68,7 +69,8 @@ pub fn update_index(config: &Config) {
6869
let response = client.get("https://api.github.com/repos/geode-sdk/mods/commits/main")
6970
.header("Accept", "application/vnd.github.sha")
7071
.header("If-None-Match", format!("\"{}\"", current_sha))
71-
.header("User-Agent", "GeodeCli")
72+
.header(USER_AGENT, "GeodeCli")
73+
.header(AUTHORIZATION, std::env::var("GITHUB_TOKEN").map_or("".into(), |token| format!("Bearer {token}")))
7274
.send()
7375
.nice_unwrap("Unable to fetch index version");
7476

src/sdk.rs

+7-10
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::config::Config;
44
use crate::util::logging::ask_confirm;
55
use git2::build::RepoBuilder;
66
use git2::{FetchOptions, RemoteCallbacks, Repository, SubmoduleUpdateOptions};
7-
use reqwest::header::{HeaderMap, HeaderValue, USER_AGENT};
7+
use reqwest::header::{USER_AGENT, AUTHORIZATION};
88
use semver::{Version, Prerelease};
99
use serde::Deserialize;
1010
use std::fs;
@@ -399,17 +399,14 @@ fn install_binaries(config: &mut Config) {
399399
stripped_ver.pre = Prerelease::EMPTY;
400400
target_dir = Config::sdk_path().join(format!("bin/{}", stripped_ver));
401401
}
402-
let url = format!(
403-
"https://api.github.com/repos/geode-sdk/geode/releases/tags/{}",
404-
release_tag
405-
);
406-
407-
let mut headers = HeaderMap::new();
408-
headers.insert(USER_AGENT, HeaderValue::from_static("github_api/1.0"));
409402

410403
let res = reqwest::blocking::Client::new()
411-
.get(&url)
412-
.headers(headers)
404+
.get(&format!(
405+
"https://api.github.com/repos/geode-sdk/geode/releases/tags/{}",
406+
release_tag
407+
))
408+
.header(USER_AGENT, "github_api/1.0")
409+
.header(AUTHORIZATION, std::env::var("GITHUB_TOKEN").map_or("".into(), |token| format!("Bearer {token}")))
413410
.send()
414411
.nice_unwrap("Unable to get download info from GitHub")
415412
.json::<GithubReleaseResponse>()

0 commit comments

Comments
 (0)