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
45 changed files
with
1,060 additions
and
198 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
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,26 @@ | ||
[package] | ||
name = "spacegate-admin" | ||
version.workspace = true | ||
authors.workspace = true | ||
description.workspace = true | ||
keywords.workspace = true | ||
categories.workspace = true | ||
homepage.workspace = true | ||
documentation.workspace = true | ||
repository.workspace = true | ||
license.workspace = true | ||
edition.workspace = true | ||
readme = "./README.md" | ||
|
||
[features] | ||
k8s = ["kube", "k8s-openapi", "k8s-gateway-api","kernel-dto/k8s"] | ||
|
||
[dependencies] | ||
tardis = { workspace = true ,features = ["web-server"]} | ||
serde.workspace = true | ||
serde_json.workspace = true | ||
|
||
kernel-dto={path = "../kernel-dto",features = ["admin-support"]} | ||
kube = { workspace = true, optional = true } | ||
k8s-openapi = { workspace = true, optional = true } | ||
k8s-gateway-api = { workspace = true, optional = true } |
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,5 @@ | ||
--- | ||
|
||
**spacegate admin server🪐** | ||
|
||
--- |
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,15 @@ | ||
[fw] | ||
[fw.app] | ||
id = "spacegate-admin" | ||
name = "admin of spacegate" | ||
desc = "admin of spacegate" | ||
version = "0.1.0" | ||
default_lang = "zh-cn" | ||
|
||
|
||
[fw.web_server.modules.admin] | ||
title = "spacegate admin" | ||
doc_urls = [["test env", "http://localhost:9080/"],["remote env", "http://192.168.31.164:9080/"]] | ||
|
||
[fw.web_server] | ||
port = 9080 |
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,3 @@ | ||
pub(crate) mod gateway_api; | ||
pub(crate) mod plugin_api; | ||
pub(crate) mod route_api; |
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,50 @@ | ||
use crate::dto::base_dto::CommonPageDto; | ||
use crate::dto::query_dto::GatewayQueryDto; | ||
use crate::service::gateway_service::GatewayService; | ||
use kernel_dto::dto::gateway_dto::SgGateway; | ||
use tardis::web::poem_openapi; | ||
use tardis::web::poem_openapi::param::Query; | ||
use tardis::web::poem_openapi::payload::Json; | ||
use tardis::web::web_resp::{TardisApiResult, TardisPage, TardisResp, Void}; | ||
|
||
#[derive(Clone, Default)] | ||
pub struct GatewayApi; | ||
|
||
/// Gateway API | ||
#[poem_openapi::OpenApi(prefix_path = "/gateway")] | ||
impl GatewayApi { | ||
/// Get Gateway List | ||
#[oai(path = "/", method = "get")] | ||
async fn list( | ||
&self, | ||
name: Query<Option<String>>, | ||
namespace: Query<Option<String>>, | ||
port: Query<Option<u16>>, | ||
hostname: Query<Option<String>>, | ||
) -> TardisApiResult<Vec<SgGateway>> { | ||
let result = GatewayService::list( | ||
namespace.0.clone(), | ||
GatewayQueryDto { | ||
name: name.0, | ||
namespace: namespace.0, | ||
port: port.0, | ||
hostname: hostname.0, | ||
}, | ||
) | ||
.await?; | ||
TardisResp::ok(result) | ||
} | ||
|
||
/// Add Gateway | ||
#[oai(path = "/", method = "post")] | ||
async fn add(&self, namespace: Query<Option<String>>, gateway: Json<SgGateway>) -> TardisApiResult<SgGateway> { | ||
TardisResp::ok(GatewayService::add(namespace.0, gateway.0).await?) | ||
} | ||
|
||
/// Delete Gateway | ||
#[oai(path = "/", method = "delete")] | ||
async fn delete(&self, namespace: Query<Option<String>>, name: Query<String>) -> TardisApiResult<Void> { | ||
GatewayService::delete(namespace.0, &name.0).await?; | ||
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,26 @@ | ||
use crate::dto::base_dto::CommonPageDto; | ||
use crate::dto::query_dto::PluginQueryDto; | ||
use crate::service::plugin_service::PluginService; | ||
use tardis::web::poem_openapi; | ||
use tardis::web::poem_openapi::param::Query; | ||
use tardis::web::web_resp::{TardisApiResult, TardisResp, Void}; | ||
|
||
#[derive(Clone, Default)] | ||
pub struct PluginApi; | ||
|
||
#[poem_openapi::OpenApi(prefix_path = "/plugin")] | ||
impl PluginApi { | ||
/// Get Plugin List | ||
#[oai(path = "/", method = "get")] | ||
async fn list(&self, ids: Query<Option<String>>, name: Query<Option<String>>, namespace: Query<Option<String>>, code: Query<Option<String>>) -> TardisApiResult<Void> { | ||
let _ = PluginService::list(PluginQueryDto { | ||
ids: ids.0.map(|s| s.split(',').map(|s| s.to_string()).collect::<Vec<String>>()), | ||
name: name.0, | ||
namespace: namespace.0, | ||
code: code.0, | ||
target: None, | ||
}) | ||
.await; | ||
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,7 @@ | ||
use tardis::web::poem_openapi; | ||
|
||
#[derive(Clone, Default)] | ||
pub struct HttprouteApi; | ||
|
||
#[poem_openapi::OpenApi(prefix_path = "/httproute")] | ||
impl HttprouteApi {} |
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,43 @@ | ||
use tardis::serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Default, Debug, Serialize, Deserialize)] | ||
#[serde(default)] | ||
pub struct SpacegateAdminConfig { | ||
#[cfg(feature = "k8s")] | ||
pub k8s_config: Option<K8sConfig>, | ||
} | ||
|
||
#[cfg(feature = "k8s")] | ||
#[derive(Default, Debug, Serialize, Deserialize)] | ||
#[serde(default)] | ||
pub struct K8sConfig { | ||
/// The configured cluster url | ||
pub cluster_url: String, | ||
/// The configured default namespace | ||
pub default_namespace: String, | ||
/// The configured root certificate | ||
pub root_cert: Option<Vec<Vec<u8>>>, | ||
/// Set the timeout for connecting to the Kubernetes API. | ||
/// | ||
/// A value of `None` means no timeout | ||
pub connect_timeout: Option<std::time::Duration>, | ||
/// Set the timeout for the Kubernetes API response. | ||
/// | ||
/// A value of `None` means no timeout | ||
pub read_timeout: Option<std::time::Duration>, | ||
/// Set the timeout for the Kubernetes API request. | ||
/// | ||
/// A value of `None` means no timeout | ||
pub write_timeout: Option<std::time::Duration>, | ||
/// Whether to accept invalid certificates | ||
pub accept_invalid_certs: bool, | ||
/// Stores information to tell the cluster who you are. | ||
pub auth_info: kube::config::AuthInfo, | ||
// TODO Actually support proxy or create an example with custom client | ||
/// Optional proxy URL. | ||
pub proxy_url: Option<String>, | ||
/// If set, apiserver certificate will be validated to contain this string | ||
/// | ||
/// If not set, the `cluster_url` is used instead | ||
pub tls_server_name: Option<String>, | ||
} |
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 @@ | ||
pub const DOMAIN_CODE: &str = "admin"; |
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,11 @@ | ||
pub mod base_dto; | ||
pub mod filter_dto; | ||
pub mod query_dto; | ||
|
||
#[cfg(feature = "k8s")] | ||
pub trait ToFields { | ||
fn to_fields_vec(&self) -> Vec<String>; | ||
fn to_fields(&self) -> String { | ||
self.to_fields_vec().join(",") | ||
} | ||
} |
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,23 @@ | ||
pub struct CommonPageDto { | ||
pub page_size: u32, | ||
pub page_number: u32, | ||
} | ||
|
||
pub struct TargetRefDTO { | ||
pub name: String, | ||
pub kind: Option<String>, | ||
pub namespace: Option<String>, | ||
} | ||
|
||
pub struct BackendRefDTO { | ||
/// Name is the kubernetes service name OR url host. | ||
pub name_or_host: String, | ||
/// Namespace is the kubernetes namespace | ||
pub namespace: Option<String>, | ||
/// Port specifies the destination port number to use for this resource. | ||
pub port: Option<u16>, | ||
// pub protocol: Option<SgProtocol>, | ||
// | ||
// /// Filters define the filters that are applied to backend that match this hostnames. | ||
// pub filters: Option<Vec<SgRouteFilter>>, | ||
} |
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 @@ | ||
use kernel_dto::k8s_crd::{K8sSgFilterSpecFilter, K8sSgFilterSpecTargetRef}; |
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,44 @@ | ||
use crate::dto::base_dto::{CommonPageDto, TargetRefDTO}; | ||
#[cfg(feature = "k8s")] | ||
use crate::dto::ToFields; | ||
|
||
#[derive(Default)] | ||
pub struct GatewayQueryDto { | ||
pub name: Option<String>, | ||
pub namespace: Option<String>, | ||
pub port: Option<u16>, | ||
pub hostname: Option<String>, | ||
} | ||
|
||
#[cfg(feature = "k8s")] | ||
impl ToFields for GatewayQueryDto { | ||
fn to_fields_vec(&self) -> Vec<String> { | ||
let mut result = vec![]; | ||
if let Some(name) = &self.name { | ||
result.push(format!("metadata.name={}", name)) | ||
}; | ||
if let Some(namespace) = &self.namespace { | ||
result.push(format!("metadata.namespace={}", namespace)) | ||
}; | ||
result | ||
} | ||
} | ||
|
||
pub struct PluginQueryDto { | ||
pub ids: Option<Vec<String>>, | ||
pub name: Option<String>, | ||
pub code: Option<String>, | ||
pub namespace: Option<String>, | ||
pub target: Option<TargetRefDTO>, | ||
} | ||
|
||
#[cfg(feature = "k8s")] | ||
impl ToFields for PluginQueryDto { | ||
fn to_fields_vec(&self) -> Vec<String> { | ||
let mut result = vec![]; | ||
if let Some(name) = &self.name { | ||
result.push(format!("metadata.name={}", name)) | ||
}; | ||
result | ||
} | ||
} |
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,18 @@ | ||
use crate::api::{gateway_api, plugin_api, route_api}; | ||
use crate::constants; | ||
use tardis::basic::result::TardisResult; | ||
use tardis::web::web_server::{TardisWebServer, WebServerModule}; | ||
|
||
pub(crate) async fn init(web_server: &TardisWebServer) -> TardisResult<()> { | ||
init_api(web_server).await | ||
} | ||
|
||
async fn init_api(web_server: &TardisWebServer) -> TardisResult<()> { | ||
web_server | ||
.add_module( | ||
constants::DOMAIN_CODE, | ||
WebServerModule::from((gateway_api::GatewayApi, plugin_api::PluginApi, route_api::HttprouteApi)), | ||
) | ||
.await; | ||
Ok(()) | ||
} |
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,18 @@ | ||
use tardis::{basic::result::TardisResult, tokio, TardisFuns}; | ||
|
||
mod api; | ||
mod config; | ||
mod constants; | ||
mod dto; | ||
mod initializer; | ||
mod service; | ||
|
||
#[tokio::main] | ||
async fn main() -> TardisResult<()> { | ||
TardisFuns::init(Some("config")).await?; | ||
let web_server = TardisFuns::web_server(); | ||
initializer::init(web_server).await?; | ||
web_server.start().await?; | ||
web_server.await; | ||
Ok(()) | ||
} |
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,3 @@ | ||
pub(crate) mod gateway_service; | ||
mod helper; | ||
pub(crate) mod plugin_service; |
Oops, something went wrong.