From ff85fb657e6a7b961af463a248f4d199a1a7a043 Mon Sep 17 00:00:00 2001 From: Brendan Golden Date: Mon, 11 Mar 2024 20:56:14 +0000 Subject: [PATCH 1/3] feat: new env var for clubs and socs --- flake.nix | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/flake.nix b/flake.nix index f8a0c10..e62d839 100644 --- a/flake.nix +++ b/flake.nix @@ -54,12 +54,13 @@ SSH_ROOT = "skynet_old"; # special categories of users - USERS_ADMIN = lib.strings.concatStringsSep "," cfg.users.admin; - USERS_COMMITTEE = lib.strings.concatStringsSep "," cfg.users.committee; - USERS_TRAINEE = lib.strings.concatStringsSep "," cfg.users.trainee; - USERS_LIFETIME = lib.strings.concatStringsSep "," cfg.users.lifetime; - USERS_BANNED = lib.strings.concatStringsSep "," cfg.users.banned; - USERS_RESTRICTED = lib.strings.concatStringsSep "," cfg.users.restricted; + USERS_ADMIN = lib.strings.concatStringsSep "," cfg.users.admin; + USERS_COMMITTEE = lib.strings.concatStringsSep "," cfg.users.committee; + USERS_TRAINEE = lib.strings.concatStringsSep "," cfg.users.trainee; + USERS_LIFETIME = lib.strings.concatStringsSep "," cfg.users.lifetime; + USERS_BANNED = lib.strings.concatStringsSep "," cfg.users.banned; + USERS_RESTRICTED = lib.strings.concatStringsSep "," cfg.users.restricted; + USERS_CLUBS_SOCIETIES = lib.strings.concatStringsSep "," cfg.users.clubs_societies; }; service_name = script: lib.strings.sanitizeDerivationName("${cfg.user}@${script}"); @@ -162,6 +163,11 @@ default = []; description = "array of restricted user accounts"; }; + clubs_societies = mkOption rec { + type = types.listOf types.str; + default = []; + description = "array of accounts for Clubs and Societies"; + }; }; host_port = mkOption rec { -- 2.46.1 From f5ab63b59e721c3a1dc38f24c4bf01148c13dbba Mon Sep 17 00:00:00 2001 From: Brendan Golden Date: Mon, 11 Mar 2024 21:14:45 +0000 Subject: [PATCH 2/3] feat: apparently this is all taht is needed to enable C&S Closes #26 --- src/bin/update_groups.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/bin/update_groups.rs b/src/bin/update_groups.rs index 523090b..2009998 100644 --- a/src/bin/update_groups.rs +++ b/src/bin/update_groups.rs @@ -26,6 +26,12 @@ async fn update(config: &Config) -> tide::Result<()> { } } + if let Ok(x) = env::var("USERS_CLUBS_SOCIETIES") { + for user in x.split(',').collect::>() { + users_tmp.insert(user.to_string()); + } + } + // pull from wolves csv for user in from_csv(&db).await.unwrap_or_default() { users_tmp.insert(user); -- 2.46.1 From 0297c04259ff22ccfef5a89ef9580c24a4a068c9 Mon Sep 17 00:00:00 2001 From: Brendan Golden Date: Mon, 11 Mar 2024 21:17:45 +0000 Subject: [PATCH 3/3] fix: havent used the csv import in quite a while, would be good to remove it now. --- src/bin/update_groups.rs | 63 ++-------------------------------------- 1 file changed, 2 insertions(+), 61 deletions(-) diff --git a/src/bin/update_groups.rs b/src/bin/update_groups.rs index 2009998..6ae177c 100644 --- a/src/bin/update_groups.rs +++ b/src/bin/update_groups.rs @@ -1,6 +1,6 @@ -use skynet_ldap_backend::{db_init, get_config, get_now_iso, get_wolves, update_group, Accounts, Config}; +use skynet_ldap_backend::{db_init, get_config, update_group, Accounts, Config}; use sqlx::{Pool, Sqlite}; -use std::{collections::HashSet, env, error::Error}; +use std::{collections::HashSet, env}; #[async_std::main] async fn main() -> tide::Result<()> { @@ -32,11 +32,6 @@ async fn update(config: &Config) -> tide::Result<()> { } } - // pull from wolves csv - for user in from_csv(&db).await.unwrap_or_default() { - users_tmp.insert(user); - } - get_from_env(&mut users_tmp, &mut admins_tmp, "USERS_ADMIN"); get_from_env(&mut users_tmp, &mut committee_tmp, "USERS_COMMITTEE"); get_from_env(&mut users_tmp, &mut trainees_tmp, "USERS_TRAINEE"); @@ -73,60 +68,6 @@ fn get_from_env(users: &mut HashSet, other: &mut HashSet, key: & } } -async fn from_csv(db: &Pool) -> Result, Box> { - let mut uids = HashSet::new(); - - for record in get_wolves(db).await { - // only import users if it is actually active. - if record.expiry < get_now_iso(true) { - continue; - } - if let Some(uid) = account_mail_get_uid(db, &record.email).await { - uids.insert(uid); - } else if let Some(id_student) = record.id_student { - if let Some(uid) = account_id_get_uid(db, &id_student).await { - uids.insert(uid); - } - } - } - - Ok(uids) -} - -async fn account_mail_get_uid(db: &Pool, mail: &str) -> Option { - match sqlx::query_as::<_, Accounts>( - r#" - SELECT * - FROM accounts - WHERE mail == ? - "#, - ) - .bind(mail) - .fetch_one(db) - .await - { - Ok(res) => Some(res.user.to_owned()), - Err(_) => None, - } -} - -async fn account_id_get_uid(db: &Pool, id: &str) -> Option { - match sqlx::query_as::<_, Accounts>( - r#" - SELECT * - FROM accounts - WHERE student_id == ? - "#, - ) - .bind(id) - .fetch_one(db) - .await - { - Ok(res) => Some(res.student_id.to_owned()), - Err(_) => None, - } -} - struct AccountsSecure { users: Vec, admins: Vec, -- 2.46.1