1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
pub mod config;
pub mod error;
pub mod model;
pub mod module;
pub mod service;
pub mod utils;
pub mod web;

use crate::error::LightSpeedError;
use crate::service::auth::InMemoryRolesProvider;
use log::info;
use std::sync::Arc;

#[derive(Clone)]
pub struct CoreModule {
    pub auth: Arc<service::auth::AuthService<InMemoryRolesProvider>>,
    pub jwt: Arc<service::jwt::JwtService>,
}

impl CoreModule {
    pub fn new(config: config::CoreConfig) -> Result<CoreModule, LightSpeedError> {
        println!("Creating CoreModule");
        info!("Creating CoreModule");

        let jwt = Arc::new(service::jwt::JwtService::new(&config.jwt)?);
        let auth = Arc::new(service::auth::AuthService::new(InMemoryRolesProvider::new(
            Arc::new(vec![]),
        )));
        Ok(CoreModule { jwt, auth })
    }
}

#[async_trait::async_trait]
impl module::Module for CoreModule {
    async fn start(&mut self) -> Result<(), LightSpeedError> {
        info!("Starting CoreModule");
        Ok(())
    }
}