This commit is contained in:
c0repwn3r 2023-04-03 16:42:52 -04:00
parent f7bd45dff3
commit 90653796cc
Signed by: core
GPG Key ID: FDBF740DADDCEECF
6 changed files with 103 additions and 11 deletions

View File

@ -1,4 +1,5 @@
pub mod auth;
pub mod signup;
pub mod totp_authenticators;
pub mod verify_totp_authenticators;
pub mod verify_totp_authenticators;
pub mod networks;

View File

@ -0,0 +1,46 @@
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct GetNetworksResponse {
pub data: Vec<GetNetworksResponseData>,
pub metadata: GetNetworksResponseMetadata
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct GetNetworksResponseData {
pub id: String,
pub cidr: String,
#[serde(rename = "organizationID")]
pub organization_id: String,
#[serde(rename = "signingCAID")]
pub signing_ca_id: String,
#[serde(rename = "createdAt")]
pub created_at: String, // 2023-03-22T18:55:47.009Z
pub name: String,
#[serde(rename = "lighthousesAsRelays")]
pub lighthouses_as_relays: bool
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct GetNetworksResponseMetadata {
#[serde(rename = "totalCount")]
pub total_count: i64,
#[serde(rename = "hasNextPage")]
pub has_next_page: bool,
#[serde(rename = "hasPrevPage")]
pub has_prev_page: bool,
#[serde(default, skip_serializing_if = "is_none", rename = "prevCursor")]
pub prev_cursor: Option<String>,
#[serde(default, skip_serializing_if = "is_none", rename = "nextCursor")]
pub next_cursor: Option<String>,
#[serde(default, skip_serializing_if = "is_none")]
pub page: Option<GetNetworksResponseMetadataPage>
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct GetNetworksResponseMetadataPage {
pub count: i64,
pub start: i64
}
fn is_none<T>(o: &Option<T>) -> bool { o.is_none() }

View File

@ -7,9 +7,14 @@ use sea_orm::entity::prelude::*;
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: String,
pub cidr: String,
#[sea_orm(unique)]
pub organization: String,
pub ip_block: String,
#[sea_orm(unique)]
pub signing_ca: String,
pub created_at: i64,
pub name: String,
pub lighthouses_as_relays: bool,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
@ -22,6 +27,14 @@ pub enum Relation {
on_delete = "Cascade"
)]
Organization,
#[sea_orm(
belongs_to = "super::signing_ca::Entity",
from = "Column::SigningCa",
to = "super::signing_ca::Column::Id",
on_update = "Cascade",
on_delete = "Cascade"
)]
SigningCa,
}
impl Related<super::organization::Entity> for Entity {
@ -30,4 +43,10 @@ impl Related<super::organization::Entity> for Entity {
}
}
impl Related<super::signing_ca::Entity> for Entity {
fn to() -> RelationDef {
Relation::SigningCa.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

View File

@ -17,6 +17,15 @@ pub struct Model {
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}
pub enum Relation {
#[sea_orm(has_one = "super::network::Entity")]
Network,
}
impl Related<super::network::Entity> for Entity {
fn to() -> RelationDef {
Relation::Network.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

View File

@ -6,12 +6,12 @@ pub mod m20230402_162601_create_table_users;
pub mod m20230402_183515_create_table_magic_links;
pub mod m20230402_213712_create_table_session_tokens;
pub mod m20230402_232316_create_table_organizations;
pub mod m20230402_232323_create_table_networks;
pub mod m20230402_233043_create_table_api_keys;
pub mod m20230402_233047_create_table_api_keys_scopes;
mod m20230402_234025_create_table_totp_authenticators;
mod m20230403_002256_create_table_auth_tokens;
mod m20230403_142517_create_table_signing_cas;
pub mod m20230402_234025_create_table_totp_authenticators;
pub mod m20230403_002256_create_table_auth_tokens;
pub mod m20230403_142517_create_table_signing_cas;
pub mod m20230403_173431_create_table_networks;
#[async_trait::async_trait]
impl MigratorTrait for Migrator {
@ -21,12 +21,12 @@ impl MigratorTrait for Migrator {
Box::new(m20230402_183515_create_table_magic_links::Migration),
Box::new(m20230402_213712_create_table_session_tokens::Migration),
Box::new(m20230402_232316_create_table_organizations::Migration),
Box::new(m20230402_232323_create_table_networks::Migration),
Box::new(m20230402_233043_create_table_api_keys::Migration),
Box::new(m20230402_233047_create_table_api_keys_scopes::Migration),
Box::new(m20230402_234025_create_table_totp_authenticators::Migration),
Box::new(m20230403_002256_create_table_auth_tokens::Migration),
Box::new(m20230403_142517_create_table_signing_cas::Migration),
Box::new(m20230403_173431_create_table_networks::Migration),
]
}
}

View File

@ -1,5 +1,6 @@
use sea_orm_migration::prelude::*;
use crate::m20230402_232316_create_table_organizations::Organization;
use crate::m20230403_142517_create_table_signing_cas::SigningCA;
#[derive(DeriveMigrationName)]
pub struct Migration;
@ -11,15 +12,27 @@ impl MigrationTrait for Migration {
Table::create()
.table(Network::Table)
.col(ColumnDef::new(Network::Id).string().not_null().primary_key())
.col(ColumnDef::new(Network::Cidr).string().not_null())
.col(ColumnDef::new(Network::Organization).string().not_null().unique_key())
.col(ColumnDef::new(Network::IpBlock).string().not_null())
.col(ColumnDef::new(Network::SigningCA).string().not_null().unique_key())
.col(ColumnDef::new(Network::CreatedAt).big_integer().not_null())
.col(ColumnDef::new(Network::Name).string().not_null())
.col(ColumnDef::new(Network::LighthousesAsRelays).boolean().not_null())
.foreign_key(
ForeignKey::create()
.from(Network::Table, Network::Organization)
.to(Organization::Table, Organization::Id)
.on_delete(ForeignKeyAction::Cascade)
.on_update(ForeignKeyAction::Cascade)
).to_owned()
)
.foreign_key(
ForeignKey::create()
.from(Network::Table, Network::SigningCA)
.to(SigningCA::Table, SigningCA::Id)
.on_delete(ForeignKeyAction::Cascade)
.on_update(ForeignKeyAction::Cascade)
)
.to_owned()
).await
}
@ -33,6 +46,10 @@ impl MigrationTrait for Migration {
pub enum Network {
Table,
Id,
Cidr,
Organization,
IpBlock
SigningCA,
CreatedAt,
Name,
LighthousesAsRelays
}