Skip to content

Commit 448b9d2

Browse files
authored
feat: mega bot identity (#2004)
* feat: add bots related model * feat: add ActorType enum in AuditLogs * feat: add bot_keys table * feat: change Option<String> to String * fix: code review mentioned problem * fix: clippy error
1 parent 22628cf commit 448b9d2

File tree

18 files changed

+989
-1
lines changed

18 files changed

+989
-1
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ chrono = { version = "0.4.43", features = ["serde"] }
7979
hex = "0.4.3"
8080
sha1 = "0.10"
8181
sha2 = "0.10.9"
82+
rsa = "0.9.10"
8283

8384
idgenerator = "2.0.0"
8485
config = "0.15.19"

jupiter/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ rustls = { workspace = true }
4949
sha1 = { workspace = true }
5050
sha2 = { workspace = true }
5151
hex = { workspace = true }
52+
rand = { workspace = true }
53+
rsa = { workspace = true }
5254

5355
[dev-dependencies]
5456
redis-test = { workspace = true, features = ["aio"] }

jupiter/callisto/src/audit_logs.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.19
2+
3+
use sea_orm::entity::prelude::*;
4+
use serde::{Deserialize, Serialize};
5+
6+
use super::sea_orm_active_enums::{ActorTypeEnum, AuditActionEnum, TargetTypeEnum};
7+
8+
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
9+
#[sea_orm(table_name = "audit_logs")]
10+
pub struct Model {
11+
#[sea_orm(primary_key, auto_increment = false)]
12+
pub id: i64,
13+
pub actor_id: i64,
14+
pub actor_type: ActorTypeEnum,
15+
pub action: AuditActionEnum,
16+
pub target_type: TargetTypeEnum,
17+
pub target_id: i64,
18+
pub metadata: Option<Json>,
19+
pub created_at: DateTimeWithTimeZone,
20+
}
21+
22+
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
23+
pub enum Relation {}
24+
25+
impl ActiveModelBehavior for ActiveModel {}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.19
2+
3+
use sea_orm::entity::prelude::*;
4+
use serde::{Deserialize, Serialize};
5+
6+
use super::sea_orm_active_enums::{InstallationBotStatusEnum, InstallationTargetTypeEnum};
7+
8+
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
9+
#[sea_orm(table_name = "bot_installations")]
10+
pub struct Model {
11+
#[sea_orm(primary_key, auto_increment = false)]
12+
pub id: i64,
13+
pub bot_id: i64,
14+
pub target_type: InstallationTargetTypeEnum,
15+
pub target_id: i64,
16+
pub status: InstallationBotStatusEnum,
17+
pub installed_by: i64,
18+
pub installed_at: DateTimeWithTimeZone,
19+
}
20+
21+
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
22+
pub enum Relation {
23+
#[sea_orm(
24+
belongs_to = "super::bots::Entity",
25+
from = "Column::BotId",
26+
to = "super::bots::Column::Id",
27+
on_update = "Cascade",
28+
on_delete = "Cascade"
29+
)]
30+
Bots,
31+
}
32+
33+
impl Related<super::bots::Entity> for Entity {
34+
fn to() -> RelationDef {
35+
Relation::Bots.def()
36+
}
37+
}
38+
39+
impl ActiveModelBehavior for ActiveModel {}

jupiter/callisto/src/bot_keys.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.19
2+
3+
use sea_orm::entity::prelude::*;
4+
use serde::{Deserialize, Serialize};
5+
6+
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
7+
#[sea_orm(table_name = "bot_keys")]
8+
pub struct Model {
9+
#[sea_orm(primary_key, auto_increment = false)]
10+
pub id: i64,
11+
pub bot_id: i64,
12+
pub private_key: String,
13+
pub public_key: String,
14+
pub created_at: DateTimeWithTimeZone,
15+
}
16+
17+
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
18+
pub enum Relation {
19+
#[sea_orm(
20+
belongs_to = "super::bots::Entity",
21+
from = "Column::BotId",
22+
to = "super::bots::Column::Id",
23+
on_update = "NoAction",
24+
on_delete = "Cascade"
25+
)]
26+
Bots,
27+
}
28+
29+
impl Related<super::bots::Entity> for Entity {
30+
fn to() -> RelationDef {
31+
Relation::Bots.def()
32+
}
33+
}
34+
35+
impl ActiveModelBehavior for ActiveModel {}

jupiter/callisto/src/bot_tokens.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.19
2+
3+
use sea_orm::entity::prelude::*;
4+
use serde::{Deserialize, Serialize};
5+
6+
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
7+
#[sea_orm(table_name = "bot_tokens")]
8+
pub struct Model {
9+
#[sea_orm(primary_key, auto_increment = false)]
10+
pub id: i64,
11+
pub bot_id: i64,
12+
pub token_hash: String,
13+
pub token_name: String,
14+
pub expires_at: Option<DateTimeWithTimeZone>,
15+
pub created_at: DateTimeWithTimeZone,
16+
pub revoked: bool,
17+
}
18+
19+
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
20+
pub enum Relation {
21+
#[sea_orm(
22+
belongs_to = "super::bots::Entity",
23+
from = "Column::BotId",
24+
to = "super::bots::Column::Id",
25+
on_update = "Cascade",
26+
on_delete = "Cascade"
27+
)]
28+
Bots,
29+
}
30+
31+
impl Related<super::bots::Entity> for Entity {
32+
fn to() -> RelationDef {
33+
Relation::Bots.def()
34+
}
35+
}
36+
37+
impl ActiveModelBehavior for ActiveModel {}

jupiter/callisto/src/bots.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.19
2+
3+
use sea_orm::entity::prelude::*;
4+
use serde::{Deserialize, Serialize};
5+
6+
use super::sea_orm_active_enums::{BotStatusEnum, PermissionScopeEnum};
7+
8+
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
9+
#[sea_orm(table_name = "bots")]
10+
pub struct Model {
11+
#[sea_orm(primary_key, auto_increment = false)]
12+
pub id: i64,
13+
pub name: String,
14+
pub organization_id: Option<i64>,
15+
pub creator_user_id: i64,
16+
pub permission_scope: PermissionScopeEnum,
17+
pub status: BotStatusEnum,
18+
pub created_at: DateTimeWithTimeZone,
19+
pub updated_at: DateTimeWithTimeZone,
20+
}
21+
22+
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
23+
pub enum Relation {
24+
#[sea_orm(has_many = "super::bot_installations::Entity")]
25+
BotInstallations,
26+
#[sea_orm(has_many = "super::bot_keys::Entity")]
27+
BotKeys,
28+
#[sea_orm(has_many = "super::bot_tokens::Entity")]
29+
BotTokens,
30+
}
31+
32+
impl Related<super::bot_installations::Entity> for Entity {
33+
fn to() -> RelationDef {
34+
Relation::BotInstallations.def()
35+
}
36+
}
37+
38+
impl Related<super::bot_keys::Entity> for Entity {
39+
fn to() -> RelationDef {
40+
Relation::BotKeys.def()
41+
}
42+
}
43+
44+
impl Related<super::bot_tokens::Entity> for Entity {
45+
fn to() -> RelationDef {
46+
Relation::BotTokens.def()
47+
}
48+
}
49+
50+
impl ActiveModelBehavior for ActiveModel {}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use chrono::Utc;
2+
3+
use crate::{bot_keys, entity_ext::generate_id};
4+
5+
impl bot_keys::Model {
6+
pub fn new(bot_id: i64, private_key: String, public_key: String) -> Self {
7+
let now = Utc::now().into();
8+
9+
Self {
10+
id: generate_id(),
11+
bot_id,
12+
private_key,
13+
public_key,
14+
created_at: now,
15+
}
16+
}
17+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use chrono::Utc;
2+
3+
use crate::{
4+
bots,
5+
entity_ext::generate_id,
6+
sea_orm_active_enums::{BotStatusEnum, PermissionScopeEnum},
7+
};
8+
9+
impl bots::Model {
10+
pub fn new(
11+
name: String,
12+
organization_id: Option<i64>,
13+
creator_user_id: i64,
14+
permission_scope: PermissionScopeEnum,
15+
status: BotStatusEnum,
16+
) -> Self {
17+
let now = Utc::now().into();
18+
19+
Self {
20+
id: generate_id(),
21+
name,
22+
organization_id,
23+
creator_user_id,
24+
permission_scope,
25+
status,
26+
created_at: now,
27+
updated_at: now,
28+
}
29+
}
30+
}

jupiter/callisto/src/entity_ext/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
pub mod bot_keys;
2+
pub mod bots;
13
pub mod buck_session;
24
pub mod buck_session_file;
35
pub mod check_result;

0 commit comments

Comments
 (0)