Skip to main content

futu_gateway_core/bridge/
auth_runtime.rs

1//! Auth/reload runtime boundary for [`super::GatewayBridge`].
2//!
3//! These fields are written across initialization, broker-auth, reload, and
4//! health-refresh paths. The bundle is intentionally a lifecycle boundary only:
5//! behavior stays in the existing phase/reload/account modules.
6
7use std::sync::Arc;
8
9use futu_backend::auth::{self, AuthResult};
10
11use super::{ClientSigRefreshStatus, ReloadRefreshStatus, ReloadState};
12
13#[derive(Clone)]
14pub struct AuthRuntime {
15    auth_result: Option<AuthResult>,
16    commconfig: auth::commconfig::SharedCommConfig,
17    web_site_config: auth::site_config::SharedSiteConfig,
18    broker_auth_route_cache: auth::BrokerAuthRouteCache,
19    reload_state: Option<ReloadState>,
20    auth_refresher: Option<Arc<dyn auth::AuthRefresher>>,
21    client_sig_refresh_status: ClientSigRefreshStatus,
22    last_reload_refresh: Arc<parking_lot::RwLock<ReloadRefreshStatus>>,
23}
24
25impl AuthRuntime {
26    pub fn new() -> Self {
27        Self {
28            auth_result: None,
29            commconfig: Arc::new(arc_swap::ArcSwap::new(Arc::new(
30                auth::commconfig::empty_snapshot(),
31            ))),
32            web_site_config: auth::site_config::empty_shared(),
33            broker_auth_route_cache: auth::BrokerAuthRouteCache::default(),
34            reload_state: None,
35            auth_refresher: None,
36            client_sig_refresh_status: ClientSigRefreshStatus::default(),
37            last_reload_refresh: Arc::new(parking_lot::RwLock::new(ReloadRefreshStatus::default())),
38        }
39    }
40
41    pub fn auth_result(&self) -> Option<AuthResult> {
42        self.auth_result.clone()
43    }
44
45    pub fn set_auth_result(&mut self, auth_result: AuthResult) {
46        self.auth_result = Some(auth_result);
47    }
48
49    pub fn commconfig(&self) -> auth::commconfig::SharedCommConfig {
50        Arc::clone(&self.commconfig)
51    }
52
53    pub fn web_site_config(&self) -> auth::site_config::SharedSiteConfig {
54        Arc::clone(&self.web_site_config)
55    }
56
57    pub fn broker_auth_route_cache(&self) -> auth::BrokerAuthRouteCache {
58        self.broker_auth_route_cache.clone()
59    }
60
61    pub fn reload_state(&self) -> Option<ReloadState> {
62        self.reload_state.clone()
63    }
64
65    pub fn set_reload_state(&mut self, reload_state: ReloadState) {
66        self.reload_state = Some(reload_state);
67    }
68
69    pub fn auth_refresher(&self) -> Option<Arc<dyn auth::AuthRefresher>> {
70        self.auth_refresher.clone()
71    }
72
73    pub fn set_auth_refresher(&mut self, auth_refresher: Arc<dyn auth::AuthRefresher>) {
74        self.auth_refresher = Some(auth_refresher);
75    }
76
77    pub fn client_sig_refresh_status(&self) -> ClientSigRefreshStatus {
78        self.client_sig_refresh_status.clone()
79    }
80
81    pub fn set_client_sig_refresh_status(&mut self, status: ClientSigRefreshStatus) {
82        self.client_sig_refresh_status = status;
83    }
84
85    pub fn last_reload_refresh(&self) -> Arc<parking_lot::RwLock<ReloadRefreshStatus>> {
86        Arc::clone(&self.last_reload_refresh)
87    }
88}
89
90impl Default for AuthRuntime {
91    fn default() -> Self {
92        Self::new()
93    }
94}