forked from ideal-world/spacegate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use tardis::web::poem_openapi; | ||
use tardis::web::web_resp::{TardisApiResult, TardisResp, Void}; | ||
|
||
#[derive(Clone, Default)] | ||
pub struct AuthApi; | ||
|
||
/// Auth API | ||
#[poem_openapi::OpenApi(prefix_path = "/")] | ||
impl AuthApi { | ||
#[oai(path = "/login", method = "post")] | ||
async fn login(&self) -> TardisApiResult<Void> { | ||
TardisResp::ok(Void {}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use serde::{Deserialize, Serialize}; | ||
use tardis::web::poem_openapi; | ||
use tardis::web::web_resp::{TardisApiResult, TardisResp}; | ||
|
||
use crate::model::query_dto::{GatewayQueryInst, HttpRouteQueryInst, PluginQueryInst}; | ||
use crate::service::gateway_service::GatewayVoService; | ||
use crate::{ | ||
model::query_dto::{SgTlsQueryInst, SpacegateInstQueryInst}, | ||
service::{plugin_service::PluginVoService, route_service::HttpRouteVoService, secret_service::TlsVoService, spacegate_manage_service::SpacegateManageService}, | ||
}; | ||
|
||
#[derive(Clone, Default)] | ||
pub struct DashboardApi; | ||
|
||
/// Dashboard API | ||
#[poem_openapi::OpenApi(prefix_path = "/")] | ||
impl DashboardApi { | ||
async fn statistics(&self) -> TardisApiResult<Statistics> { | ||
//todo client_name | ||
let client_name = ""; | ||
TardisResp::ok(Statistics { | ||
gateway_count: GatewayVoService::list( | ||
client_name, | ||
GatewayQueryInst { | ||
names: None, | ||
port: None, | ||
hostname: None, | ||
tls_ids: None, | ||
}, | ||
) | ||
.await? | ||
.len() as i64, | ||
route_count: HttpRouteVoService::list( | ||
client_name, | ||
HttpRouteQueryInst { | ||
names: None, | ||
gateway_name: None, | ||
hostnames: None, | ||
filter_ids: None, | ||
}, | ||
) | ||
.await? | ||
.len() as i64, | ||
plugin_count: PluginVoService::list( | ||
client_name, | ||
PluginQueryInst { | ||
ids: None, | ||
name: None, | ||
code: None, | ||
namespace: None, | ||
target_name: None, | ||
target_kind: None, | ||
target_namespace: None, | ||
}, | ||
) | ||
.await? | ||
.len() as i64, | ||
tls_count: TlsVoService::list(client_name, SgTlsQueryInst { names: None }).await?.len() as i64, | ||
instance_count: SpacegateManageService::list(SpacegateInstQueryInst { names: None }).await?.len() as i64, | ||
}) | ||
} | ||
} | ||
|
||
#[derive(Default, Debug, Serialize, Deserialize, Clone, poem_openapi::Object)] | ||
struct Statistics { | ||
pub gateway_count: i64, | ||
pub route_count: i64, | ||
pub plugin_count: i64, | ||
pub tls_count: i64, | ||
pub instance_count: i64, | ||
} |