summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorJoe Carstairs <me@joeac.net>2026-06-08 09:06:08 +0100
committerJoe Carstairs <me@joeac.net>2026-06-08 09:06:08 +0100
commit158044c320ef328ffad0a150d50b40e103d3f685 (patch)
tree60579fe23c778208f6213090c9e50bed34bb285e /src/main.rs
parent1277a0733f812fcc84a746cedb16c1317036988e (diff)
replaces git repo config with routes config
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs52
1 files changed, 20 insertions, 32 deletions
diff --git a/src/main.rs b/src/main.rs
index 42cfaae..5dd5db5 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -4,47 +4,35 @@ use dirs::config_dir;
#[macro_use] extern crate rocket;
-mod build;
-mod config;
+mod routes;
-use config::read_config;
+use anyhow::Result;
+use routes::read_routes;
use rocket::{State, http::Status};
-use crate::{build::{BuildError, pull_or_clone_and_build_and_push}, config::Config};
-
const BIN_NAME: &str = "build-joeac";
#[launch]
fn rocket() -> _ {
- let config_path: PathBuf = config_dir().unwrap()
- .join(BIN_NAME).join(BIN_NAME).with_added_extension("toml");
- let config = read_config(&config_path).inspect_err(|err|
- eprintln!("Failed to read config. Error: {}\nProceeding with defaults", err))
- .unwrap_or(Config::default());
-
- rocket::build().manage(config).mount("/", routes![index])
+ let routes_path: PathBuf = config_dir().unwrap().join(BIN_NAME).join("routes");
+ let routes = read_routes(&routes_path).expect("Failed to read routes config");
+ rocket::build().manage(routes).mount("/", routes![index])
}
-#[get("/<remote_git_repo..>")]
-fn index(remote_git_repo: PathBuf, config: &State<Config>) -> (Status, String) {
- match remote_git_repo.to_str() {
- None => (Status::BadRequest, format!("Failed to convert request path to unicode: {:?}", remote_git_repo)),
- Some(remote_git_repo) => match config.repositories.iter().find(|repo| repo.remote_git_repo.eq(remote_git_repo)) {
- None => (Status::NotFound, format!("Remote git repository not configured: {remote_git_repo}")),
- Some(repo) => match pull_or_clone_and_build_and_push(repo) {
- Err(BuildError::FailedToOpenOrClone(open_err, clone_err)) => (
- Status::InternalServerError,
- format!(
- "Failed to open or clone git repository. Error opening: {:#?}\n\nError cloning: {:#?}",
- open_err,
- clone_err)
- ),
- Err(BuildError::FailedToPull(err)) => (
- Status::InternalServerError,
- format!("Failed to pull git repository. Error: {:#?}", err),
- ),
- Ok(()) => (Status::Ok, String::from("Pulled, built and pushed image")),
- }
+#[get("/<req_path..>")]
+fn index(req_path: PathBuf, routes: &State<Vec<String>>) -> (Status, String) {
+ match req_path.to_str().map(String::from) {
+ None => (Status::BadRequest, format!("Failed to convert request path to unicode: {:?}", req_path)),
+ Some(req_path) => match routes.iter().find(|&route| req_path.eq(route)) {
+ None => (Status::NotFound, format!("Route not configured: {req_path}")),
+ Some(route) => match execute_route(route) {
+ Ok(_) => todo!(),
+ Err(_) => todo!(),
+ },
}
}
}
+
+fn execute_route(route: &str) -> Result<()> {
+ todo!();
+}