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
2 changes: 1 addition & 1 deletion .github/workflows/base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
- uses: Swatinem/rust-cache@v2
- run: |
sudo apt update
sudo apt install libwebkit2gtk-4.0-dev \
sudo apt install -y libwebkit2gtk-4.0-dev \
build-essential \
curl \
wget \
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ axum-server = "0.7"
tower-http = "0.5.2"
tower = "0.5.0"
hex = "0.4.3"
sea-orm = "1.0.0"
sea-orm = "1.0.1"
flate2 = "1.0.30"
bstr = "1.10.0"
colored = "2.1.0"
Expand Down
2 changes: 1 addition & 1 deletion atlas/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
async-openai = "0.24.0"
async-openai = "0.23.4"
reqwest.workspace = true
serde.workspace = true
serde_json.workspace = true
Expand Down
6 changes: 5 additions & 1 deletion common/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ pub struct Config {
pub monorepo: MonoConfig,
pub pack: PackConfig,
pub lfs: LFSConfig,
pub oauth: OauthConfig,
// Not used in mega app
#[serde(default)]
pub oauth: Option<OauthConfig>,
}

impl Config {
Expand Down Expand Up @@ -277,4 +279,6 @@ impl Default for LFSConfig {
pub struct OauthConfig {
pub github_client_id: String,
pub github_client_secret: String,
pub ui_domain: String,
pub cookie_domain: String,
}
2 changes: 1 addition & 1 deletion docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ docker network create mono-network
# run postgres
docker run --rm -it -d --name mono-pg --network mono-network -v /mnt/data/mono/pg-data:/var/lib/postgresql/data -p 5432:5432 mono-pg:0.1-pre-release
docker run --rm -it -d --name mono-engine --network mono-network -v /mnt/data/mono/mono-data:/opt/mega -p 8000:8000 -p 22:9000 mono-engine:0.1-pre-release
docker run --rm -it -d --name mono-ui --network mono-network -e MEGA_INTERNAL_HOST=http://mono-engine:8000 -e MEGA_HOST=http://git.gitmono.com -e MOON_HOST=https://console.gitmono.com -p 3000:3000 mono-ui:0.1-pre-release
docker run --rm -it -d --name mono-ui --network mono-network -e MEGA_INTERNAL_HOST=http://mono-engine:8000 -e MEGA_HOST=https://git.gitmono.com -e MOON_HOST=https://console.gitmono.com -p 3000:3000 mono-ui:0.1-pre-release
```
4 changes: 4 additions & 0 deletions gateway/src/https_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ pub async fn app(
inner: MonoApiServiceState {
context: context.clone(),
common: common.clone(),
oauth_client: None,
store: None,
},
ztm,
port,
Expand All @@ -140,6 +142,8 @@ pub async fn app(
let mono_api_state = MonoApiServiceState {
context: context.clone(),
common: common.clone(),
oauth_client: None,
store: None,
};

pub fn mega_routers() -> Router<MegaApiServiceState> {
Expand Down
2 changes: 2 additions & 0 deletions jupiter/callisto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ pub mod mega_tag;
pub mod mega_tree;
pub mod mq_storage;
pub mod raw_blob;
pub mod ssh_keys;
pub mod user;
pub mod ztm_node;
pub mod ztm_nostr_event;
pub mod ztm_nostr_req;
Expand Down
2 changes: 2 additions & 0 deletions jupiter/callisto/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ pub use crate::mega_refs::Entity as MegaRefs;
pub use crate::mega_tag::Entity as MegaTag;
pub use crate::mega_tree::Entity as MegaTree;
pub use crate::raw_blob::Entity as RawBlob;
pub use crate::ssh_keys::Entity as SshKeys;
pub use crate::user::Entity as User;
pub use crate::ztm_node::Entity as ZtmNode;
pub use crate::ztm_path_mapping::Entity as ZtmPathMapping;
pub use crate::ztm_repo_info::Entity as ZtmRepoInfo;
19 changes: 19 additions & 0 deletions jupiter/callisto/src/ssh_keys.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.0

use sea_orm::entity::prelude::*;

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "ssh_keys")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i64,
pub user_id: i64,
#[sea_orm(column_type = "Text")]
pub ssh_key: String,
pub created_at: DateTime,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}

impl ActiveModelBehavior for ActiveModel {}
25 changes: 25 additions & 0 deletions jupiter/callisto/src/user.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.0

use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[sea_orm(table_name = "user")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: i64,
#[sea_orm(column_type = "Text")]
pub name: String,
#[sea_orm(column_type = "Text", unique)]
pub email: String,
#[sea_orm(column_type = "Text")]
pub avatar_url: String,
pub is_github: bool,
pub created_at: DateTime,
pub updated_at: Option<DateTime>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}

impl ActiveModelBehavior for ActiveModel {}
2 changes: 1 addition & 1 deletion jupiter/callisto/src/ztm_path_mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use sea_orm::entity::prelude::*;
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: i64,
#[sea_orm(column_type = "Text")]
#[sea_orm(column_type = "Text", unique)]
pub alias: String,
#[sea_orm(column_type = "Text")]
pub repo_path: String,
Expand Down
6 changes: 5 additions & 1 deletion jupiter/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use common::config::Config;

use crate::storage::{
git_db_storage::GitDbStorage, init::database_connection, lfs_storage::LfsStorage,
mono_storage::MonoStorage, mq_storage::MQStorage, ztm_storage::ZTMStorage,
mono_storage::MonoStorage, mq_storage::MQStorage, user_storage::UserStorage,
ztm_storage::ZTMStorage,
};

#[derive(Clone)]
Expand Down Expand Up @@ -35,6 +36,7 @@ pub struct Service {
pub lfs_storage: Arc<LfsStorage>,
pub ztm_storage: Arc<ZTMStorage>,
pub mq_storage: Arc<MQStorage>,
pub user_storage: UserStorage,
}

impl Service {
Expand All @@ -50,6 +52,7 @@ impl Service {
lfs_storage: Arc::new(LfsStorage::new(connection.clone()).await),
ztm_storage: Arc::new(ZTMStorage::new(connection.clone()).await),
mq_storage: Arc::new(MQStorage::new(connection.clone()).await),
user_storage: UserStorage::new(connection.clone()).await,
}
}

Expand All @@ -64,6 +67,7 @@ impl Service {
lfs_storage: Arc::new(LfsStorage::mock()),
ztm_storage: Arc::new(ZTMStorage::mock()),
mq_storage: Arc::new(MQStorage::mock()),
user_storage: UserStorage::mock(),
})
}
}
6 changes: 4 additions & 2 deletions jupiter/src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ pub mod init;
pub mod lfs_storage;
pub mod mono_storage;
pub mod mq_storage;
pub mod user_storage;
pub mod ztm_storage;

use async_trait::async_trait;
use sea_orm::{sea_query::OnConflict, ActiveModelTrait, ConnectionTrait, EntityTrait};

use callisto::import_refs;
use common::errors::MegaError;
use sea_orm::{sea_query::OnConflict, ActiveModelTrait, ConnectionTrait, EntityTrait};
///
/// This interface is designed to handle the commonalities between the database storage and
/// file system storage.
Expand All @@ -23,7 +24,8 @@ pub trait GitStorageProvider: Send + Sync {

async fn get_ref(&self, repo_id: i64) -> Result<Vec<import_refs::Model>, MegaError>;

async fn update_ref(&self, repo_id: i64, ref_name: &str, new_id: &str) -> Result<(), MegaError>;
async fn update_ref(&self, repo_id: i64, ref_name: &str, new_id: &str)
-> Result<(), MegaError>;

// async fn save_entry(&self, repo: &Repo, entry_list: Vec<Entry>) -> Result<(), MegaError>;

Expand Down
70 changes: 70 additions & 0 deletions jupiter/src/storage/user_storage.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
use std::sync::Arc;

use sea_orm::{
ActiveModelTrait, ColumnTrait, DatabaseConnection, EntityTrait, IntoActiveModel, QueryFilter,
};

use callisto::{ssh_keys, user};
use common::{errors::MegaError, utils::generate_id};

#[derive(Clone)]
pub struct UserStorage {
pub connection: Arc<DatabaseConnection>,
}

impl UserStorage {
pub fn get_connection(&self) -> &DatabaseConnection {
&self.connection
}

pub async fn new(connection: Arc<DatabaseConnection>) -> Self {
UserStorage { connection }
}

pub fn mock() -> Self {
UserStorage {
connection: Arc::new(DatabaseConnection::default()),
}
}

pub async fn find_user_by_email(&self, email: &str) -> Result<Option<user::Model>, MegaError> {
let res = user::Entity::find()
.filter(user::Column::Email.eq(email))
.one(self.get_connection())
.await?;
Ok(res)
}

pub async fn save_user(&self, user: user::Model) -> Result<(), MegaError> {
let a_model = user.into_active_model();
a_model.insert(self.get_connection()).await.unwrap();
Ok(())
}

pub async fn save_ssh_key(&self, user_id: i64, ssh_key: &str) -> Result<(), MegaError> {
let model = ssh_keys::Model {
id: generate_id(),
user_id,
ssh_key: ssh_key.to_owned(),
created_at: chrono::Utc::now().naive_utc(),
};
let a_model = model.into_active_model();
a_model.insert(self.get_connection()).await.unwrap();
Ok(())
}

pub async fn list_user_ssh(&self, user_id: i64) -> Result<Vec<ssh_keys::Model>, MegaError> {
let res = ssh_keys::Entity::find()
.filter(ssh_keys::Column::UserId.eq(user_id))
.all(self.get_connection())
.await?;
Ok(res)
}

pub async fn delete_ssh_key(&self, id: i64) -> Result<(), MegaError> {
ssh_keys::Entity::delete_by_id(id)
.exec(self.get_connection())
.await?;
Ok(())
}
}
4 changes: 0 additions & 4 deletions mega/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,3 @@ enable_split = true # Default is disabled. Set to true to enable file splitting
# Size of each file chunk when splitting is enabled, in bytes. Ignored if splitting is disabled.
split_size = 20971520 # Default size is 20MB (20971520 bytes)

[oauth]
# GitHub OAuth application client id and secret
github_client_id = ""
github_client_secret = ""
5 changes: 5 additions & 0 deletions mono/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ path = "src/main.rs"

[dependencies]
common = { workspace = true }
callisto = { workspace = true }
jupiter = { workspace = true }
ceres = { workspace = true }
taurus = { workspace = true }
Expand Down Expand Up @@ -50,6 +51,10 @@ ed25519-dalek = { workspace = true, features = ["pkcs8"] }
lazy_static = { workspace = true }
ctrlc = { workspace = true }
shadow-rs = { workspace = true }
oauth2 = "4.4.2"
async-session = "3.0.0"
http = "1.1.0"
sea-orm = { workspace = true, features = [] }

[dev-dependencies]
reqwest = { workspace = true, features = ["stream", "json"] }
Expand Down
12 changes: 11 additions & 1 deletion mono/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ big_obj_threshold = 1024
# set the local path of the project storage
raw_obj_local_path = "${base_dir}/objects"

# set the local path of the lfs storage
lfs_obj_local_path = "${base_dir}/lfs"

obs_access_key = ""
Expand Down Expand Up @@ -80,6 +81,9 @@ clean_cache_after_decode = true
channel_message_size = 1_000_000

[lfs]
# LFS Server url
url = "http://localhost:8000"

## IMPORTANT: The 'enable_split' feature can only be enabled for new databases. Existing databases do not support this feature.
# Enable or disable splitting large files into smaller chunks
enable_split = true # Default is disabled. Set to true to enable file splitting.
Expand All @@ -90,4 +94,10 @@ split_size = 20971520 # Default size is 20MB (20971520 bytes)
[oauth]
# GitHub OAuth application client id and secret
github_client_id = ""
github_client_secret = ""
github_client_secret = ""

# Used redirect to ui after login
ui_domain = "http://localhost:3000"

# Set .gitmono.com on Production
cookie_domain = "localhost"
6 changes: 5 additions & 1 deletion mono/src/api/api_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use common::model::CommonResult;
use taurus::event::api_request::{ApiRequestEvent, ApiType};

use crate::api::mr_router;
use crate::api::user::user_router;
use crate::api::MonoApiServiceState;

pub fn routers() -> Router<MonoApiServiceState> {
Expand All @@ -26,7 +27,10 @@ pub fn routers() -> Router<MonoApiServiceState> {
.route("/tree", get(get_tree_info))
.route("/blob", get(get_blob_object));

Router::new().merge(router).merge(mr_router::routers())
Router::new()
.merge(router)
.merge(mr_router::routers())
.merge(user_router::routers())
}

async fn get_blob_object(
Expand Down
Loading