From 5a97731c6996847e335daf1fe9a5d265540de3d1 Mon Sep 17 00:00:00 2001 From: alyx Date: Wed, 3 Apr 2024 11:57:23 -0400 Subject: whitelist -> allowlist --- src/cache/user.rs | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'src/cache') 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>; type UserCache = Cache>; #[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 = crate::http::lazy(); -static WHITELIST: LazyLock = LazyLock::new(|| { +static ALLOWLIST: LazyLock = 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, (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) } } } } -- cgit v1.2.3-70-g09d2