Skip to content

Commit

Permalink
Remove env var based build information
Browse files Browse the repository at this point in the history
Update README.md and help information
  • Loading branch information
dormant-user committed Feb 10, 2024
1 parent 6d0bd96 commit a4fd247
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 57 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<details>
<summary><i><strong>Sample content of JSON file</strong></i></summary>

```json
{
"authorization": {"rustic": "S0m3rAn0mP@ssW0rD"},
"video_source": "/Users/hannibal/Downloads/stream",
"video_port": 5883,
"file_formats": [".mov", ".mp4", ".mkv"],
"workers": 10
}
```
</details>

## Crate
https://crates.io/crates/RuStream
Expand Down
40 changes: 0 additions & 40 deletions src/constant.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::{env, path};
use std::collections::HashMap;
use std::sync::Mutex;

Expand All @@ -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<String>,
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();
}
Expand Down
5 changes: 2 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
19 changes: 12 additions & 7 deletions src/squire/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 4 additions & 6 deletions src/squire/startup.rs
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -23,6 +20,7 @@ pub fn init_logger(debug: bool, build_info: &constant::Cargo) {

pub fn get_config(args: Args) -> Arc<Config> {
let filename = if args.filename.is_empty() {
log::warn!("Missing 'filename' argument, assuming default ('config.json')");
"config.json".to_string()
} else {
args.filename
Expand Down

0 comments on commit a4fd247

Please sign in to comment.