Project compiles now

pull/3/head
Jef Roosens 2021-11-23 17:49:31 +01:00
parent 07f25219d6
commit b99d9faa04
Signed by: Jef Roosens
GPG Key ID: 955C0660072F691F
10 changed files with 93 additions and 91 deletions

63
Cargo.lock generated
View File

@ -652,15 +652,6 @@ version = "0.2.108"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8521a1b57e76b1ec69af7599e75e38e7b7fad6610f037db8c79b127201b5d119" checksum = "8521a1b57e76b1ec69af7599e75e38e7b7fad6610f037db8c79b127201b5d119"
[[package]]
name = "libmimalloc-sys"
version = "0.1.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9636c194f9db483f4d0adf2f99a65011a99f904bd222bbd67fb4df4f37863c30"
dependencies = [
"cc",
]
[[package]] [[package]]
name = "linked-hash-map" name = "linked-hash-map"
version = "0.5.4" version = "0.5.4"
@ -687,9 +678,9 @@ dependencies = [
[[package]] [[package]]
name = "loom" name = "loom"
version = "0.5.2" version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2b9df80a3804094bf49bb29881d18f6f05048db72127e84e09c26fc7c2324f5" checksum = "5df2c4aeb432e60c9e5ae517ca8ed8b63556ce23093b2758fc8837d75439c5ec"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"generator", "generator",
@ -702,9 +693,9 @@ dependencies = [
[[package]] [[package]]
name = "matchers" name = "matchers"
version = "0.0.1" version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f099785f7595cc4b4553a174ce30dd7589ef93391ff414dbb67f62392b9e0ce1" checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558"
dependencies = [ dependencies = [
"regex-automata", "regex-automata",
] ]
@ -736,15 +727,6 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "mimalloc"
version = "0.1.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf5f78c1d9892fb5677a8b2f543f967ab891ac0f71feecd961435b74f877283a"
dependencies = [
"libmimalloc-sys",
]
[[package]] [[package]]
name = "mime" name = "mime"
version = "0.3.16" version = "0.3.16"
@ -1045,6 +1027,23 @@ dependencies = [
"rand_core", "rand_core",
] ]
[[package]]
name = "rb"
version = "0.1.0"
source = "git+https://git.hackbever.be/rusty-bever/common-rs.git#1ce6c47124533a9f6b9e276b7bae23f07db0bf68"
dependencies = [
"base64",
"chrono",
"figment",
"hmac",
"jwt",
"rand",
"rocket",
"serde",
"sha2",
"uuid",
]
[[package]] [[package]]
name = "rb-blog" name = "rb-blog"
version = "0.1.0" version = "0.1.0"
@ -1056,9 +1055,9 @@ dependencies = [
"figment", "figment",
"hmac", "hmac",
"jwt", "jwt",
"mimalloc",
"openssl", "openssl",
"rand", "rand",
"rb",
"rocket", "rocket",
"rocket_sync_db_pools", "rocket_sync_db_pools",
"rust-argon2", "rust-argon2",
@ -1692,36 +1691,22 @@ dependencies = [
"tracing-core", "tracing-core",
] ]
[[package]]
name = "tracing-serde"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb65ea441fbb84f9f6748fd496cf7f63ec9af5bca94dd86456978d055e8eb28b"
dependencies = [
"serde",
"tracing-core",
]
[[package]] [[package]]
name = "tracing-subscriber" name = "tracing-subscriber"
version = "0.2.25" version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e0d2eaa99c3c2e41547cfa109e910a68ea03823cccad4a0525dcbc9b01e8c71" checksum = "7507ec620f809cdf07cccb5bc57b13069a88031b795efd4079b1c71b66c1613d"
dependencies = [ dependencies = [
"ansi_term", "ansi_term",
"chrono",
"lazy_static", "lazy_static",
"matchers", "matchers",
"regex", "regex",
"serde",
"serde_json",
"sharded-slab", "sharded-slab",
"smallvec", "smallvec",
"thread_local", "thread_local",
"tracing", "tracing",
"tracing-core", "tracing-core",
"tracing-log", "tracing-log",
"tracing-serde",
] ]
[[package]] [[package]]

View File

@ -14,6 +14,7 @@ path = "src/main.rs"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
rb = { git = "https://git.hackbever.be/rusty-bever/common-rs.git" }
# Backend web framework # Backend web framework
rocket = { version = "0.5.0-rc.1", features = [ "json", "uuid" ] } rocket = { version = "0.5.0-rc.1", features = [ "json", "uuid" ] }
# Used to provide Rocket routes with database connections # Used to provide Rocket routes with database connections
@ -39,4 +40,3 @@ chrono = { version = "*", features = [ "serde" ] }
base64 = "0.13.0" base64 = "0.13.0"
# Reading in configuration files # Reading in configuration files
figment = { version = "*", features = [ "yaml" ] } figment = { version = "*", features = [ "yaml" ] }
mimalloc = { version = "0.1.26", default_features = false }

18
docker-compose.yml 100644
View File

@ -0,0 +1,18 @@
# I just use this compose file to easily start up test databases
version: '3'
services:
db-blog:
image: 'postgres:14-alpine'
restart: 'always'
environment:
- 'POSTGRES_USER=rb'
- 'POSTGRES_PASSWORD=rb'
ports:
- '5433:5432'
# volumes:
# - 'db-data:/var/lib/postgresql/data'
# volumes:
# db-data:

View File

@ -1,12 +1,10 @@
use chrono::NaiveDate; use chrono::NaiveDate;
use diesel::{insert_into, prelude::*, Insertable, PgConnection, Queryable}; use diesel::{insert_into, prelude::*, Insertable, PgConnection, Queryable};
use rb::errors::{RbError, RbOption, RbResult};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use uuid::Uuid; use uuid::Uuid;
use crate::{ use crate::schema::{posts, posts::dsl::*};
errors::{RbError, RbOption, RbResult},
schema::{posts, posts::dsl::*},
};
#[derive(Queryable, Serialize)] #[derive(Queryable, Serialize)]
pub struct Post pub struct Post

View File

@ -1,11 +1,9 @@
use diesel::{insert_into, prelude::*, Insertable, PgConnection, Queryable}; use diesel::{insert_into, prelude::*, Insertable, PgConnection, Queryable};
use rb::errors::{RbError, RbResult};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use uuid::Uuid; use uuid::Uuid;
use crate::{ use crate::schema::{sections, sections::dsl::*};
errors::{RbError, RbResult},
schema::{sections, sections::dsl::*},
};
#[derive(Queryable, Serialize)] #[derive(Queryable, Serialize)]
pub struct Section pub struct Section

View File

@ -0,0 +1,5 @@
#[macro_use]
extern crate diesel;
pub mod db;
pub(crate) mod schema;

View File

@ -1,17 +1,13 @@
// This needs to be explicitely included before diesel is imported to make sure
// compilation succeeds in the release Docker image.
extern crate openssl;
#[macro_use] #[macro_use]
extern crate rocket; extern crate rocket;
#[macro_use] #[macro_use]
extern crate diesel_migrations; extern crate diesel_migrations;
#[macro_use]
extern crate diesel;
use figment::{ use figment::{
providers::{Env, Format, Yaml}, providers::{Env, Format, Yaml},
Figment, Figment,
}; };
use rb::auth::JwtConf;
use rocket::{ use rocket::{
fairing::AdHoc, fairing::AdHoc,
http::Status, http::Status,
@ -21,16 +17,9 @@ use rocket::{
use rocket_sync_db_pools::database; use rocket_sync_db_pools::database;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
pub mod db;
pub mod errors;
pub mod guards;
pub mod posts; pub mod posts;
pub(crate) mod schema;
pub mod sections; pub mod sections;
#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
#[database("postgres_rb")] #[database("postgres_rb")]
pub struct RbDbConn(diesel::PgConnection); pub struct RbDbConn(diesel::PgConnection);
@ -54,35 +43,12 @@ async fn run_db_migrations(rocket: Rocket<Build>) -> Result<Rocket<Build>, Rocke
.await .await
} }
// async fn create_admin_user<'a>(rocket: &'a Rocket<Orbit>)
// {
// let config = rocket.state::<RbConfig>().expect("RbConfig instance");
// let admin_user = config.admin_user.clone();
// let admin_pass = config.admin_pass.clone();
// let conn = RbDbConn::get_one(&rocket)
// .await
// .expect("database connection");
// conn.run(move |c| {
// admin::create_admin_user(c, &admin_user, &admin_pass).expect("failed to create admin user")
// })
// .await;
// }
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct RbJwtConf
{
key: String,
refresh_token_size: usize,
refresh_token_expire: i64,
}
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]
pub struct RbConfig pub struct RbConfig
{ {
admin_user: String, admin_user: String,
admin_pass: String, admin_pass: String,
jwt: RbJwtConf, jwt: JwtConf,
} }
#[launch] #[launch]
@ -101,7 +67,7 @@ fn rocket() -> _
run_db_migrations, run_db_migrations,
)) ))
// .attach(AdHoc::try_on_ignite("Create admin user", create_admin_user)) // .attach(AdHoc::try_on_ignite("Create admin user", create_admin_user))
.attach(AdHoc::config::<RbConfig>()) .attach(AdHoc::config::<JwtConf>())
.register("/", catchers![default_catcher]) .register("/", catchers![default_catcher])
.mount("/sections", routes![sections::create_section]) .mount("/sections", routes![sections::create_section])
.mount("/posts", routes![posts::get, posts::create]) .mount("/posts", routes![posts::get, posts::create])

View File

@ -1,11 +1,11 @@
use rocket::serde::json::Json; use rb::{
use crate::{
db,
errors::{RbOption, RbResult}, errors::{RbOption, RbResult},
guards::Admin, guards::Admin,
RbDbConn,
}; };
use rb_blog::db;
use rocket::serde::json::Json;
use crate::RbDbConn;
#[get("/?<offset>&<limit>")] #[get("/?<offset>&<limit>")]
pub async fn get(conn: RbDbConn, offset: u32, limit: u32) -> RbResult<Json<Vec<db::Post>>> pub async fn get(conn: RbDbConn, offset: u32, limit: u32) -> RbResult<Json<Vec<db::Post>>>

View File

@ -0,0 +1,27 @@
table! {
posts (id) {
id -> Uuid,
section_id -> Uuid,
title -> Nullable<Varchar>,
publish_date -> Date,
content -> Text,
}
}
table! {
sections (id) {
id -> Uuid,
title -> Varchar,
shortname -> Varchar,
description -> Nullable<Text>,
is_default -> Bool,
has_titles -> Bool,
}
}
joinable!(posts -> sections (section_id));
allow_tables_to_appear_in_same_query!(
posts,
sections,
);

View File

@ -1,8 +1,13 @@
//! This module handles management of site sections (aka blogs). //! This module handles management of site sections (aka blogs).
use rb::{
errors::{RbOption, RbResult},
guards::Admin,
};
use rb_blog::db;
use rocket::serde::json::Json; use rocket::serde::json::Json;
use crate::{db, errors::RbResult, guards::Admin, RbDbConn}; use crate::RbDbConn;
/// Route for creating a new section. /// Route for creating a new section.
/// ///