From a4fd24786c5bffb3106879498a44e024743d7e64 Mon Sep 17 00:00:00 2001 From: thevickypedia Date: Sat, 10 Feb 2024 17:00:35 -0600 Subject: [PATCH] Remove env var based build information Update README.md and help information --- Cargo.toml | 2 +- README.md | 18 ++++++++++++++++++ src/constant.rs | 40 ---------------------------------------- src/lib.rs | 5 ++--- src/squire/parser.rs | 19 ++++++++++++------- src/squire/startup.rs | 10 ++++------ 6 files changed, 37 insertions(+), 57 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f2a5513..f4524f8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ # https://doc.rust-lang.org/cargo/getting-started/first-steps.html#first-steps-with-cargo [package] name = "RuStream" -version = "0.0.1-test" +version = "0.0.1-temp" description = "An API written in Rust, to stream videos using Actix framework, via authenticated sessions" license = "MIT" documentation = "https://thevickypedia.github.io/RuStream" diff --git a/README.md b/README.md index cf2e88d..87e76b3 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,24 @@ curl -o asset -LH "Accept: application/octet-stream" "https://github.com/thevick #### Flags - `--filename` / `-f` - Filename (JSON) for the secrets config +- `--version` / `-v` - Get package version + +#### Config file +[RuStream][1] requires a JSON file with secrets loaded as key-value paris. + +
+Sample content of JSON file + +```json +{ + "authorization": {"rustic": "S0m3rAn0mP@ssW0rD"}, + "video_source": "/Users/hannibal/Downloads/stream", + "video_port": 5883, + "file_formats": [".mov", ".mp4", ".mkv"], + "workers": 10 +} +``` +
## Crate https://crates.io/crates/RuStream diff --git a/src/constant.rs b/src/constant.rs index f0e4050..cfb1b8d 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -1,4 +1,3 @@ -use std::{env, path}; use std::collections::HashMap; use std::sync::Mutex; @@ -8,45 +7,6 @@ use minijinja::Environment; use crate::template; -pub fn get_binary() -> String { - let binary = env::args().next().unwrap(); - path::Path::new(&binary).file_name().unwrap().to_str().unwrap().to_string() -} - -#[derive(Debug)] -pub struct Cargo { - pub binary: String, - pub manifest_dir: String, - pub authors: Vec, - pub description: String, - pub homepage: String, - pub pkg_name: String, - pub pkg_repo: String, - pub pkg_version: String, - pub pkg_version_major: String, - pub pkg_version_minor: String, - pub pkg_version_patch: String, - pub pkg_version_pre: String, -} - -pub fn build_info() -> Cargo { - let cargo = Cargo { - binary: get_binary(), - manifest_dir: env::var("CARGO_MANIFEST_DIR").unwrap_or("NA".to_string()), - authors: env::var("CARGO_PKG_AUTHORS").unwrap_or_default().split(',').map(String::from).collect(), - description: env::var("CARGO_PKG_DESCRIPTION").unwrap_or("NA".to_string()), - homepage: env::var("CARGO_PKG_HOMEPAGE").unwrap_or("NA".to_string()), - pkg_name: env::var("CARGO_PKG_NAME").unwrap_or("NA".to_string()), - pkg_repo: env::var("CARGO_PKG_REPOSITORY").unwrap_or("NA".to_string()), - pkg_version: env::var("CARGO_PKG_VERSION").unwrap_or("NA".to_string()), - pkg_version_major: env::var("CARGO_PKG_VERSION_MAJOR").unwrap_or("NA".to_string()), - pkg_version_minor: env::var("CARGO_PKG_VERSION_MINOR").unwrap_or("NA".to_string()), - pkg_version_patch: env::var("CARGO_PKG_VERSION_PATCH").unwrap_or("NA".to_string()), - pkg_version_pre: env::var("CARGO_PKG_VERSION_PRE").unwrap_or("NA".to_string()), - }; - cargo -} - lazy_static! { pub static ref FERNET: Fernet = Fernet::new(&generate_key()).unwrap(); } diff --git a/src/lib.rs b/src/lib.rs index 19cfddf..16fff2a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,9 +14,8 @@ mod routes; pub async fn start() -> io::Result<()> { let args = squire::parser::arguments(); - let build_info = constant::build_info(); - squire::startup::init_logger(args.debug, &build_info); - println!("Welcome to RuStream [v{}] - {}", build_info.pkg_version, build_info.description); + squire::startup::init_logger(args.debug); + println!("Welcome to RuStream - A Rust API, to stream videos using Actix framework, via authenticated sessions"); let arts = [squire::ascii_art::DOG, squire::ascii_art::DOLPHIN, squire::ascii_art::HORSE]; println!("{}", arts.choose(&mut rand::thread_rng()).unwrap()); diff --git a/src/squire/parser.rs b/src/squire/parser.rs index d190457..759f09d 100644 --- a/src/squire/parser.rs +++ b/src/squire/parser.rs @@ -38,15 +38,20 @@ pub fn arguments() -> Args { debug = true; } "-h" | "--help" => { - let helper = "\nMandatory Args:\n - authorization: Dictionary of key-value pairs with username as key and password as value.\n + let helper = "RuStream takes the arguments, debug, \ + --filename/-f and --version/-v\n\n\ + debug: Optional flag to enable debug level logging\n\ + --filename: JSON filename with the following arguments as a feed.\n\ + --version: Get the package version.\n\ + \nMandatory Args:\n + authorization: Dictionary of key-value pairs with username as key and password as value. video_source: Source path for video files.\n\n\ Optional Args:\n - video_host: IP address to host the video. Defaults to 127.0.0.1\n - video_port: Port number to host the application. Defaults to 8000\n - file_formats: Sequence of supported video file formats. Defaults to (.mp4, .mov)\n - workers: Number of workers to spin up the uvicorn server. Defaults to 1\n - website: List of websites (supports regex) to add to CORS configuration. Required only if tunneled via CDN\n\n" + video_host: IP address to host the video. Defaults to 127.0.0.1 + video_port: Port number to host the application. Defaults to 8000 + file_formats: Sequence of supported video file formats. Defaults to (.mp4, .mov) + workers: Number of workers to spin up the server. Defaults to the number of physical cores. + website: List of websites (supports regex) to add to CORS configuration. Required only if tunneled via CDN\n" // todo: to be implemented .to_string(); println!("{}", helper); exit(0) diff --git a/src/squire/startup.rs b/src/squire/startup.rs index 4425cdb..62ec4d0 100644 --- a/src/squire/startup.rs +++ b/src/squire/startup.rs @@ -1,20 +1,17 @@ use std::{env, path}; use std::sync::Arc; -use crate::constant; use crate::squire::parser::Args; use crate::squire::settings::Config; -pub fn init_logger(debug: bool, build_info: &constant::Cargo) { +pub fn init_logger(debug: bool) { let logging_level; if debug { - logging_level = format!("actix_web=debug,actix_server=info,{}=debug,{}=debug", - build_info.binary, build_info.pkg_name); + logging_level = "actix_web=debug,actix_server=info,stream=debug,RuStream=debug"; env::set_var("RUST_BACKTRACE", "1"); } else { // set actix logging to warning mode since it becomes too noisy when streaming a giant video file - logging_level = format!("actix_web=warn,actix_server=warn,{}=info,{}=info", - build_info.binary, build_info.pkg_name); + logging_level = "actix_web=warn,actix_server=warn,stream=info,RuStream=info"; env::set_var("RUST_BACKTRACE", "0"); } env::set_var("RUST_LOG", logging_level); @@ -23,6 +20,7 @@ pub fn init_logger(debug: bool, build_info: &constant::Cargo) { pub fn get_config(args: Args) -> Arc { let filename = if args.filename.is_empty() { + log::warn!("Missing 'filename' argument, assuming default ('config.json')"); "config.json".to_string() } else { args.filename