Skip to content

Commit

Permalink
[0.5.1] Dependency Update & Minor Endpoint Update (#35)
Browse files Browse the repository at this point in the history
* chore: bump dependency versions

* chore: bump webreg scraper version

* feat: remove term query param for /terms endpoint

* style: run cargo fmt + cargo clippy
  • Loading branch information
ewang2002 authored Nov 13, 2024
1 parent c28c5bc commit 4ebfb83
Show file tree
Hide file tree
Showing 12 changed files with 1,037 additions and 456 deletions.
1,421 changes: 1,002 additions & 419 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions crates/authmanager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ version = "0.5.0"
edition = "2021"

[dependencies]
clap = { version = "4.4", features = ["derive"] }
tabled = "0.14"
clap = { version = "4.5", features = ["derive"] }
tabled = "0.16"
basicauth = { path = "../basicauth" }
4 changes: 2 additions & 2 deletions crates/authmanager/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ fn main() {
CliSubCmd::ShowAll { show_tokens } => {
let mut table_builder = Builder::new();
if show_tokens.unwrap_or(false) {
table_builder.set_header(["Prefix", "Token", "Created", "Expired", "Description"]);
table_builder.push_record(["Prefix", "Token", "Created", "Expired", "Description"]);
} else {
table_builder.set_header(["Prefix", "Created", "Expired", "Description"]);
table_builder.push_record(["Prefix", "Created", "Expired", "Description"]);
}

let entries = manager.get_all_entries();
Expand Down
4 changes: 2 additions & 2 deletions crates/basicauth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rusqlite = { version = "0.29", features = ["bundled", "chrono"] }
rusqlite = { version = "0.32", features = ["bundled", "chrono"] }
chrono = "0.4"
uuid = { version = "1.4", features = ["v4", "fast-rng"] }
uuid = { version = "1.11", features = ["v4", "fast-rng"] }
10 changes: 5 additions & 5 deletions crates/webreg/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
[package]
name = "webreg"
version = "0.5.0"
version = "0.5.1"
authors = ["Edward Wang"]
edition = "2021"
description = "A scraper and API for UC San Diego's WebReg enrollment system."
repository = "https://github.com/ewang2002/webreg_scraper"

[dependencies]
anyhow = "1.0"
axum = "0.6"
axum = "0.7"
chrono = "0.4"
futures = "0.3"
reqwest = "0.11"
reqwest = "0.12"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tokio = { version = "1.17", features = ["rt-multi-thread", "macros", "signal"] }
tokio = { version = "1.41", features = ["rt-multi-thread", "macros", "signal"] }
tracing = "0.1"
tracing-subscriber = "0.3"
webweg = { version = "0.9", features = ["multi"] }
basicauth = { path = "../basicauth", optional = true }
[dev-dependencies]
axum-macros = "0.3"
axum-macros = "0.4"

[features]
default = []
Expand Down
6 changes: 3 additions & 3 deletions crates/webreg/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ async fn main() -> ExitCode {
state.api_base_endpoint.port
);

axum::Server::bind(&addr.unwrap())
.serve(create_router(state.clone()).into_make_service())
let listener = tokio::net::TcpListener::bind(&addr.unwrap()).await.unwrap();
axum::serve(listener, create_router(state.clone()).into_make_service())
.with_graceful_shutdown(shutdown_signal(state))
.await
.unwrap();
Expand All @@ -86,7 +86,7 @@ async fn main() -> ExitCode {
///
/// # Parameters
/// - `state`: The wrapper state, which is a reference to all valid scrapers and other relevant
/// information.
/// information.
async fn shutdown_signal(state: Arc<WrapperState>) {
tokio::signal::ctrl_c()
.await
Expand Down
10 changes: 5 additions & 5 deletions crates/webreg/src/server/middleware/auth_validator.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::types::WrapperState;
use axum::extract::State;
use axum::http::{header, Request, StatusCode};
use axum::extract::{Request, State};
use axum::http::{header, StatusCode};
use axum::middleware::Next;
use axum::response::IntoResponse;
use axum::Json;
Expand All @@ -10,10 +10,10 @@ use std::sync::Arc;
use tracing::log::{info, warn};

#[tracing::instrument(skip(state, req, next))]
pub async fn auth<B>(
pub async fn auth(
State(state): State<Arc<WrapperState>>,
mut req: Request<B>,
next: Next<B>,
mut req: Request,
next: Next,
) -> Result<impl IntoResponse, (StatusCode, Json<Value>)> {
info!("Auth middleware invoked.");
let token = req
Expand Down
9 changes: 5 additions & 4 deletions crates/webreg/src/server/middleware/cookie_validator.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use axum::extract::Request;
use axum::http::header::COOKIE;
use axum::http::{HeaderMap, Request, StatusCode};
use axum::http::{HeaderMap, StatusCode};
use axum::middleware::Next;
use axum::response::IntoResponse;
use axum::Json;
Expand All @@ -8,10 +9,10 @@ use tracing::log::info;

/// A middleware function that checks if the wrapper is able to handle requests.
#[tracing::instrument(skip(req, next))]
pub async fn check_cookies<B>(
pub async fn check_cookies(
header_map: HeaderMap,
req: Request<B>,
next: Next<B>,
req: Request,
next: Next,
) -> Result<impl IntoResponse, (StatusCode, Json<Value>)> {
info!("Validating if cookie header is available.");
if let Some(header) = header_map.get(COOKIE) {
Expand Down
10 changes: 5 additions & 5 deletions crates/webreg/src/server/middleware/running_validator.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::sync::Arc;

use axum::extract::State;
use axum::http::{Request, StatusCode};
use axum::extract::{Request, State};
use axum::http::StatusCode;
use axum::middleware::Next;
use axum::response::IntoResponse;
use axum::Json;
Expand All @@ -12,10 +12,10 @@ use crate::types::WrapperState;

/// A middleware function that checks if the wrapper is able to handle requests.
#[tracing::instrument(skip(state, req, next))]
pub async fn validate_wrapper_running<B>(
pub async fn validate_wrapper_running(
State(state): State<Arc<WrapperState>>,
req: Request<B>,
next: Next<B>,
req: Request,
next: Next,
) -> Result<impl IntoResponse, (StatusCode, Json<Value>)> {
info!("Validating if API is ready.");
if state.is_running() {
Expand Down
10 changes: 5 additions & 5 deletions crates/webreg/src/server/middleware/term_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
use std::sync::Arc;

use axum::extract::{Path, State};
use axum::http::{Request, StatusCode};
use axum::extract::{Path, Request, State};
use axum::http::StatusCode;
use axum::middleware::Next;
use axum::response::IntoResponse;
use axum::Json;
Expand All @@ -15,11 +15,11 @@ use crate::types::WrapperState;
/// A middleware function that validates a term that's passed as part of the path
/// is supported by the server.
#[tracing::instrument(skip(state, req, next))]
pub async fn validate_term<B>(
pub async fn validate_term(
Path(term): Path<String>,
State(state): State<Arc<WrapperState>>,
req: Request<B>,
next: Next<B>,
req: Request,
next: Next,
) -> Result<impl IntoResponse, (StatusCode, Json<Value>)> {
info!("Validating if term is supported.");
let term = term.to_uppercase();
Expand Down
2 changes: 1 addition & 1 deletion crates/webreg/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ pub fn create_router(app_state: Arc<WrapperState>) -> Router {
// Live WebReg router.
let webreg_router = Router::new()
.merge(parsed_router)
.route("/terms", get(ww_general::get_all_terms))
.layer(mw::from_fn_with_state(
app_state.clone(),
running_validator::validate_wrapper_running,
Expand All @@ -68,6 +67,7 @@ pub fn create_router(app_state: Arc<WrapperState>) -> Router {
let router = Router::new()
.route("/health", get(status::get_health))
.nest("/live/:term", webreg_router)
.route("/terms", get(ww_general::get_all_terms))
.route("/timing/:term", get(status::get_timing_stats))
.route("/login_stat/:stat", get(status::get_login_script_stats))
.with_state(app_state.clone());
Expand Down
3 changes: 0 additions & 3 deletions crates/webreg/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ impl WrapperState {
num_requests: Default::default(),
total_time_spent: Default::default(),
},
should_save: data.save_data_to_file,
})
.map(|data| (data.term.to_owned(), Arc::new(data)))
.collect();
Expand Down Expand Up @@ -167,8 +166,6 @@ pub struct TermInfo {
pub search_query: Vec<SearchRequestBuilder>,
/// Tracker stats. This field contains information on the performance of the scraper.
pub tracker: StatTracker,
/// Whether we should save data scraped for this term to a file.
pub should_save: bool,
}

/// A structure that represents a configuration file specifically for the scraper. See the
Expand Down

0 comments on commit 4ebfb83

Please sign in to comment.