Skip to content

Commit

Permalink
More restructure and docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
dormant-user committed Feb 17, 2024
1 parent 6088f95 commit 6ddb740
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ jobs:
run: cargo build --verbose
- name: Run tests verbose
if: env.release == 'false'
run: cargo test --verbose
run: cargo test --no-run --verbose

upload_assets:
needs: release
Expand Down Expand Up @@ -183,7 +183,7 @@ jobs:
export OPENSSL_STATIC="Yes"
export VCPKG_ROOT="${{ env.vcpkg_dir }}\installed\x64-windows-static"
fi
cargo test
cargo test --no-run
shell: bash

- name: Copy Artifacts (Windows)
Expand Down
1 change: 1 addition & 0 deletions src/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ lazy_static! {
/// Generates a random key, that can be safely passed to `Fernet::new()`
///
/// # Returns
///
/// Random key as a `String`
fn fernet_key() -> String {
Fernet::generate_key()
Expand Down
20 changes: 14 additions & 6 deletions src/routes/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ use actix_web::http::StatusCode;
use minijinja;
use serde::Serialize;

use crate::{constant, routes, squire};
use crate::routes::authenticator::AuthToken;
use crate::{constant, squire};

/// Struct for representing a JSON Response with a redirect URL.
#[derive(Serialize)]
Expand All @@ -35,7 +34,7 @@ pub struct DetailError {
/// * `401` - HttpResponse with an error message for failed authentication.
#[post("/login")]
pub async fn login(config: web::Data<Arc<squire::settings::Config>>, request: HttpRequest) -> HttpResponse {
let verified = routes::authenticator::verify_login(&request, &config);
let verified = squire::authenticator::verify_login(&request, &config);
if let Err(err) = verified {
let err_message = err.to_string();
log::warn!("Error response::{}", err_message);
Expand Down Expand Up @@ -72,6 +71,10 @@ pub async fn login(config: web::Data<Arc<squire::settings::Config>>, request: Ht
///
/// * `config` - Configuration data for the application.
/// * `request` - Actix HttpRequest containing information about the incoming request.
///
/// # Returns
///
/// Returns an `HTTPResponse` with the cookie for `session_token` reset if available.
#[get("/logout")]
pub async fn logout(config: web::Data<Arc<squire::settings::Config>>,
environment: web::Data<Arc<Mutex<minijinja::Environment<'static>>>>,
Expand All @@ -83,7 +86,7 @@ pub async fn logout(config: web::Data<Arc<squire::settings::Config>>,
response.content_type("text/html; charset=utf-8");

let rendered;
let auth_response = routes::authenticator::verify_token(&request, &config);
let auth_response = squire::authenticator::verify_token(&request, &config);
log::debug!("Session Validation Response: {}", auth_response.detail);

if auth_response.username != "NA" {
Expand Down Expand Up @@ -121,11 +124,16 @@ pub async fn logout(config: web::Data<Arc<squire::settings::Config>>,
///
/// * `config` - Configuration data for the application.
/// * `request` - Actix HttpRequest containing information about the incoming request.
///
/// # Returns
///
/// * `200` - Returns an `HTTPResponse` with the home/listing page if session token is valid.
/// * `401` - HttpResponse with an error message for failed authentication.
#[get("/home")]
pub async fn home(config: web::Data<Arc<squire::settings::Config>>,
environment: web::Data<Arc<Mutex<minijinja::Environment<'static>>>>,
request: HttpRequest) -> HttpResponse {
let auth_response = routes::authenticator::verify_token(&request, &config);
let auth_response = squire::authenticator::verify_token(&request, &config);
if !auth_response.ok {
return failed_auth(auth_response);
}
Expand Down Expand Up @@ -182,7 +190,7 @@ pub async fn error(environment: web::Data<Arc<Mutex<minijinja::Environment<'stat
/// # Returns
///
/// Returns an `HttpResponse` with a redirect, setting a cookie with the failure detail.
pub fn failed_auth(auth_response: AuthToken) -> HttpResponse {
pub fn failed_auth(auth_response: squire::authenticator::AuthToken) -> HttpResponse {
let mut response = HttpResponse::build(StatusCode::FOUND);
let detail = auth_response.detail;
let age = Duration::new(3, 0);
Expand Down
2 changes: 1 addition & 1 deletion src/routes/images.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ lazy_static! {
///
/// # Returns
///
/// - `HttpResponse`: Responds with the requested image content if found, or raises a 404.
/// Returns an `HttpResponse` with the requested image content if found, or raises a 404.
#[get("/images/{filename:.*}")]
pub async fn image_endpoint(request: HttpRequest, filename: web::Path<String>) -> HttpResponse {
// Log the incoming connection for monitoring purposes
Expand Down
2 changes: 1 addition & 1 deletion src/routes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ pub mod basics;
pub mod video;
/// Module for `/home`, `/login`, `/logout` and `/error` entrypoints.
pub mod auth;
pub mod authenticator;
/// Module to render images for the HTML pages requested via JavaScript.
pub mod images;
6 changes: 3 additions & 3 deletions src/routes/video.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ fn subtitles(true_path: PathBuf, relative_path: &String) -> Subtitles {
#[get("/track")]
pub async fn track(config: web::Data<Arc<squire::settings::Config>>,
request: HttpRequest, info: web::Query<Payload>) -> HttpResponse {
let auth_response = routes::authenticator::verify_token(&request, &config);
let auth_response = squire::authenticator::verify_token(&request, &config);
if !auth_response.ok {
return routes::auth::failed_auth(auth_response);
}
Expand Down Expand Up @@ -114,7 +114,7 @@ pub async fn track(config: web::Data<Arc<squire::settings::Config>>,
pub async fn stream(config: web::Data<Arc<squire::settings::Config>>,
environment: web::Data<Arc<Mutex<Environment<'static>>>>,
request: HttpRequest, video_path: web::Path<String>) -> HttpResponse {
let auth_response = routes::authenticator::verify_token(&request, &config);
let auth_response = squire::authenticator::verify_token(&request, &config);
if !auth_response.ok {
return routes::auth::failed_auth(auth_response);
}
Expand Down Expand Up @@ -210,7 +210,7 @@ pub async fn stream(config: web::Data<Arc<squire::settings::Config>>,
#[get("/video")]
pub async fn streaming_endpoint(config: web::Data<Arc<squire::settings::Config>>,
request: HttpRequest, info: web::Query<Payload>) -> HttpResponse {
let auth_response = routes::authenticator::verify_token(&request, &config);
let auth_response = squire::authenticator::verify_token(&request, &config);
if !auth_response.ok {
return routes::auth::failed_auth(auth_response);
}
Expand Down
File renamed without changes.
11 changes: 11 additions & 0 deletions src/squire/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
/// Module for the commandline interface creation kit that parses the commandline arguments
pub mod parser;
/// Module for the web data configuration that holds the secrets required by the application.
pub mod settings;
/// Module that initializes the logger and loads the configuration into a dedicated Struct.
pub mod startup;
/// Module for the functions that handle encryption/encoding and decryption/decoding.
pub mod secure;
/// Module for the function that logs the incoming connection information.
pub mod logger;
/// Module for the functions that yield an ASCII art to print during startup.
pub mod ascii_art;
/// Module for the CORS middleware configuration.
pub mod middleware;
/// Module for the function that converts the subtitles from `srt` to `vtt` file format.
pub mod subtitles;
/// Module for the functions that scan the video source and render the filenames as struct.
pub mod content;
/// Module that handles the authentication and
pub mod authenticator;

0 comments on commit 6ddb740

Please sign in to comment.