0e66a41
use sea_orm::entity::Set;
use sea_orm::entity::prelude::*;
use uuid::Uuid;
#[derive(Clone, Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum)]
#[sea_orm(
rs_type = "String",
db_type = "String(StringLen::N(16))",
rename_all = "snake_case"
)]
pub enum PublicKeyType {
RSA,
ED25519,
ECDSA,
}
#[sea_orm::model]
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
#[sea_orm(table_name = "user_ssh_keys")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
#[sea_orm(indexed)]
pub user_id: i64,
#[sea_orm(column_type = "String(StringLen::N(64))")]
pub name: String,
#[sea_orm(column_type = "String(StringLen::N(255))")]
pub description: Option<String>,
#[sea_orm(column_type = "Text")]
pub public_key: String,
pub algorithm: PublicKeyType,
#[sea_orm(unique, column_type = "String(StringLen::N(128))")]
pub fingerprint: String,
#[sea_orm(default_expr = "Expr::current_timestamp()")]
pub created_at: DateTimeUtc,
pub expires_at: Option<DateTimeUtc>,
pub last_used_at: Option<DateTimeUtc>,
pub revoked_at: Option<DateTimeUtc>,
#[sea_orm(default_value = 1)]
pub version: i32,
#[sea_orm(belongs_to, from = "user_id", to = "id", on_delete = "Cascade")]
pub user: BelongsTo<super::users::Entity>,
}
#[async_trait::async_trait]
impl ActiveModelBehavior for ActiveModel {
async fn before_save<C>(mut self, _db: &C, insert: bool) -> Result<Self, DbErr>
where
C: ConnectionTrait,
{
if insert && self.id.is_not_set() {
self.id = Set(Uuid::now_v7());
}
Ok(self)
}
}