aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cache/user.rs36
-rw-r--r--src/config.rs15
2 files changed, 26 insertions, 25 deletions
diff --git a/src/cache/user.rs b/src/cache/user.rs
index f12d852..253773c 100644
--- a/src/cache/user.rs
+++ b/src/cache/user.rs
@@ -15,9 +15,9 @@ type UserGetter = CacheGetter<Arc<(User, Track, TrackStub)>>;
type UserCache = Cache<Arc<(User, Track, TrackStub)>>;
#[derive(Debug)]
-enum Whitelist {
+enum Allowlist {
Exclusive{cache: UserCache},
- Open{default_cache: UserCache, whitelist_cache: UserCache}
+ Open{default_cache: UserCache, allowlist_cache: UserCache}
}
fn user_getter(username: &String) -> UserFuture {
@@ -63,40 +63,40 @@ fn user_getter(username: &String) -> UserFuture {
static HTTP: LazyLock<Client> = crate::http::lazy();
-static WHITELIST: LazyLock<Whitelist> = LazyLock::new(|| {
+static ALLOWLIST: LazyLock<Allowlist> = LazyLock::new(|| {
let default_cache = Arc::new(RwLock::new(AsyncCache::new(CONFIG.default_refresh, user_getter as UserGetter)));
- let whitelist_cache = Arc::new(RwLock::new(AsyncCache::new(CONFIG.whitelist_refresh, user_getter as UserGetter)));
- match CONFIG.whitelist_mode.as_str() {
+ let allowlist_cache = Arc::new(RwLock::new(AsyncCache::new(CONFIG.allowlist_refresh, user_getter as UserGetter)));
+ match CONFIG.allowlist_mode.as_str() {
"open" => {
- Whitelist::Open{default_cache, whitelist_cache}
+ Allowlist::Open{default_cache, allowlist_cache}
},
"exclusive" => {
- if CONFIG.whitelist.is_empty() {
- panic!("Exclusive mode set with empty whitelist, cannot serve any requests!");
+ if CONFIG.allowlist.is_empty() {
+ panic!("Exclusive mode set with empty allowlist, cannot serve any requests!");
}
- Whitelist::Exclusive{cache: whitelist_cache}
+ Allowlist::Exclusive{cache: allowlist_cache}
},
m => {
- panic!("Bad whitelist mode: `{m}`");
+ panic!("Bad allowlist mode: `{m}`");
}
}
});
pub async fn get_userinfo(user: &String) -> (Result<Arc<(User, Track, TrackStub)>, (StatusCode, &'static str)>, Duration) {
- match LazyLock::force(&WHITELIST) {
- Whitelist::Open{default_cache, whitelist_cache} => {
- if CONFIG.whitelist.contains(user) {
- (whitelist_cache.write().await.get_owned(user).await, CONFIG.whitelist_refresh)
+ match LazyLock::force(&ALLOWLIST) {
+ Allowlist::Open{default_cache, allowlist_cache} => {
+ if CONFIG.allowlist.contains(user) {
+ (allowlist_cache.write().await.get_owned(user).await, CONFIG.allowlist_refresh)
}
else {
(default_cache.write().await.get_owned(user).await, CONFIG.default_refresh)
}
},
- Whitelist::Exclusive{cache} => {
- if CONFIG.whitelist.contains(user) {
- (cache.write().await.get_owned(user).await, CONFIG.whitelist_refresh)
+ Allowlist::Exclusive{cache} => {
+ if CONFIG.allowlist.contains(user) {
+ (cache.write().await.get_owned(user).await, CONFIG.allowlist_refresh)
}
- else { (Err((StatusCode::FORBIDDEN, "User not in whitelist!")), CONFIG.default_refresh) }
+ else { (Err((StatusCode::FORBIDDEN, "User not in allowlist!")), CONFIG.default_refresh) }
}
}
}
diff --git a/src/config.rs b/src/config.rs
index bc24b83..1a192b2 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -24,10 +24,10 @@ pub struct Config {
pub(crate) theme_ext: Arc<str>,
pub(crate) theme_debug: bool,
- pub(crate) whitelist: BTreeSet<String>,
- pub(crate) whitelist_mode: String,
+ pub(crate) allowlist: BTreeSet<String>,
+ pub(crate) allowlist_mode: String,
pub(crate) default_refresh: Duration,
- pub(crate) whitelist_refresh: Duration,
+ pub(crate) allowlist_refresh: Duration,
}
impl Config {
@@ -35,6 +35,7 @@ impl Config {
let duration_from_var = |v: &str, d: u64| -> Duration {var(v).map(|r| ds::parse(&r).expect("bad duration string")).unwrap_or_else(|_| Duration::from_secs(d))};
let default_refresh = duration_from_var("LFME_DEFAULT_REFRESH", 300);
let whitelist_refresh = duration_from_var("LFME_WHITELIST_REFRESH", 60);
+ let allowlist_refresh = if whitelist_refresh == Duration::from_secs(60) { duration_from_var("LFME_ALLOWLIST_REFRESH", 60) } else { whitelist_refresh };
Arc::new(Config {
lastfm_api_key: var("LFME_LASTFM_API_KEY").expect("last.fm API key must be set").into(),
google_api_key: var("LFME_GOOGLE_API_KEY").map(Into::into).ok(),
@@ -47,10 +48,10 @@ impl Config {
theme_ext: var("LFME_THEME_EXT").unwrap_or_else(|_| ".hbs".into()).into(),
theme_debug: var("LFME_THEME_DEV").map(|h| &h == "1").unwrap_or(false),
- whitelist: var("LFME_WHITELIST").ok().map(|w| w.split(',').map(|s| s.trim().to_string()).collect()).unwrap_or_default(),
- whitelist_mode: var("LFME_WHITELIST_MODE").map(|m| m.to_ascii_lowercase()).unwrap_or_else(|_| "open".into()),
- default_refresh: default_refresh + Duration::from_secs(1),
- whitelist_refresh: whitelist_refresh + Duration::from_secs(1)
+ allowlist: var("LFME_WHITELIST").or_else(|_| var("LFME_ALLOWLIST")).ok().map(|w| w.split(',').map(|s| s.trim().to_string()).collect()).unwrap_or_default(),
+ allowlist_mode: var("LFME_WHITELIST_MODE").or_else(|_| var("LFME_ALLOWLIST_MODE")).map(|m| m.to_ascii_lowercase()).unwrap_or_else(|_| "open".into()),
+ default_refresh: default_refresh,
+ allowlist_refresh: allowlist_refresh
})
}