wasmcloud/src/main.rs

72 lines
1.7 KiB
Rust
Raw Normal View History

2020-10-26 16:56:24 +00:00
#![feature(proc_macro_hygiene, decl_macro)]
#[macro_use]
extern crate diesel;
#[macro_use]
extern crate rocket;
#[macro_use]
extern crate rocket_contrib;
2020-10-28 19:00:57 +00:00
#[macro_use]
extern crate tracing;
2020-10-26 16:56:24 +00:00
2020-10-27 15:43:54 +00:00
use color_eyre::eyre::Result;
2020-10-26 16:56:24 +00:00
use diesel::pg::PgConnection;
2020-10-28 16:20:00 +00:00
use rocket_contrib::helmet::SpaceHelmet;
2020-10-30 15:01:36 +00:00
use rocket_oauth2::OAuth2;
2020-10-26 16:56:24 +00:00
2020-10-28 01:07:25 +00:00
pub mod api;
2020-10-30 18:09:35 +00:00
pub mod b2;
2020-10-27 15:43:54 +00:00
pub mod gitea;
2020-10-28 16:20:00 +00:00
pub mod jwt;
2020-10-26 16:56:24 +00:00
pub mod models;
pub mod schema;
#[database("main_data")]
2020-10-28 01:07:25 +00:00
pub struct MainDatabase(PgConnection);
2020-10-26 16:56:24 +00:00
2020-10-28 16:20:00 +00:00
pub struct Gitea;
2020-10-27 15:43:54 +00:00
2020-10-30 18:09:35 +00:00
// Name your user agent after your app?
pub static APP_USER_AGENT: &str = concat!(
env!("CARGO_PKG_NAME"),
"/",
env!("CARGO_PKG_VERSION"),
" +https://tulpa.dev/wasmcloud/api",
);
2020-10-27 15:43:54 +00:00
fn main() -> Result<()> {
color_eyre::install()?;
tracing_subscriber::fmt::init();
2020-10-28 19:00:57 +00:00
// XXX(Xe): This looks ineffectual, however it forces jwt::SECRET to be
// evaluated and will kill the program if JWT_SECRET is not found.
let _ = *jwt::SECRET;
2020-10-30 18:09:35 +00:00
let _ = *b2::CREDS;
let _ = *b2::BUCKET_NAME;
2020-10-26 16:56:24 +00:00
rocket::ignite()
2020-10-27 15:43:54 +00:00
.attach(OAuth2::<Gitea>::fairing("gitea"))
2020-10-26 16:56:24 +00:00
.attach(MainDatabase::fairing())
2020-10-27 15:43:54 +00:00
.attach(SpaceHelmet::default())
2020-10-28 18:09:03 +00:00
.mount(
"/api",
routes![
2020-10-30 15:01:36 +00:00
api::handler::create,
2020-10-30 14:26:56 +00:00
api::handler::list,
api::handler::get,
api::handler::delete,
2020-10-30 15:57:29 +00:00
api::handler::get_config,
api::handler::create_config,
2020-10-30 14:26:56 +00:00
api::user::whoami,
api::user::get,
api::token::list,
api::token::delete,
api::token::create,
2020-10-28 18:09:03 +00:00
],
)
2020-10-30 14:26:56 +00:00
.mount("/", routes![gitea::login, gitea::callback])
2020-10-27 15:43:54 +00:00
.launch();
Ok(())
2020-10-26 16:56:24 +00:00
}