lots of work
This commit is contained in:
parent
646340b637
commit
f108db3f23
|
@ -880,6 +880,7 @@ dependencies = [
|
|||
"byteorder",
|
||||
"diesel_derives",
|
||||
"itoa",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -19,7 +19,7 @@ serde_json = "1"
|
|||
toml = "0.8"
|
||||
log = "0.4"
|
||||
env_logger = "0.10"
|
||||
diesel = { version = "2" }
|
||||
diesel = { version = "2", features = ["serde_json"] }
|
||||
diesel-async = { version = "0.4", features = ["postgres", "bb8", "async-connection-wrapper"] }
|
||||
diesel_migrations = "2"
|
||||
bb8 = "0.8"
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
DROP TABLE organizations;
|
|
@ -0,0 +1,5 @@
|
|||
CREATE TABLE organizations (
|
||||
id VARCHAR NOT NULL PRIMARY KEY,
|
||||
owner_id VARCHAR NOT NULL UNIQUE REFERENCES users(id),
|
||||
name VARCHAR NOT NULL
|
||||
);
|
|
@ -0,0 +1 @@
|
|||
DROP TABLE signing_cas;
|
|
@ -0,0 +1,11 @@
|
|||
CREATE TABLE signing_cas
|
||||
(
|
||||
id VARCHAR NOT NULL PRIMARY KEY,
|
||||
pem VARCHAR NOT NULL,
|
||||
cert jsonb NOT NULL,
|
||||
expires_at TIMESTAMP NOT NULL,
|
||||
organization_id VARCHAR NOT NULL REFERENCES organizations(id),
|
||||
salt bytea NOT NULL,
|
||||
info bytea NOT NULL,
|
||||
private_key bytea NOT NULL
|
||||
);
|
|
@ -0,0 +1 @@
|
|||
DROP TABLE networks;
|
|
@ -0,0 +1,10 @@
|
|||
CREATE TABLE networks
|
||||
(
|
||||
id VARCHAR NOT NULL PRIMARY KEY,
|
||||
cidr VARCHAR NOT NULL,
|
||||
organization_id VARCHAR NOT NULL REFERENCES organizations(id),
|
||||
signing_ca_id VARCHAR NOT NULL REFERENCES signing_cas(id),
|
||||
created_at TIMESTAMP NOT NULL,
|
||||
name VARCHAR NOT NULL,
|
||||
lighthouses_as_relays BOOLEAN NOT NULL
|
||||
);
|
|
@ -1,5 +1,6 @@
|
|||
use diesel::{Associations, Identifiable, Insertable, Queryable, Selectable};
|
||||
use std::time::SystemTime;
|
||||
use serde_json::Value;
|
||||
|
||||
#[derive(Queryable, Selectable, Insertable, Identifiable, Debug, PartialEq, Clone)]
|
||||
#[diesel(table_name = crate::schema::users)]
|
||||
|
@ -60,3 +61,70 @@ pub struct AuthToken {
|
|||
pub user_id: String,
|
||||
pub expires: SystemTime,
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Queryable, Selectable, Insertable, Identifiable, Associations, Debug, PartialEq, Clone,
|
||||
)]
|
||||
#[diesel(belongs_to(User, foreign_key = owner_id))]
|
||||
#[diesel(table_name = crate::schema::organizations)]
|
||||
#[diesel(check_for_backend(diesel::pg::Pg))]
|
||||
pub struct Organization {
|
||||
pub id: String,
|
||||
pub owner_id: String,
|
||||
pub name: String
|
||||
}
|
||||
|
||||
/*
|
||||
id -> Varchar,
|
||||
pem -> Varchar,
|
||||
cert -> Jsonb,
|
||||
expires_at -> Timestamp,
|
||||
organization_id -> Varchar,
|
||||
salt -> Bytea,
|
||||
info -> Bytea,
|
||||
private_key -> Bytea,
|
||||
*/
|
||||
|
||||
#[derive(
|
||||
Queryable, Selectable, Insertable, Identifiable, Associations, Debug, PartialEq, Clone,
|
||||
)]
|
||||
#[diesel(belongs_to(Organization))]
|
||||
#[diesel(table_name = crate::schema::signing_cas)]
|
||||
#[diesel(check_for_backend(diesel::pg::Pg))]
|
||||
pub struct SigningCA {
|
||||
pub id: String,
|
||||
pub pem: String,
|
||||
pub cert: Value,
|
||||
pub expires_at: SystemTime,
|
||||
pub organization_id: String,
|
||||
pub salt: Vec<u8>,
|
||||
pub info: Vec<u8>,
|
||||
pub private_key: Vec<u8>
|
||||
}
|
||||
|
||||
/*
|
||||
id VARCHAR NOT NULL PRIMARY KEY,
|
||||
cidr VARCHAR NOT NULL,
|
||||
organization_id VARCHAR NOT NULL REFERENCES organizations(id),
|
||||
signing_ca_id VARCHAR NOT NULL REFERENCES signing_cas(id),
|
||||
created_at TIMESTAMP NOT NULL,
|
||||
name VARCHAR NOT NULL,
|
||||
lighthouses_as_relays BOOLEAN
|
||||
*/
|
||||
|
||||
#[derive(
|
||||
Queryable, Selectable, Insertable, Identifiable, Associations, Debug, PartialEq, Clone,
|
||||
)]
|
||||
#[diesel(belongs_to(Organization))]
|
||||
#[diesel(belongs_to(SigningCA, foreign_key = signing_ca_id))]
|
||||
#[diesel(table_name = crate::schema::networks)]
|
||||
#[diesel(check_for_backend(diesel::pg::Pg))]
|
||||
pub struct Network {
|
||||
pub id: String,
|
||||
pub cidr: String,
|
||||
pub organization_id: String,
|
||||
pub signing_ca_id: String,
|
||||
pub created_at: SystemTime,
|
||||
pub name: String,
|
||||
pub lighthouses_as_relays: bool
|
||||
}
|
|
@ -2,3 +2,4 @@ pub mod auth;
|
|||
pub mod signup;
|
||||
pub mod totp_authenticators;
|
||||
pub mod verify_totp_authenticator;
|
||||
pub mod networks;
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
use actix_web::HttpRequest;
|
||||
use actix_web::web::Json;
|
||||
use serde::Deserialize;
|
||||
use crate::AppState;
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct CreateNetworkReq {
|
||||
pub cidr: String,
|
||||
pub name: String
|
||||
}
|
||||
|
||||
pub struct CreateNetworkResp {
|
||||
|
||||
}
|
||||
|
||||
pub async fn create_network_req(req: Json<CreateNetworkReq>, state: Data<AppState>, req_info: HttpRequest)
|
|
@ -16,6 +16,26 @@ diesel::table! {
|
|||
}
|
||||
}
|
||||
|
||||
diesel::table! {
|
||||
networks (id) {
|
||||
id -> Varchar,
|
||||
cidr -> Varchar,
|
||||
organization_id -> Varchar,
|
||||
signing_ca_id -> Varchar,
|
||||
created_at -> Timestamp,
|
||||
name -> Varchar,
|
||||
lighthouses_as_relays -> Bool,
|
||||
}
|
||||
}
|
||||
|
||||
diesel::table! {
|
||||
organizations (id) {
|
||||
id -> Varchar,
|
||||
owner_id -> Varchar,
|
||||
name -> Varchar,
|
||||
}
|
||||
}
|
||||
|
||||
diesel::table! {
|
||||
session_tokens (id) {
|
||||
id -> Varchar,
|
||||
|
@ -24,6 +44,19 @@ diesel::table! {
|
|||
}
|
||||
}
|
||||
|
||||
diesel::table! {
|
||||
signing_cas (id) {
|
||||
id -> Varchar,
|
||||
pem -> Varchar,
|
||||
cert -> Jsonb,
|
||||
expires_at -> Timestamp,
|
||||
organization_id -> Varchar,
|
||||
salt -> Bytea,
|
||||
info -> Bytea,
|
||||
private_key -> Bytea,
|
||||
}
|
||||
}
|
||||
|
||||
diesel::table! {
|
||||
totp_authenticators (id) {
|
||||
id -> Varchar,
|
||||
|
@ -45,13 +78,20 @@ diesel::table! {
|
|||
|
||||
diesel::joinable!(auth_tokens -> users (user_id));
|
||||
diesel::joinable!(magic_links -> users (user_id));
|
||||
diesel::joinable!(networks -> organizations (organization_id));
|
||||
diesel::joinable!(networks -> signing_cas (signing_ca_id));
|
||||
diesel::joinable!(organizations -> users (owner_id));
|
||||
diesel::joinable!(session_tokens -> users (user_id));
|
||||
diesel::joinable!(signing_cas -> organizations (organization_id));
|
||||
diesel::joinable!(totp_authenticators -> users (user_id));
|
||||
|
||||
diesel::allow_tables_to_appear_in_same_query!(
|
||||
auth_tokens,
|
||||
magic_links,
|
||||
networks,
|
||||
organizations,
|
||||
session_tokens,
|
||||
signing_cas,
|
||||
totp_authenticators,
|
||||
users,
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue