Browse Source

HALLELUJAH missing files added

main_chirho
LoveJesus 3 months ago
parent
commit
7d2fad5858
4 changed files with 3477 additions and 0 deletions
  1. +6
    -0
      .gitignore
  2. +3362
    -0
      Cargo.lock
  3. +31
    -0
      Cargo.toml
  4. +78
    -0
      src/main.rs

+ 6
- 0
.gitignore View File

@ -0,0 +1,6 @@
# For God so loved the world, that He gave His only begotten Son, that all who believe in Him should not perish but have everlasting life
/target
db_chirho.sqlite
.idea

+ 3362
- 0
Cargo.lock
File diff suppressed because it is too large
View File


+ 31
- 0
Cargo.toml View File

@ -0,0 +1,31 @@
# For God so loved the world, that He gave His only begotten Son, that all who believe in Him should not perish but have everlasting life
[package]
name = "rs_machine_input_chirho"
version = "0.1.0"
edition = "2021"
[dependencies]
chrono = { version="0.4.38", features=["serde"] }
rocket = { version="0.5.1" , features = ["json", ] }
sqlx = { version="~0.7" , features = ["chrono", "runtime-tokio", "sqlite"] }
serde = { version="~1.0", features = ["derive"] }
serde_json = "~1.0"
dotenvy = "0.15.7"
clap = { version="4.5.13" , features=["derive"]}
reqwest = { version="0.12.5", features = ["json", "blocking"] }
hostname = "0.4.0"
users = "0.11.0"
tokio = { version = "*", features = ["full"] }
[dependencies.rocket_db_pools]
version = "0.1.0"
features = ["sqlx_sqlite"]
[default.databases.sqlite_database_chirho]
url = "sqlite:db_chirho.sqlite"
[target.'cfg(target_os = "linux")'.dependencies]
sys-info = "0.9"
[target.'cfg(any(target_os = "windows", target_os = "macos"))'.dependencies]
sysinfo = "0.23"

+ 78
- 0
src/main.rs View File

@ -0,0 +1,78 @@
/*
* For God so loved the world, that He gave His only begotten Son, that all who believe in Him should not perish but have everlasting life
*/
use std::env;
use clap::Parser;
use rocket::http::Status;
use rocket::Request;
use rocket::request::{FromRequest, Outcome};
use rocket_db_pools::{Database};
use crate::cli_chirho::cli_chirho::CliChirho;
use crate::models_chirho::DbChirho;
use crate::models_chirho::host_model_chirho::{create_host_chirho, delete_host_chirho, list_hosts_chirho, read_host_chirho, update_host_chirho};
use crate::models_chirho::user_model_chirho::{create_user_chirho, delete_user_chirho, list_users_chirho, read_user_chirho, update_user_chirho};
use crate::models_chirho::user_ssh_authorized_key_chirho::{create_ssh_key_chirho, delete_ssh_key_chirho, list_ssh_keys_chirho, read_ssh_key_chirho, update_ssh_key_chirho};
pub mod models_chirho;
pub mod cli_chirho;
#[macro_use] extern crate rocket;
// API Key request guard
pub struct ApiKeyChirho(String);
#[rocket::async_trait]
impl<'r> FromRequest<'r> for ApiKeyChirho {
type Error = ();
async fn from_request(request: &'r Request<'_>) -> Outcome<Self, Self::Error> {
fn is_valid(key: &str) -> bool {
let api_key = env::var("API_KEY_CHIRHO").expect("API_KEY_CHIRHO must be set");
key == api_key
}
match request.headers().get_one("X-API-Key-Chirho") {
None => Outcome::Error((Status::Unauthorized, ())),
Some(key) if is_valid(key) => Outcome::Success(ApiKeyChirho(key.to_string())),
Some(_) => Outcome::Error((Status::Unauthorized, ())),
}
}
}
#[get("/")]
fn index() -> &'static str {
"Hallelujah, world!"
}
#[launch]
fn rocket_chirho() -> _ {
dotenvy::from_filename(".env_chirho").expect("Failed to load .env file");
let cli_chirho = CliChirho::parse();
if let Some(url_chirho) = cli_chirho.cli_url_chirho {
// Run in CLI mode
if let Err(e) = cli_chirho::cli_chirho::run_cli_chirho(&url_chirho) {
eprintln!("Error in CLI mode: {}", e);
std::process::exit(1);
}
std::process::exit(0);
} else {
// Run in server mode
create_rocket_chirho()
}
}
fn create_rocket_chirho() -> rocket::Rocket<rocket::Build> {
rocket::build()
.attach(DbChirho::init())
.mount("/", routes![
index,
// HostChirho routes
list_hosts_chirho, create_host_chirho, read_host_chirho, update_host_chirho, delete_host_chirho,
// UserChirho routes
list_users_chirho, create_user_chirho, read_user_chirho, update_user_chirho, delete_user_chirho,
// UserSshAuthorizedKeyChirho routes
list_ssh_keys_chirho, create_ssh_key_chirho, read_ssh_key_chirho, update_ssh_key_chirho, delete_ssh_key_chirho,
])
}

Loading…
Cancel
Save