Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ jobs:
libgtk-3-dev \
libayatana-appindicator3-dev \
librsvg2-dev
- run: cargo build
- run: rustup component add clippy
- uses: actions-rs/cargo@v1
with:
Expand Down
10 changes: 9 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[workspace]
members = [
"mono",
"mega",
"gateway",
"common",
Expand All @@ -16,7 +17,7 @@ members = [
"lunar/src-tauri",
"atlas",
]
default-members = ["mega", "libra", "aries"]
default-members = ["mega", "mono", "libra", "aries"]
exclude = ["craft"]
resolver = "1"

Expand All @@ -34,6 +35,8 @@ neptune = { path = "neptune" }
saturn = { path = "saturn" }
taurus = { path = "taurus" }
mega = { path = "mega" }
mono = { path = "mono" }

anyhow = "1.0.86"
serde = "1.0.205"
serde_json = "1.0.122"
Expand Down Expand Up @@ -75,3 +78,8 @@ shadow-rs = "0.31.1"
reqwest = "0.12.5"
lazy_static = "1.5.0"
uuid = "1.10.0"
regex = "1.10.4"
ed25519-dalek = "2.1.1"
ctrlc = "3.4.4"
git2 = "0.19.0"
tempfile = "3.10.1"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ For now, we are developing on the macOS and Arch Linux. And quick start manuel i

### Quick Review of Architecture

![Mega Architect](docs/images/architect.svg)
![Mega Architect](docs/images/Mega_Bin_and_Modules.png)

1. **mega** - The main entry of Mega.
2. **gateway** - The Gateway module is responsible for handling `git`, `git-lfs` and web UI requests through the HTTP and SSH protocol. More information on the [Gateway](gateway/README.md).
Expand Down
3 changes: 3 additions & 0 deletions common/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ use serde::{Deserialize, Serialize};
pub struct CommonOptions {
#[arg(long, default_value_t = String::from("127.0.0.1"))]
pub host: String,
}

#[derive(Args, Clone, Debug)]
pub struct ZtmOptions {
#[arg(long, default_value_t = 7777)]
pub ztm_agent_port: u16,

Expand Down
Binary file added docs/images/Mega_Bin_and_Modules.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 3 additions & 19 deletions gateway/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,24 @@ name = "gateway"
path = "src/lib.rs"

[dependencies]
mono = { workspace = true }
common = { workspace = true }
jupiter = { workspace = true }
callisto = { workspace = true }
ceres = { workspace = true }
gemini = { workspace = true }
vault = { workspace = true }
venus = { workspace = true }
mercury = { workspace = true }
taurus = { workspace = true }
anyhow = { workspace = true }

axum = { workspace = true }
axum-server = { version = "0.7", features = ["tls-rustls"] }
tower = { workspace = true }
tracing = { workspace = true }
russh = { workspace = true }
russh-keys = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
chrono = { workspace = true }
futures = { workspace = true }
bytes = { workspace = true }
async-trait = { workspace = true }
clap = { workspace = true, features = ["derive"] }
tower-http = { workspace = true, features = [
"cors",
"trace",
"decompression-full",
] }
axum-extra = { workspace = true, features = ["typed-header"] }
tokio = { workspace = true, features = ["net"] }
tokio-stream = { workspace = true }
async-stream = { workspace = true }
reqwest = { workspace = true, features = ["json"] }
uuid = { workspace = true, features = ["v4"] }
regex = "1.10.4"
ed25519-dalek = { version = "2.1.1", features = ["pkcs8"] }
lazy_static ={ workspace = true }
lazy_static = { workspace = true }
4 changes: 2 additions & 2 deletions gateway/src/api/github_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use lazy_static::lazy_static;
use reqwest::Client;
use serde_json::Value;
use taurus::event::github_webhook::{GithubWebhookEvent, WebhookType};
use crate::api::ApiServiceState;
use crate::api::MegaApiServiceState;

lazy_static! {
static ref CLIENT: Client = Client::builder()
Expand All @@ -15,7 +15,7 @@ lazy_static! {
.unwrap();
}

pub fn routers() -> Router<ApiServiceState> {
pub fn routers() -> Router<MegaApiServiceState> {
Router::new()
.route("/github/webhook", post(webhook))
}
Expand Down
52 changes: 6 additions & 46 deletions gateway/src/api/mod.rs
Original file line number Diff line number Diff line change
@@ -1,52 +1,12 @@
use std::path::PathBuf;
use common::model::ZtmOptions;
use mono::api::MonoApiServiceState;

use ceres::api_service::{
import_api_service::ImportApiService, mono_api_service::MonoApiService, ApiHandler,
};
use common::model::CommonOptions;
use jupiter::context::Context;
use venus::import_repo::repo::Repo;

pub mod api_router;
pub mod mr_router;
pub mod oauth;
pub mod github_router;
pub mod ztm_router;
mod github_router;

#[derive(Clone)]
pub struct ApiServiceState {
pub context: Context,
pub struct MegaApiServiceState {
pub inner: MonoApiServiceState,
pub port: u16,
pub common: CommonOptions,
}

impl ApiServiceState {
pub fn monorepo(&self) -> MonoApiService {
MonoApiService {
context: self.context.clone(),
}
}

pub async fn api_handler(&self, path: PathBuf) -> Box<dyn ApiHandler> {
let import_dir = self.context.config.monorepo.import_dir.clone();
if path.starts_with(&import_dir) && path != import_dir {
if let Some(model) = self
.context
.services
.git_db_storage
.find_git_repo_like_path(path.to_str().unwrap())
.await
.unwrap()
{
let repo: Repo = model.into();
return Box::new(ImportApiService {
context: self.context.clone(),
repo,
});
}
}
Box::new(MonoApiService {
context: self.context.clone(),
})
}
pub ztm: ZtmOptions,
}
14 changes: 7 additions & 7 deletions gateway/src/api/ztm_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@ use axum::{

use common::model::CommonResult;

use crate::api::ApiServiceState;
use crate::api::MegaApiServiceState;

pub fn routers() -> Router<ApiServiceState> {
pub fn routers() -> Router<MegaApiServiceState> {
Router::new()
.route("/ztm/repo_provide", get(repo_provide))
.route("/ztm/repo_folk", get(repo_folk))
}

async fn repo_provide(
Query(query): Query<HashMap<String, String>>,
state: State<ApiServiceState>,
state: State<MegaApiServiceState>,
) -> Result<Json<CommonResult<String>>, (StatusCode, String)> {
let path = match query.get("path") {
Some(p) => p,
None => {
return Err((StatusCode::BAD_REQUEST, String::from("Path not provide\n")));
}
};
let bootstrap_node = match state.common.bootstrap_node.clone() {
let bootstrap_node = match state.ztm.bootstrap_node.clone() {
Some(b) => b.clone(),
None => {
return Err((
Expand All @@ -39,7 +39,7 @@ async fn repo_provide(
let res = match gemini::http::handler::repo_provide(
state.port,
bootstrap_node,
state.context.clone(),
state.inner.context.clone(),
path.to_string(),
)
.await
Expand All @@ -52,7 +52,7 @@ async fn repo_provide(

async fn repo_folk(
Query(query): Query<HashMap<String, String>>,
state: State<ApiServiceState>,
state: State<MegaApiServiceState>,
) -> Result<Json<CommonResult<String>>, (StatusCode, String)> {
let identifier = match query.get("identifier") {
Some(i) => i,
Expand All @@ -77,7 +77,7 @@ async fn repo_folk(
};

let res = gemini::http::handler::repo_folk(
state.common.ztm_agent_port,
state.ztm.ztm_agent_port,
identifier.to_string(),
local_port,
)
Expand Down
Loading