feat(curseforge): enable source builds with a default API key
This commit is contained in:
1 parent
ad039cab05
commit
c2e039e412
3 files changed
+38
-4
No files matched your search
+12
-3
@@ -18,10 +18,19 @@ const SHADERS_CLASS_ID: u32 = 6552;
|
||||
const DATA_PACKS_CLASS_ID: u32 = 6945;
|
||||
pub const MODPACKS_CLASS_ID: u32 = 4471;
|
||||
|
||||
// Keys supplied for rmcl must not be reused by forks or rebranded applications
|
||||
const DEFAULT_API_KEY: &str = "$2a$10$j2eThhfsaLOAJIMwP7RbwO4D/Tp2NUE16LNalqguv04T7I5jGu8H2";
|
||||
|
||||
pub fn api_key() -> Option<&'static str> {
|
||||
option_env!("CURSEFORGE_API_KEY")
|
||||
.map(str::trim)
|
||||
.filter(|key| !key.is_empty())
|
||||
select_api_key(option_env!("CURSEFORGE_API_KEY"), DEFAULT_API_KEY)
|
||||
}
|
||||
|
||||
fn select_api_key(
|
||||
build_key: Option<&'static str>,
|
||||
default_key: &'static str,
|
||||
) -> Option<&'static str> {
|
||||
let key = build_key.unwrap_or(default_key).trim();
|
||||
(!key.is_empty()).then_some(key)
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
|
||||
@@ -3,6 +3,19 @@
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn build_key_overrides_the_default_and_empty_values_disable_curseforge() {
|
||||
for (build_key, default_key, expected) in [
|
||||
(None, "", None),
|
||||
(None, " default-key ", Some("default-key")),
|
||||
(Some(" override-key "), "default-key", Some("override-key")),
|
||||
(Some(""), "default-key", None),
|
||||
(Some(" \n\t"), "default-key", None),
|
||||
] {
|
||||
assert_eq!(select_api_key(build_key, default_key), expected);
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test(start_paused = true)]
|
||||
async fn authenticated_requests_retry_transient_failures_with_the_api_key() {
|
||||
use std::sync::Arc;
|
||||
|
||||
Reference in new issue
Block a user