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
11 changes: 7 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ mega = { path = "mega" }
mono = { path = "mono" }
libra = { path = "libra" }

anyhow = "1.0.89"
anyhow = "1.0.90"
serde = "1.0.210"
serde_json = "1.0.128"
serde_json = "1.0.132"
tracing = "0.1.40"
tracing-subscriber = "0.3.18"
tracing-appender = "0.2"
Expand Down Expand Up @@ -65,7 +65,7 @@ axum-server = "0.7.1"
tower-http = "0.6.1"
tower = "0.5.1"
hex = "0.4.3"
sea-orm = "1.0.1"
sea-orm = "1.1.0"
flate2 = "1.0.34"
bstr = "1.10.0"
colored = "2.1.0"
Expand All @@ -75,7 +75,7 @@ config = "0.14.0"
shadow-rs = "0.35.1"
reqwest = "0.12.8"
lazy_static = "1.5.0"
uuid = "1.10.0"
uuid = "1.11.0"
regex = "1.11.0"
ed25519-dalek = "2.1.1"
ctrlc = "3.4.4"
Expand All @@ -85,3 +85,6 @@ home = "0.5.9"
ring = "0.17.8"
cedar-policy = "4.2.1"
secp256k1 = "0.30.0"

[profile.release]
debug = true
22 changes: 9 additions & 13 deletions gateway/src/https_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use tower_http::cors::{Any, CorsLayer};
use tower_http::decompression::RequestDecompressionLayer;
use tower_http::trace::TraceLayer;

use common::config::Config;
use common::model::{CommonOptions, ZtmOptions};
use gemini::ztm::agent::{run_ztm_client, LocalZTMAgent};
use jupiter::context::Context;
Expand Down Expand Up @@ -54,7 +53,7 @@ pub struct HttpsOptions {
pub https_cert_path: PathBuf,
}

pub async fn https_server(config: Config, options: HttpsOptions) {
pub async fn https_server(context: Context, options: HttpsOptions) {
let HttpsOptions {
common: CommonOptions { host, .. },
https_key_path,
Expand All @@ -63,10 +62,10 @@ pub async fn https_server(config: Config, options: HttpsOptions) {
ztm,
} = options.clone();

check_run_with_ztm(config.clone(), options.ztm.clone(), https_port);
check_run_with_ztm(context.clone(), options.ztm.clone(), https_port);

let app = app(
config,
context,
host.clone(),
https_port,
options.common.clone(),
Expand All @@ -85,17 +84,17 @@ pub async fn https_server(config: Config, options: HttpsOptions) {
.unwrap();
}

pub async fn http_server(config: Config, options: HttpOptions) {
pub async fn http_server(context: Context, options: HttpOptions) {
let HttpOptions {
common: CommonOptions { host, .. },
http_port,
ztm,
} = options.clone();

check_run_with_ztm(config.clone(), options.ztm.clone(), http_port);
check_run_with_ztm(context.clone(), options.ztm.clone(), http_port);

let app = app(
config,
context,
host.clone(),
http_port,
options.common.clone(),
Expand All @@ -113,14 +112,12 @@ pub async fn http_server(config: Config, options: HttpOptions) {
}

pub async fn app(
config: Config,
context: Context,
host: String,
port: u16,
common: CommonOptions,
ztm: ZtmOptions,
) -> Router {
let context = Context::new(config.clone()).await;
context.services.mono_storage.init_monorepo(&config.monorepo).await;
let state = AppState {
host,
port,
Expand Down Expand Up @@ -182,7 +179,7 @@ pub async fn app(
.with_state(state)
}

pub fn check_run_with_ztm(config: Config, ztm: ZtmOptions, http_port: u16) {
pub fn check_run_with_ztm(context: Context, ztm: ZtmOptions, http_port: u16) {
//Mega server join a ztm mesh
match ztm.bootstrap_node {
Some(bootstrap_node) => {
Expand All @@ -198,7 +195,7 @@ pub fn check_run_with_ztm(config: Config, ztm: ZtmOptions, http_port: u16) {
thread::sleep(time::Duration::from_secs(3));

let bootstrap_node_clone = bootstrap_node.clone();
let config_clone = config.clone();
let config_clone = context.config.clone();
let ztm_agent_clone = ztm_agent.clone();
tokio::spawn(async move {
run_ztm_client(
Expand All @@ -214,7 +211,6 @@ pub fn check_run_with_ztm(config: Config, ztm: ZtmOptions, http_port: u16) {
if ztm.cache_repo {
thread::sleep(time::Duration::from_secs(3));
tokio::spawn(async move {
let context = Context::new(config.clone()).await;
cache_public_repository(bootstrap_node, context, ztm_agent).await
});
}
Expand Down
10 changes: 8 additions & 2 deletions mega/src/commands/service/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use clap::{ArgMatches, Args, Command, FromArgMatches};

use common::{config::Config, errors::MegaResult};
use gateway::https_server::{self, HttpOptions};

use jupiter::context::Context;

pub fn cli() -> Command {
HttpOptions::augment_args_for_update(Command::new("http").about("Start Mega HTTP server"))
Expand All @@ -14,7 +14,13 @@ pub(crate) async fn exec(config: Config, args: &ArgMatches) -> MegaResult {
.unwrap();

tracing::info!("{server_matchers:#?}");
https_server::http_server(config, server_matchers).await;
let context = Context::new(config.clone()).await;
context
.services
.mono_storage
.init_monorepo(&config.monorepo)
.await;
https_server::http_server(context, server_matchers).await;
Ok(())
}

Expand Down
9 changes: 8 additions & 1 deletion mega/src/commands/service/https.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use clap::{ArgMatches, Args, Command, FromArgMatches};

use common::{config::Config, errors::MegaResult};
use gateway::https_server::{self, HttpsOptions};
use jupiter::context::Context;


pub fn cli() -> Command {
Expand All @@ -14,7 +15,13 @@ pub(crate) async fn exec(config: Config, args: &ArgMatches) -> MegaResult {
.unwrap();

tracing::info!("{server_matchers:#?}");
https_server::https_server(config, server_matchers).await;
let context = Context::new(config.clone()).await;
context
.services
.mono_storage
.init_monorepo(&config.monorepo)
.await;
https_server::https_server(context, server_matchers).await;
Ok(())
}

Expand Down
12 changes: 8 additions & 4 deletions mega/src/commands/service/multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use common::{
model::{CommonOptions, ZtmOptions},
};
use gateway::https_server::{self, HttpOptions, HttpsOptions};
use jupiter::context::Context;
use mono::server::ssh_server::{self, SshCustom, SshOptions};

#[derive(Debug, PartialEq, Clone, ValueEnum)]
Expand Down Expand Up @@ -58,14 +59,17 @@ pub(crate) async fn exec(config: Config, args: &ArgMatches) -> MegaResult {

let service_type = server_matchers.service;

let config_clone = config.clone();
let context = Context::new(config.clone()).await;
context.services.mono_storage.init_monorepo(&config.monorepo).await;

let context_clone = context.clone();
let http_server = if service_type.contains(&StartCommand::Http) {
let http = HttpOptions {
common: server_matchers.common.clone(),
http_port: server_matchers.http_port,
ztm: server_matchers.ztm,
};
tokio::spawn(async move { https_server::http_server(config_clone, http).await })
tokio::spawn(async move { https_server::http_server(context_clone, http).await })
} else if service_type.contains(&StartCommand::Https) {
let https = HttpsOptions {
common: server_matchers.common.clone(),
Expand All @@ -74,7 +78,7 @@ pub(crate) async fn exec(config: Config, args: &ArgMatches) -> MegaResult {
https_cert_path: server_matchers.https_cert_path.unwrap(),
ztm: server_matchers.ztm,
};
tokio::spawn(async move { https_server::https_server(config_clone, https).await })
tokio::spawn(async move { https_server::https_server(context_clone, https).await })
} else {
tokio::task::spawn(async {})
};
Expand All @@ -84,7 +88,7 @@ pub(crate) async fn exec(config: Config, args: &ArgMatches) -> MegaResult {
common: server_matchers.common.clone(),
custom: server_matchers.ssh,
};
tokio::spawn(async move { ssh_server::start_server(config, &ssh).await })
tokio::spawn(async move { ssh_server::start_server(context, &ssh).await })
} else {
tokio::task::spawn(async {})
};
Expand Down
9 changes: 8 additions & 1 deletion mega/src/commands/service/ssh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use clap::{ArgMatches, Args, Command, FromArgMatches};

use common::config::Config;
use common::errors::MegaResult;
use jupiter::context::Context;
use mono::server::ssh_server::start_server;
use mono::server::ssh_server::SshOptions;

Expand All @@ -14,7 +15,13 @@ pub(crate) async fn exec(config: Config, args: &ArgMatches) -> MegaResult {
.map_err(|err| err.exit())
.unwrap();
tracing::info!("{server_matchers:#?}");
start_server(config, &server_matchers).await;
let context = Context::new(config.clone()).await;
context
.services
.mono_storage
.init_monorepo(&config.monorepo)
.await;
start_server(context, &server_matchers).await;
Ok(())
}

Expand Down
9 changes: 8 additions & 1 deletion mono/src/commands/service/http.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use clap::{ArgMatches, Args, Command, FromArgMatches};

use common::{config::Config, errors::MegaResult};
use jupiter::context::Context;
use crate::server::https_server::{self, HttpOptions};


Expand All @@ -15,7 +16,13 @@ pub(crate) async fn exec(config: Config, args: &ArgMatches) -> MegaResult {
.unwrap();

tracing::info!("{server_matchers:#?}");
https_server::start_http(config, server_matchers).await;
let context = Context::new(config.clone()).await;
context
.services
.mono_storage
.init_monorepo(&config.monorepo)
.await;
https_server::start_http(context, server_matchers).await;
Ok(())
}

Expand Down
9 changes: 8 additions & 1 deletion mono/src/commands/service/https.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use clap::{ArgMatches, Args, Command, FromArgMatches};

use common::{config::Config, errors::MegaResult};
use jupiter::context::Context;

use crate::server::https_server::{start_https, HttpsOptions};

Expand All @@ -14,7 +15,13 @@ pub(crate) async fn exec(config: Config, args: &ArgMatches) -> MegaResult {
.unwrap();

tracing::info!("{server_matchers:#?}");
start_https(config, server_matchers).await;
let context = Context::new(config.clone()).await;
context
.services
.mono_storage
.init_monorepo(&config.monorepo)
.await;
start_https(context, server_matchers).await;
Ok(())
}

Expand Down
15 changes: 11 additions & 4 deletions mono/src/commands/service/multi.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::path::PathBuf;

use clap::{ArgMatches, Args, Command, FromArgMatches, ValueEnum};
use jupiter::context::Context;

use crate::server::{
https_server::{self, HttpOptions, HttpsOptions},
Expand Down Expand Up @@ -53,21 +54,27 @@ pub(crate) async fn exec(config: Config, args: &ArgMatches) -> MegaResult {

let service_type = server_matchers.service;

let config_clone = config.clone();
let context = Context::new(config.clone()).await;
context
.services
.mono_storage
.init_monorepo(&config.monorepo)
.await;
let context_clone = context.clone();
let http_server = if service_type.contains(&StartCommand::Http) {
let http = HttpOptions {
common: server_matchers.common.clone(),
http_port: server_matchers.http_port,
};
tokio::spawn(async move { https_server::start_http(config_clone, http).await })
tokio::spawn(async move { https_server::start_http(context_clone, http).await })
} else if service_type.contains(&StartCommand::Https) {
let https = HttpsOptions {
common: server_matchers.common.clone(),
https_port: server_matchers.https_port,
https_key_path: server_matchers.https_key_path.unwrap(),
https_cert_path: server_matchers.https_cert_path.unwrap(),
};
tokio::spawn(async move { https_server::start_https(config_clone, https).await })
tokio::spawn(async move { https_server::start_https(context_clone, https).await })
} else {
panic!("start params should provide! run like 'mega service multi http https'")
};
Expand All @@ -77,7 +84,7 @@ pub(crate) async fn exec(config: Config, args: &ArgMatches) -> MegaResult {
common: server_matchers.common.clone(),
custom: server_matchers.ssh,
};
tokio::spawn(async move { ssh_server::start_server(config, &ssh).await })
tokio::spawn(async move { ssh_server::start_server(context, &ssh).await })
} else {
tokio::task::spawn(async {})
};
Expand Down
9 changes: 8 additions & 1 deletion mono/src/commands/service/ssh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use clap::{ArgMatches, Args, Command, FromArgMatches};

use common::config::Config;
use common::errors::MegaResult;
use jupiter::context::Context;
use crate::server::ssh_server::{start_server, SshOptions};


Expand All @@ -14,7 +15,13 @@ pub(crate) async fn exec(config: Config, args: &ArgMatches) -> MegaResult {
.map_err(|err| err.exit())
.unwrap();
tracing::info!("{server_matchers:#?}");
start_server(config, &server_matchers).await;
let context = Context::new(config.clone()).await;
context
.services
.mono_storage
.init_monorepo(&config.monorepo)
.await;
start_server(context, &server_matchers).await;
Ok(())
}

Expand Down
Loading