Loads clients list only once #106

Merged
pierre merged 2 commits from unique-clients-load into master 2023-04-17 16:49:21 +00:00
3 changed files with 19 additions and 10 deletions
Showing only changes of commit a367425952 - Show all commits

View File

@ -1,4 +1,5 @@
use std::ops::Deref; use std::ops::Deref;
use std::sync::Arc;
use actix::Addr; use actix::Addr;
use actix_web::{web, HttpResponse, Responder}; use actix_web::{web, HttpResponse, Responder};
@ -36,7 +37,10 @@ struct EditUserTemplate {
clients: Vec<Client>, clients: Vec<Client>,
} }
pub async fn clients_route(user: CurrentUser, clients: web::Data<ClientManager>) -> impl Responder { pub async fn clients_route(
user: CurrentUser,
clients: web::Data<Arc<ClientManager>>,
) -> impl Responder {
HttpResponse::Ok().body( HttpResponse::Ok().body(
ClientsListTemplate { ClientsListTemplate {
_p: BaseSettingsPage::get("Clients list", &user, None, None), _p: BaseSettingsPage::get("Clients list", &user, None, None),
@ -233,7 +237,10 @@ pub async fn users_route(
) )
} }
pub async fn create_user(admin: CurrentUser, clients: web::Data<ClientManager>) -> impl Responder { pub async fn create_user(
admin: CurrentUser,
clients: web::Data<Arc<ClientManager>>,
) -> impl Responder {
let user = User { let user = User {
authorized_clients: Some( authorized_clients: Some(
clients clients
@ -263,7 +270,7 @@ pub struct EditUserQuery {
pub async fn edit_user( pub async fn edit_user(
admin: CurrentUser, admin: CurrentUser,
clients: web::Data<ClientManager>, clients: web::Data<Arc<ClientManager>>,
users: web::Data<Addr<UsersActor>>, users: web::Data<Addr<UsersActor>>,
query: web::Query<EditUserQuery>, query: web::Query<EditUserQuery>,
) -> impl Responder { ) -> impl Responder {

View File

@ -1,4 +1,5 @@
use std::fmt::Debug; use std::fmt::Debug;
use std::sync::Arc;
use actix::Addr; use actix::Addr;
use actix_identity::Identity; use actix_identity::Identity;
@ -113,7 +114,7 @@ pub async fn authorize(
user: CurrentUser, user: CurrentUser,
id: Identity, id: Identity,
query: web::Query<AuthorizeQuery>, query: web::Query<AuthorizeQuery>,
clients: web::Data<ClientManager>, clients: web::Data<Arc<ClientManager>>,
sessions: web::Data<Addr<OpenIDSessionsActor>>, sessions: web::Data<Addr<OpenIDSessionsActor>>,
logger: ActionLogger, logger: ActionLogger,
) -> impl Responder { ) -> impl Responder {
@ -267,7 +268,7 @@ pub struct TokenResponse {
pub async fn token( pub async fn token(
req: HttpRequest, req: HttpRequest,
query: web::Form<TokenQuery>, query: web::Form<TokenQuery>,
clients: web::Data<ClientManager>, clients: web::Data<Arc<ClientManager>>,
sessions: web::Data<Addr<OpenIDSessionsActor>>, sessions: web::Data<Addr<OpenIDSessionsActor>>,
users: web::Data<Addr<UsersActor>>, users: web::Data<Addr<UsersActor>>,
jwt_signer: web::Data<JWTSigner>, jwt_signer: web::Data<JWTSigner>,

View File

@ -72,14 +72,15 @@ async fn main() -> std::io::Result<()> {
let jwt_signer = JWTSigner::gen_from_memory().expect("Failed to generate JWKS key"); let jwt_signer = JWTSigner::gen_from_memory().expect("Failed to generate JWKS key");
let webauthn_manager = Arc::new(WebAuthManager::init(config)); let webauthn_manager = Arc::new(WebAuthManager::init(config));
let mut clients =
ClientManager::open_or_create(config.clients_file()).expect("Failed to load clients list!");
clients.apply_environment_variables();
let clients = Arc::new(clients);
log::info!("Server will listen on {}", config.listen_address); log::info!("Server will listen on {}", config.listen_address);
let listen_address = config.listen_address.to_string(); let listen_address = config.listen_address.to_string();
HttpServer::new(move || { HttpServer::new(move || {
let mut clients = ClientManager::open_or_create(config.clients_file())
.expect("Failed to load clients list!");
clients.apply_environment_variables();
let session_mw = SessionMiddleware::builder( let session_mw = SessionMiddleware::builder(
CookieSessionStore::default(), CookieSessionStore::default(),
Key::from(config.token_key.as_bytes()), Key::from(config.token_key.as_bytes()),
@ -99,7 +100,7 @@ async fn main() -> std::io::Result<()> {
.app_data(web::Data::new(users_actor.clone())) .app_data(web::Data::new(users_actor.clone()))
.app_data(web::Data::new(bruteforce_actor.clone())) .app_data(web::Data::new(bruteforce_actor.clone()))
.app_data(web::Data::new(openid_sessions_actor.clone())) .app_data(web::Data::new(openid_sessions_actor.clone()))
.app_data(web::Data::new(clients)) .app_data(web::Data::new(clients.clone()))
.app_data(web::Data::new(jwt_signer.clone())) .app_data(web::Data::new(jwt_signer.clone()))
.app_data(web::Data::new(webauthn_manager.clone())) .app_data(web::Data::new(webauthn_manager.clone()))
.wrap( .wrap(