Skip to content

Commit

Permalink
Merge branch 'release/v0.13.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
ja573 committed Jan 17, 2025
2 parents 2e49621 + ca01090 commit 9d36a16
Show file tree
Hide file tree
Showing 18 changed files with 143 additions and 52 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [[0.13.5]](https://github.com/thoth-pub/thoth/releases/tag/v0.13.5) - 2025-01-17
### Changed
- [665](https://github.com/thoth-pub/thoth/pull/665) - Removed unnecessary `map_or()` to comply with [`rustc 1.84.0`](https://github.com/rust-lang/rust/releases/tag/1.84.0)
- [666](https://github.com/thoth-pub/thoth/pull/666) - Upgrade rust to `1.84.0` in production `Dockerfile`

### Added
- [666](https://github.com/thoth-pub/thoth/pull/666) - CLI subcommand `thoth cache delete` to delete cached metadata records by specification ID

## [[0.13.4]](https://github.com/thoth-pub/thoth/releases/tag/v0.13.4) - 2024-12-11
### Added
Expand Down
29 changes: 15 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "thoth"
version = "0.13.4"
version = "0.13.5"
authors = ["Javier Arias <[email protected]>", "Ross Higman <[email protected]>"]
edition = "2021"
license = "Apache-2.0"
Expand All @@ -15,11 +15,12 @@ maintenance = { status = "actively-developed" }
members = ["thoth-api", "thoth-api-server", "thoth-app", "thoth-app-server", "thoth-client", "thoth-errors", "thoth-export-server"]

[dependencies]
thoth-api = { version = "=0.13.4", path = "thoth-api", features = ["backend"] }
thoth-api-server = { version = "=0.13.4", path = "thoth-api-server" }
thoth-app-server = { version = "=0.13.4", path = "thoth-app-server" }
thoth-errors = { version = "=0.13.4", path = "thoth-errors" }
thoth-export-server = { version = "=0.13.4", path = "thoth-export-server" }
thoth-api = { version = "=0.13.5", path = "thoth-api", features = ["backend"] }
thoth-api-server = { version = "=0.13.5", path = "thoth-api-server" }
thoth-app-server = { version = "=0.13.5", path = "thoth-app-server" }
thoth-errors = { version = "=0.13.5", path = "thoth-errors" }
thoth-export-server = { version = "=0.13.5", path = "thoth-export-server" }
clap = { version = "4.5.21", features = ["cargo", "env"] }
dialoguer = { version = "0.11.0", features = ["password"] }
dotenv = "0.15.0"
tokio = { version = "1.43.0", features = ["rt", "rt-multi-thread", "macros"] }
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG MUSL_IMAGE=clux/muslrust:1.83.0-stable
ARG MUSL_IMAGE=clux/muslrust:1.84.0-stable

FROM ${MUSL_IMAGE} as build

Expand Down
58 changes: 49 additions & 9 deletions src/bin/thoth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@ use clap::{crate_authors, crate_version, value_parser, Arg, ArgAction, Command};
use dialoguer::{console::Term, theme::ColorfulTheme, Input, MultiSelect, Password, Select};
use dotenv::dotenv;
use std::env;
use thoth::api::account::model::{AccountData, LinkedPublisher};
use thoth::api::account::service::{all_emails, all_publishers, register, update_password};
use thoth::api::db::{init_pool, revert_migrations, run_migrations};
use thoth::api_server;
use thoth::app_server;
use thoth::export_server;
use thoth_errors::ThothResult;
use thoth::{
api::{
account::{
model::{AccountData, LinkedPublisher},
service::{all_emails, all_publishers, register, update_password},
},
db::{init_pool as init_pg_pool, revert_migrations, run_migrations},
redis::{del, init_pool as init_redis_pool, scan_match},
},
api_server, app_server,
errors::{ThothError, ThothResult},
export_server, ALL_SPECIFICATIONS,
};

fn database_argument() -> Arg {
Arg::new("db")
Expand Down Expand Up @@ -220,6 +226,14 @@ fn thoth_commands() -> Command {
.subcommand(Command::new("register").about("Create a new user account"))
.subcommand(Command::new("password").about("Reset a password")),
)
.subcommand(
Command::new("cache")
.about("Manage cached records")
.arg(redis_argument())
.subcommand_required(true)
.arg_required_else_help(true)
.subcommand(Command::new("delete").about("Delete cached records")),
)
}

fn main() -> ThothResult<()> {
Expand Down Expand Up @@ -326,7 +340,7 @@ fn main() -> ThothResult<()> {
let database_url = account_matches.get_one::<String>("db").unwrap();
match account_matches.subcommand() {
Some(("register", _)) => {
let pool = init_pool(database_url);
let pool = init_pg_pool(database_url);

let name = Input::new()
.with_prompt("Enter given name")
Expand Down Expand Up @@ -383,7 +397,7 @@ fn main() -> ThothResult<()> {
register(account_data, linked_publishers, &pool).map(|_| ())
}
Some(("password", _)) => {
let pool = init_pool(database_url);
let pool = init_pg_pool(database_url);
let all_emails =
all_emails(&pool).expect("No user accounts present in database.");
let email_selection = Select::with_theme(&ColorfulTheme::default())
Expand All @@ -402,6 +416,32 @@ fn main() -> ThothResult<()> {
_ => unreachable!(),
}
}
Some(("cache", cache_matches)) => match cache_matches.subcommand() {
Some(("delete", _)) => {
let redis_url = cache_matches.get_one::<String>("redis").unwrap();
let pool = init_redis_pool(redis_url);
let chosen: Vec<usize> = MultiSelect::new()
.items(&ALL_SPECIFICATIONS)
.with_prompt("Select cached specifications to delete")
.interact_on(&Term::stdout())?;
// run a separate tokio runtime to avoid interfering with actix's threads
let runtime = tokio::runtime::Builder::new_multi_thread()
.worker_threads(1)
.enable_all()
.build()?;
runtime.block_on(async {
for index in chosen {
let specification = ALL_SPECIFICATIONS.get(index).unwrap();
let keys = scan_match(&pool, &format!("{}*", specification)).await?;
for key in keys {
del(&pool, &key).await?;
}
}
Ok::<(), ThothError>(())
})
}
_ => unreachable!(),
},
_ => unreachable!(),
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub use thoth_api as api;
pub use thoth_api_server::start_server as api_server;
pub use thoth_app_server::start_server as app_server;
pub use thoth_export_server::start_server as export_server;
pub use thoth_errors as errors;
pub use thoth_export_server::{start_server as export_server, ALL_SPECIFICATIONS};
6 changes: 3 additions & 3 deletions thoth-api-server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "thoth-api-server"
version = "0.13.4"
version = "0.13.5"
authors = ["Javier Arias <[email protected]>", "Ross Higman <[email protected]>"]
edition = "2021"
license = "Apache-2.0"
Expand All @@ -9,8 +9,8 @@ repository = "https://github.com/thoth-pub/thoth"
readme = "README.md"

[dependencies]
thoth-api = { version = "=0.13.4", path = "../thoth-api", features = ["backend"] }
thoth-errors = { version = "=0.13.4", path = "../thoth-errors" }
thoth-api = { version = "=0.13.5", path = "../thoth-api", features = ["backend"] }
thoth-errors = { version = "=0.13.5", path = "../thoth-errors" }
actix-web = "4.9"
actix-cors = "0.7.0"
actix-http = "3.9.0"
Expand Down
4 changes: 2 additions & 2 deletions thoth-api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "thoth-api"
version = "0.13.4"
version = "0.13.5"
authors = ["Javier Arias <[email protected]>", "Ross Higman <[email protected]>"]
edition = "2021"
license = "Apache-2.0"
Expand All @@ -15,7 +15,7 @@ maintenance = { status = "actively-developed" }
backend = ["diesel", "diesel-derive-enum", "diesel_migrations", "futures", "actix-web", "jsonwebtoken", "deadpool-redis"]

[dependencies]
thoth-errors = { version = "=0.13.4", path = "../thoth-errors" }
thoth-errors = { version = "=0.13.5", path = "../thoth-errors" }
actix-web = { version = "4.9", optional = true }
argon2rs = "0.2.5"
isbn2 = "0.4.0"
Expand Down
2 changes: 1 addition & 1 deletion thoth-api/src/graphql/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1985,7 +1985,7 @@ impl MutationRoot {
Some(vec![LocationPlatform::Thoth]),
)?
.first()
.map_or(false, |location| location.canonical);
.is_some_and(|location| location.canonical);
// Only superusers can update the canonical location when a Thoth Location Platform canonical location already exists
if has_canonical_thoth_location && data.canonical && !context.account_access.is_superuser {
return Err(ThothError::ThothUpdateCanonicalError.into());
Expand Down
34 changes: 34 additions & 0 deletions thoth-api/src/redis.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use deadpool_redis::{redis::AsyncCommands, Config, Connection, Pool};
use futures::StreamExt;
use thoth_errors::ThothResult;

pub type RedisPool = Pool;
Expand Down Expand Up @@ -31,6 +32,12 @@ pub async fn del(pool: &RedisPool, key: &str) -> ThothResult<String> {
con.del(key).await.map_err(Into::into)
}

pub async fn scan_match(pool: &RedisPool, pattern: &str) -> ThothResult<Vec<String>> {
let mut con = create_connection(pool).await?;
let keys: Vec<String> = con.scan_match(pattern).await?.collect().await;
Ok(keys)
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -73,4 +80,31 @@ mod tests {
let get_result = get(&pool, test_key).await;
assert!(get_result.is_err());
}

#[tokio::test]
async fn test_del() {
let pool = get_pool().await;
let test_key = "test_key_to_delete";
let test_value = "test_value";
set(&pool, test_key, test_value).await.unwrap();

let del_result = del(&pool, test_key).await;
assert!(del_result.is_ok());
let get_result = get(&pool, test_key).await;
assert!(get_result.is_err());
}

#[tokio::test]
async fn test_scan_match() {
let pool = get_pool().await;
set(&pool, "onix_3.0::key1", "value1").await.unwrap();
set(&pool, "onix_3.0::key2", "value2").await.unwrap();
set(&pool, "onix_3.0::key3", "value3").await.unwrap();

let keys = scan_match(&pool, "onix_3.0::*").await.unwrap();
assert_eq!(keys.len(), 3);
assert!(keys.contains(&"onix_3.0::key1".to_string()));
assert!(keys.contains(&"onix_3.0::key2".to_string()));
assert!(keys.contains(&"onix_3.0::key3".to_string()));
}
}
2 changes: 1 addition & 1 deletion thoth-app-server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "thoth-app-server"
version = "0.13.4"
version = "0.13.5"
authors = ["Javier Arias <[email protected]>", "Ross Higman <[email protected]>"]
edition = "2021"
license = "Apache-2.0"
Expand Down
6 changes: 3 additions & 3 deletions thoth-app/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "thoth-app"
version = "0.13.4"
version = "0.13.5"
authors = ["Javier Arias <[email protected]>", "Ross Higman <[email protected]>"]
edition = "2021"
license = "Apache-2.0"
Expand Down Expand Up @@ -29,8 +29,8 @@ semver = "1.0.23"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
uuid = { version = "1.11.0", features = ["serde", "v4", "js"] }
thoth-api = { version = "=0.13.4", path = "../thoth-api" }
thoth-errors = { version = "=0.13.4", path = "../thoth-errors" }
thoth-api = { version = "=0.13.5", path = "../thoth-api" }
thoth-errors = { version = "=0.13.5", path = "../thoth-errors" }

[build-dependencies]
dotenv = "0.15.0"
Loading

0 comments on commit 9d36a16

Please sign in to comment.