aboutsummaryrefslogtreecommitdiffstats
path: root/daemon/src
diff options
context:
space:
mode:
authorToby Vincent <tobyv13@gmail.com>2022-01-12 15:25:31 -0600
committerToby Vincent <tobyv13@gmail.com>2022-01-12 15:25:31 -0600
commit887456a217e595b64501169c57cabd6b6a34f167 (patch)
tree518f23c433947d977e84e22deac5424625ece0c2 /daemon/src
parent19ad50c61d71101dc253f14d731958be628cd1ba (diff)
feat: inital project structure and api
Diffstat (limited to 'daemon/src')
-rw-r--r--daemon/src/lib.rs76
-rw-r--r--daemon/src/main.rs9
2 files changed, 85 insertions, 0 deletions
diff --git a/daemon/src/lib.rs b/daemon/src/lib.rs
new file mode 100644
index 0000000..3cdb9b9
--- /dev/null
+++ b/daemon/src/lib.rs
@@ -0,0 +1,76 @@
+pub mod api {
+ use rocket::{get, post, serde::json::Json, Build, Config, Rocket};
+ use rocket_okapi::{
+ openapi, openapi_get_routes, rapidoc::*, settings::UrlObject, swagger_ui::*,
+ };
+ use std::net::Ipv4Addr;
+ use zone_core::Container;
+
+ /// # Get all containers
+ ///
+ /// Returns all containers.
+ #[openapi(tag = "Containers")]
+ #[get("/containers/list")]
+ fn get_all_containers() -> Json<Vec<Container>> {
+ let containers = vec![];
+ Json(containers)
+ }
+
+ /// # Get a user's containers
+ ///
+ /// Returns all containers belonging to a single user.
+ #[openapi(tag = "Containers")]
+ #[get("/containers/list/<user>")]
+ fn get_containers_by_user(user: String) -> Json<Vec<Container>> {
+ let containers = vec![];
+ let _user = user;
+ Json(containers)
+ }
+
+ /// # Create container
+ #[openapi(tag = "Containers")]
+ #[post("/container", data = "<container>")]
+ fn create_container(container: Json<Container>) -> Json<Container> {
+ container
+ }
+
+ pub fn build_rocket() -> Rocket<Build> {
+ let config = Config {
+ address: Ipv4Addr::new(127, 0, 0, 1).into(),
+ port: 8000,
+ ..Config::debug_default()
+ };
+
+ rocket::custom(config)
+ .mount(
+ "/",
+ openapi_get_routes![get_all_containers, get_containers_by_user, create_container,],
+ )
+ .mount(
+ "/swagger-ui/",
+ make_swagger_ui(&SwaggerUIConfig {
+ url: "../openapi.json".to_owned(),
+ ..Default::default()
+ }),
+ )
+ .mount(
+ "/rapidoc/",
+ make_rapidoc(&RapiDocConfig {
+ general: GeneralConfig {
+ spec_urls: vec![UrlObject::new("General", "../openapi.json")],
+ ..Default::default()
+ },
+ hide_show: HideShowConfig {
+ allow_spec_url_load: false,
+ allow_spec_file_load: false,
+ ..Default::default()
+ },
+ ..Default::default()
+ }),
+ )
+ }
+}
+
+pub mod zfs {}
+
+pub mod nspawn {}
diff --git a/daemon/src/main.rs b/daemon/src/main.rs
new file mode 100644
index 0000000..2f2bcf1
--- /dev/null
+++ b/daemon/src/main.rs
@@ -0,0 +1,9 @@
+use zoned::api;
+
+#[rocket::main]
+async fn main() {
+ match api::build_rocket().launch().await {
+ Ok(()) => println!("Rocket shut down gracefully."),
+ Err(err) => eprintln!("Rocket had an error: {}", err),
+ };
+}