Clion auto-optimize imports, remove dead imports, Clippy lint

This commit is contained in:
Brandon Thomas committed 2023-09-20 01:39:58 -04:00
1 parent 226f111a00
commit 699bb6a6a7
695 files changed
+3961 -3624

No files matched your search

+3
View File
@@ -39,6 +39,9 @@ deny = [
"clippy::redundant_field_names", # Lint: Duplicate names is a burden when reading: you wonder why they're dupes.
"clippy::redundant_static_lifetimes", # Lint: feels more modern to elide static lifetimes
# Rust
"unused_imports", # These are easy to automatically cull
# Possible:
# "clippy::ptr_arg",
# "clippy::too_many_lines" (note: this is configurable)
@@ -1,6 +1,7 @@
use crockford::crockford_entropy_lower;
use crate::public::public_path::PublicPath;
use crate::util::hashed_directory_path_long_string::hashed_directory_path_long_string;
use crockford::crockford_entropy_lower;
// TODO: Generate these from a macro.
@@ -1,7 +1,9 @@
use std::path::PathBuf;
use crockford::crockford_entropy_lower;
use crate::public::media_files::directory::MediaFileBucketDirectory;
use crate::public::public_path::PublicPath;
use crockford::crockford_entropy_lower;
use std::path::PathBuf;
const ORIGINAL_FILE_BASENAME : &str = "file.bin";
@@ -57,9 +59,10 @@ impl MediaFileBucketPath {
#[cfg(test)]
mod tests {
use crate::public::media_files::original_file::MediaFileBucketPath;
use std::path::PathBuf;
use crate::public::media_files::original_file::MediaFileBucketPath;
#[test]
pub fn generate_new_entropy() {
let file = MediaFileBucketPath::generate_new();
@@ -1,6 +1,7 @@
use crockford::crockford_entropy_lower;
use crate::public::public_path::PublicPath;
use crate::util::hashed_directory_path_long_string::hashed_directory_path_long_string;
use crockford::crockford_entropy_lower;
// TODO: Generate these from a macro.
@@ -1,7 +1,9 @@
use std::path::PathBuf;
use crockford::crockford_entropy_lower;
use crate::public::media_uploads::directory::MediaUploadDirectory;
use crate::public::public_path::PublicPath;
use crockford::crockford_entropy_lower;
use std::path::PathBuf;
const ORIGINAL_FILE_BASENAME : &str = "original_upload.bin";
@@ -57,9 +59,10 @@ impl MediaUploadOriginalFilePath {
#[cfg(test)]
mod tests {
use crate::public::media_uploads::original_file::MediaUploadOriginalFilePath;
use std::path::PathBuf;
use crate::public::media_uploads::original_file::MediaUploadOriginalFilePath;
#[test]
pub fn generate_new_entropy() {
let file = MediaUploadOriginalFilePath::generate_new();
@@ -1,7 +1,9 @@
use std::path::PathBuf;
use crockford::crockford_entropy_lower;
use crate::public::public_path::PublicPath;
use crate::public::voice_conversion_results::directory::VoiceConversionResultDirectory;
use crockford::crockford_entropy_lower;
use std::path::PathBuf;
const ORIGINAL_FILE_PREFIX : &str = "fakeyou_";
const ORIGINAL_FILE_SUFFIX : &str = ".wav";
@@ -61,9 +63,10 @@ impl VoiceConversionResultOriginalFilePath {
#[cfg(test)]
mod tests {
use crate::public::voice_conversion_results::original_file::VoiceConversionResultOriginalFilePath;
use std::path::PathBuf;
use crate::public::voice_conversion_results::original_file::VoiceConversionResultOriginalFilePath;
#[test]
pub fn generate_new_entropy() {
let file = VoiceConversionResultOriginalFilePath::generate_new();
@@ -1,6 +1,7 @@
use std::path::PathBuf;
use errors::AnyhowResult;
use errors::bail;
use std::path::PathBuf;
#[deprecated(note = "this is a messy function and should be avoided")]
pub (crate) fn hash_to_bucket_path(file_hash: &str,
@@ -28,9 +29,10 @@ pub (crate) fn hash_to_bucket_path(file_hash: &str,
#[cfg(test)]
mod tests {
use crate::util::hash_to_bucket_path::hash_to_bucket_path;
use std::path::PathBuf;
use crate::util::hash_to_bucket_path::hash_to_bucket_path;
#[test]
fn test_bucket_without_root() {
assert_eq!(
@@ -1,6 +1,7 @@
use crate::util::hash_to_bucket_path::hash_to_bucket_path;
use errors::AnyhowResult;
use errors::anyhow;
use errors::AnyhowResult;
use crate::util::hash_to_bucket_path::hash_to_bucket_path;
#[deprecated(note = "this is a messy function and should be avoided")]
pub fn hash_to_bucket_path_string(file_hash: &str,
@@ -1,6 +1,5 @@
use serde::Deserialize;
use serde::Serialize;
#[cfg(test)]
use strum::EnumCount;
#[cfg(test)]
@@ -1,6 +1,5 @@
use serde::Deserialize;
use serde::Serialize;
#[cfg(test)]
use strum::EnumCount;
#[cfg(test)]
@@ -1,6 +1,5 @@
use serde::Deserialize;
use serde::Serialize;
#[cfg(test)]
use strum::EnumCount;
#[cfg(test)]
@@ -5,7 +5,6 @@ use strum::EnumCount;
#[cfg(test)]
use strum::EnumIter;
/// Used in the `generic_inference_jobs` table in `VARCHAR(32)` field `inference_category`.
///
/// Our "generic inference" pipeline supports a wide variety of ML models and other media.
@@ -5,7 +5,6 @@ use strum::EnumCount;
#[cfg(test)]
use strum::EnumIter;
/// Used in the `generic_inference_jobs` table in `VARCHAR(32)` field `maybe_input_source_token`.
///
/// DO NOT CHANGE VALUES WITHOUT A MIGRATION STRATEGY.
@@ -5,7 +5,6 @@ use strum::EnumCount;
#[cfg(test)]
use strum::EnumIter;
/// Used in the `generic_inference_jobs` table in `VARCHAR(32)` field `maybe_model_type`.
///
/// Our "generic inference" pipeline supports a wide variety of ML models and other media.
@@ -5,7 +5,6 @@ use strum::EnumCount;
#[cfg(test)]
use strum::EnumIter;
/// Used in the `generic_inference_jobs` table in `VARCHAR(32)` field `on_success_result_entity_type`.
///
/// Our "generic inference" pipeline supports a wide variety of output types.
@@ -5,7 +5,6 @@ use strum::EnumCount;
#[cfg(test)]
use strum::EnumIter;
/// Used in the `generic_synthetic_ids` table in `VARCHAR(32)` field `id_category`.
///
/// This lets us create synthetic increment IDs on a per-user, per-category basis.
@@ -1,6 +1,5 @@
use serde::Deserialize;
use serde::Serialize;
#[cfg(test)]
use strum::EnumCount;
#[cfg(test)]
@@ -1,6 +1,5 @@
use serde::Deserialize;
use serde::Serialize;
#[cfg(test)]
use strum::EnumCount;
#[cfg(test)]
@@ -1,6 +1,5 @@
use serde::Deserialize;
use serde::Serialize;
#[cfg(test)]
use strum::EnumCount;
#[cfg(test)]
@@ -1,6 +1,5 @@
use serde::Deserialize;
use serde::Serialize;
#[cfg(test)]
use strum::EnumCount;
#[cfg(test)]
@@ -1,6 +1,5 @@
use serde::Deserialize;
use serde::Serialize;
#[cfg(test)]
use strum::EnumCount;
#[cfg(test)]
@@ -1,6 +1,5 @@
use serde::Deserialize;
use serde::Serialize;
#[cfg(test)]
use strum::EnumCount;
#[cfg(test)]
@@ -1,6 +1,5 @@
use serde::Deserialize;
use serde::Serialize;
#[cfg(test)]
use strum::EnumCount;
#[cfg(test)]
@@ -1,6 +1,5 @@
use serde::Deserialize;
use serde::Serialize;
#[cfg(test)]
use strum::EnumCount;
#[cfg(test)]
@@ -1,6 +1,5 @@
use serde::Deserialize;
use serde::Serialize;
#[cfg(test)]
use strum::EnumCount;
#[cfg(test)]
@@ -1,6 +1,5 @@
use serde::Deserialize;
use serde::Serialize;
#[cfg(test)]
use strum::EnumCount;
#[cfg(test)]
@@ -62,8 +61,8 @@ impl TtsRenderStatus {
#[cfg(test)]
mod tests {
use crate::test_helpers::assert_serialization;
use crate::by_table::tts_render_tasks::tts_render_status::TtsRenderStatus;
use crate::test_helpers::assert_serialization;
mod serde {
use super::*;
@@ -1,6 +1,5 @@
use serde::Deserialize;
use serde::Serialize;
#[cfg(test)]
use strum::EnumCount;
#[cfg(test)]
@@ -5,7 +5,6 @@ use strum::EnumCount;
#[cfg(test)]
use strum::EnumIter;
/// Used in the `voice_conversion_models` table in `VARCHAR(32)` field `model_type`.
///
/// DO NOT CHANGE VALUES WITHOUT A MIGRATION STRATEGY.
@@ -1,6 +1,5 @@
use serde::Deserialize;
use serde::Serialize;
#[cfg(test)]
use strum::EnumCount;
#[cfg(test)]
@@ -1,6 +1,5 @@
use serde::Deserialize;
use serde::Serialize;
#[cfg(test)]
use strum::EnumCount;
#[cfg(test)]
@@ -1,6 +1,5 @@
use serde::Deserialize;
use serde::Serialize;
#[cfg(test)]
use strum::EnumCount;
#[cfg(test)]
@@ -1,6 +1,5 @@
use serde::Deserialize;
use serde::Serialize;
#[cfg(test)]
use strum::EnumCount;
#[cfg(test)]
@@ -1,6 +1,5 @@
use serde::Deserialize;
use serde::Serialize;
#[cfg(test)]
use strum::EnumCount;
#[cfg(test)]
@@ -1,6 +1,5 @@
use serde::Deserialize;
use serde::Serialize;
#[cfg(test)]
use strum::EnumCount;
#[cfg(test)]
@@ -1,6 +1,5 @@
use serde::Deserialize;
use serde::Serialize;
#[cfg(test)]
use strum::EnumCount;
#[cfg(test)]
@@ -83,8 +82,8 @@ impl WebContentType {
#[cfg(test)]
mod tests {
use crate::test_helpers::assert_serialization;
use crate::common::sqlite::web_content_type::WebContentType;
use crate::test_helpers::assert_serialization;
mod serde {
use super::*;
@@ -144,6 +144,7 @@ mod tests {
mod serde_serialization {
use crate::common::visibility::Visibility;
use super::CompositeType;
#[test]
@@ -166,6 +167,7 @@ mod tests {
mod serde_deserialization {
use crate::common::visibility::Visibility;
use super::CompositeType;
#[test]
@@ -1,7 +1,9 @@
use crate::prefixes::EntityType;
use std::fmt::Debug;
use serde::Deserialize;
use serde::Serialize;
use std::fmt::Debug;
use crate::prefixes::EntityType;
// FIXME: I think that this file+module structure is an anti-pattern.
// In the future, we should create two top-level directories: /tokens and /ids, and each token or
+4 -2
View File
@@ -1,7 +1,9 @@
use crate::prefixes::EntityType;
use std::fmt::Debug;
use serde::Deserialize;
use serde::Serialize;
use std::fmt::Debug;
use crate::prefixes::EntityType;
// FIXME: I think that this file+module structure is an anti-pattern.
// In the future, we should create two top-level directories: /tokens and /ids, and each token or
+4 -2
View File
@@ -1,7 +1,9 @@
use crate::prefixes::EntityType;
use std::fmt::Debug;
use serde::Deserialize;
use serde::Serialize;
use std::fmt::Debug;
use crate::prefixes::EntityType;
// FIXME: I think that this file+module structure is an anti-pattern.
// In the future, we should create two top-level directories: /tokens and /ids, and each token or
+3 -1
View File
@@ -53,11 +53,13 @@ impl EntityType {
#[cfg(test)]
mod tests {
use crate::prefixes::EntityType;
use std::collections::HashSet;
use strum::EnumCount;
use strum::IntoEnumIterator;
use crate::prefixes::EntityType;
#[test]
fn test_all_prefixes_are_unique() {
let entities = EntityType::iter()
@@ -1,7 +1,9 @@
use crate::prefixes::EntityType;
use std::fmt::Debug;
use serde::Deserialize;
use serde::Serialize;
use std::fmt::Debug;
use crate::prefixes::EntityType;
/// The primary key for Audit Logs.
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, sqlx::Type, Debug, Serialize, Deserialize)]
+4 -2
View File
@@ -1,7 +1,9 @@
use crate::prefixes::EntityType;
use std::fmt::Debug;
use serde::Deserialize;
use serde::Serialize;
use std::fmt::Debug;
use crate::prefixes::EntityType;
/// The primary key for Audit Logs.
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, sqlx::Type, Debug, Serialize, Deserialize)]
@@ -1,7 +1,9 @@
use crate::prefixes::EntityType;
use std::fmt::Debug;
use serde::Deserialize;
use serde::Serialize;
use std::fmt::Debug;
use crate::prefixes::EntityType;
/// The primary key for Audit Logs.
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, sqlx::Type, Debug, Serialize, Deserialize)]
@@ -1,7 +1,9 @@
use crate::prefixes::EntityType;
use std::fmt::Debug;
use serde::Deserialize;
use serde::Serialize;
use std::fmt::Debug;
use crate::prefixes::EntityType;
/// The primary key for model categories.
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, sqlx::Type, Debug, Serialize, Deserialize)]
@@ -1,7 +1,9 @@
use crate::prefixes::EntityType;
use std::fmt::Debug;
use serde::Deserialize;
use serde::Serialize;
use std::fmt::Debug;
use crate::prefixes::EntityType;
/// The primary key for news stories (Sqlite)
#[derive(Clone, PartialEq, Eq, sqlx::Type, Debug, Serialize, Deserialize)]
@@ -1,7 +1,9 @@
use crate::prefixes::EntityType;
use std::fmt::Debug;
use serde::Deserialize;
use serde::Serialize;
use std::fmt::Debug;
use crate::prefixes::EntityType;
/// The primary key for TTS models.
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, sqlx::Type, Debug, Serialize, Deserialize)]
@@ -1,7 +1,9 @@
use crate::prefixes::EntityType;
use std::fmt::Debug;
use serde::Deserialize;
use serde::Serialize;
use std::fmt::Debug;
use crate::prefixes::EntityType;
/// The primary key for TTS render tasks (Sqlite / AiChatBotSidecar)
#[derive(Clone, PartialEq, Eq, sqlx::Type, Debug, Serialize, Deserialize)]
@@ -1,7 +1,9 @@
use crate::prefixes::EntityType;
use std::fmt::Debug;
use serde::Deserialize;
use serde::Serialize;
use std::fmt::Debug;
use crate::prefixes::EntityType;
/// The primary key for model categories.
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, sqlx::Type, Debug, Serialize, Deserialize)]
@@ -1,7 +1,9 @@
use crate::prefixes::EntityType;
use std::fmt::Debug;
use serde::Deserialize;
use serde::Serialize;
use std::fmt::Debug;
use crate::prefixes::EntityType;
/// The primary key for W2L templates.
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, sqlx::Type, Debug, Serialize, Deserialize)]
+4 -2
View File
@@ -1,7 +1,9 @@
use crate::prefixes::EntityType;
use std::fmt::Debug;
use serde::Deserialize;
use serde::Serialize;
use std::fmt::Debug;
use crate::prefixes::EntityType;
// FIXME: I think that this file+module structure is an anti-pattern.
// In the future, we should create two top-level directories: /tokens and /ids, and each token or
@@ -1,7 +1,9 @@
use crate::prefixes::EntityType;
use std::fmt::Debug;
use serde::Deserialize;
use serde::Serialize;
use std::fmt::Debug;
use crate::prefixes::EntityType;
// FIXME: I think that this file+module structure is an anti-pattern.
// In the future, we should create two top-level directories: /tokens and /ids, and each token or
@@ -2,6 +2,7 @@
use serde::Deserialize;
use serde::Serialize;
use tokens::tokens::media_files::MediaFileToken;
#[derive(Serialize, Deserialize, PartialEq, Debug)]
@@ -62,9 +63,10 @@ mod traits {
}
mod serialization {
use crate::CompositeType;
use tokens::tokens::media_files::MediaFileToken;
use crate::CompositeType;
#[test]
fn serialize() {
let expected = "\"m_foo\"".to_string(); // NB: Quoted
@@ -85,9 +87,10 @@ mod serialization {
}
mod deserialization {
use crate::CompositeType;
use tokens::tokens::media_files::MediaFileToken;
use crate::CompositeType;
#[test]
fn deserialize() {
let payload = "\"m_foo\""; // NB: Quoted
@@ -2,6 +2,7 @@
use serde::Deserialize;
use serde::Serialize;
use tokens::files::media_upload::MediaUploadToken;
#[derive(Serialize, Deserialize, PartialEq, Debug)]
@@ -62,9 +63,10 @@ mod traits {
}
mod serialization {
use crate::CompositeType;
use tokens::files::media_upload::MediaUploadToken;
use crate::CompositeType;
#[test]
fn serialize() {
let expected = "\"mu_foo\"".to_string(); // NB: Quoted
@@ -85,9 +87,10 @@ mod serialization {
}
mod deserialization {
use crate::CompositeType;
use tokens::files::media_upload::MediaUploadToken;
use crate::CompositeType;
#[test]
fn deserialize() {
let payload = "\"mu_foo\""; // NB: Quoted
@@ -2,6 +2,7 @@
use serde::Deserialize;
use serde::Serialize;
use tokens::users::user::UserToken;
#[derive(Serialize, Deserialize, PartialEq, Debug)]
@@ -62,9 +63,10 @@ mod traits {
}
mod serialization {
use crate::CompositeType;
use tokens::users::user::UserToken;
use crate::CompositeType;
#[test]
fn serialize() {
let expected = "\"U:foo\"".to_string(); // NB: Quoted
@@ -85,9 +87,10 @@ mod serialization {
}
mod deserialization {
use crate::CompositeType;
use tokens::users::user::UserToken;
use crate::CompositeType;
#[test]
fn deserialize() {
let payload = "\"U:foo\""; // NB: Quoted
+2 -1
View File
@@ -1,7 +1,8 @@
use container_common::anyhow_result::AnyhowResult;
use easyenv::init_all_with_default_logging;
use log::info;
use container_common::anyhow_result::AnyhowResult;
fn main() -> AnyhowResult<()> {
init_all_with_default_logging(None);
+2 -1
View File
@@ -1,7 +1,8 @@
use container_common::anyhow_result::AnyhowResult;
use easyenv::init_all_with_default_logging;
use log::info;
use container_common::anyhow_result::AnyhowResult;
fn main() -> AnyhowResult<()> {
init_all_with_default_logging(None);
+1
View File
@@ -1,4 +1,5 @@
use clap::{App, Arg};
use errors::{anyhow, AnyhowResult};
use web_scrapers::scrape_supported_webpage::scrape_supported_webpage;
@@ -1,6 +1,7 @@
use std::str::FromStr;
use actix_http::header::HeaderMap;
use actix_http::header::HeaderName;
use std::str::FromStr;
pub (crate) fn get_ip_from_header(headers: &HeaderMap, header_name: &str) -> Option<String> {
if let Ok(header_name) = HeaderName::from_str(header_name) {
@@ -1,4 +1,5 @@
use actix_web::dev::ServiceRequest;
use crate::extractors::get_ip_from_header::get_ip_from_header;
pub fn get_service_request_ip_address(request: &ServiceRequest) -> String {
@@ -1,9 +1,10 @@
use actix_web::Error;
use actix_web::dev::{Service, Transform};
use actix_web::dev::{ServiceRequest, ServiceResponse};
use actix_web::Error;
use futures_util::future::{ok, Ready};
use crate::middleware::banned_cidr_filter::banned_cidr_filter_middleware::BannedCidrFilterMiddleware;
use crate::middleware::banned_cidr_filter::banned_cidr_set::BannedCidrSet;
use futures_util::future::{ok, Ready};
// There are two steps in middleware processing.
// 1. Middleware initialization, middleware factory gets called with
@@ -1,12 +1,15 @@
use actix_web::Error;
use actix_web::dev::Service;
use std::net::IpAddr;
use std::str::FromStr;
use actix_web::dev::{ServiceRequest, ServiceResponse};
use actix_web::dev::Service;
use actix_web::Error;
use futures_util::future::{Either, err, Ready};
use crate::extractors::get_service_request_ip_address::get_service_request_ip_address;
use crate::middleware::banned_cidr_filter::banned_cidr_set::BannedCidrSet;
use crate::middleware::banned_ip_filter::banned_error::BannedError;
use futures_util::future::{err, Either, Ready};
use std::net::IpAddr;
use std::str::FromStr;
//use std::task::{Context, Poll};
pub struct BannedCidrFilterMiddleware<S> {
@@ -1,11 +1,13 @@
use cidr_utils::cidr::IpCidr;
use cidr_utils::num_bigint::BigUint;
use errors::{anyhow, AnyhowResult};
use num_traits::cast::ToPrimitive;
use std::collections::HashSet;
use std::net::IpAddr;
use std::sync::{Arc, RwLock};
use cidr_utils::cidr::IpCidr;
use cidr_utils::num_bigint::BigUint;
use num_traits::cast::ToPrimitive;
use errors::{anyhow, AnyhowResult};
#[derive(Clone)]
pub struct BannedCidrSet {
cidr_set: Arc<RwLock<HashSet<IpCidr>>>
@@ -68,12 +70,15 @@ impl BannedCidrSet {
#[cfg(test)]
mod tests {
use cidr_utils::cidr::IpCidr;
use crate::middleware::banned_cidr_filter::banned_cidr_set::BannedCidrSet;
use std::net::IpAddr;
use std::str::FromStr;
use cidr_utils::cidr::IpCidr;
use errors::AnyhowResult;
use crate::middleware::banned_cidr_filter::banned_cidr_set::BannedCidrSet;
fn to_ip(ip_address: &str) -> IpAddr {
IpAddr::from_str(ip_address).expect("ip should have parsed")
}
@@ -1,11 +1,14 @@
use cidr_utils::cidr::IpCidr;
use crate::middleware::banned_cidr_filter::banned_cidr_set::BannedCidrSet;
use errors::AnyhowResult;
use std::collections::HashSet;
use std::fs::File;
use std::io::{BufRead, BufReader};
use std::path::Path;
use cidr_utils::cidr::IpCidr;
use errors::AnyhowResult;
use crate::middleware::banned_cidr_filter::banned_cidr_set::BannedCidrSet;
pub fn load_cidr_ban_set_from_file<P: AsRef<Path>>(path: P) -> AnyhowResult<BannedCidrSet> {
let file = File::open(path)?;
let reader = BufReader::new(file);
@@ -27,12 +30,14 @@ pub fn load_cidr_ban_set_from_file<P: AsRef<Path>>(path: P) -> AnyhowResult<Bann
#[cfg(test)]
mod tests {
use crate::middleware::banned_cidr_filter::load_cidr_ban_set_from_file::load_cidr_ban_set_from_file;
use errors::AnyhowResult;
use std::net::IpAddr;
use std::path::PathBuf;
use std::str::FromStr;
use errors::AnyhowResult;
use crate::middleware::banned_cidr_filter::load_cidr_ban_set_from_file::load_cidr_ban_set_from_file;
fn test_file(path_from_repo_root: &str) -> PathBuf {
// https://doc.rust-lang.org/cargo/reference/environment-variables.html
let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
@@ -1,8 +1,8 @@
use actix_http::body::BoxBody;
use actix_http::header::CONTENT_TYPE;
use actix_web::http::StatusCode;
use actix_web::http::header::ContentType;
use actix_web::{HttpResponse, HttpResponseBuilder, ResponseError};
use actix_web::http::header::ContentType;
use actix_web::http::StatusCode;
#[derive(Debug)]
pub struct BannedError;
@@ -1,9 +1,10 @@
use actix_web::Error;
use actix_web::dev::{Service, Transform};
use actix_web::dev::{ServiceRequest, ServiceResponse};
use actix_web::Error;
use futures_util::future::{ok, Ready};
use crate::middleware::banned_ip_filter::banned_ip_filter_middleware::BannedIpFilterMiddleware;
use crate::middleware::banned_ip_filter::ip_ban_list::ip_ban_list::IpBanList;
use futures_util::future::{ok, Ready};
// There are two steps in middleware processing.
// 1. Middleware initialization, middleware factory gets called with
@@ -1,10 +1,12 @@
use actix_web::Error;
use actix_web::dev::Service;
use actix_web::dev::{ServiceRequest, ServiceResponse};
use actix_web::dev::Service;
use actix_web::Error;
use futures_util::future::{Either, err, Ready};
use crate::extractors::get_service_request_ip_address::get_service_request_ip_address;
use crate::middleware::banned_ip_filter::banned_error::BannedError;
use crate::middleware::banned_ip_filter::ip_ban_list::ip_ban_list::IpBanList;
use futures_util::future::{err, Either, Ready};
//use std::task::{Context, Poll};
// There are two steps in middleware processing.
@@ -1,8 +1,10 @@
use crate::middleware::banned_ip_filter::ip_ban_list::ip_set::IpSet;
use errors::{anyhow, AnyhowResult};
use std::collections::HashMap;
use std::sync::{Arc, RwLock};
use errors::{anyhow, AnyhowResult};
use crate::middleware::banned_ip_filter::ip_ban_list::ip_set::IpSet;
#[derive(Clone)]
pub struct IpBanList {
ip_sets: Arc<RwLock<HashMap<String, IpSet>>>
@@ -1,7 +1,9 @@
use std::path::Path;
use errors::AnyhowResult;
use crate::middleware::banned_ip_filter::ip_ban_list::ip_ban_list::IpBanList;
use crate::middleware::banned_ip_filter::ip_ban_list::load_ip_set_from_file::load_ip_set_from_file;
use errors::AnyhowResult;
use std::path::Path;
pub fn load_ip_ban_list_from_directory<P: AsRef<Path>>(path: P) -> AnyhowResult<IpBanList> {
let ip_ban_list = IpBanList::new();
@@ -32,6 +34,7 @@ fn ignore_path(path: &Path) -> bool {
#[cfg(test)]
mod tests {
use std::path::{Path, PathBuf};
use crate::middleware::banned_ip_filter::ip_ban_list::load_ip_ban_list_from_directory::{ignore_path, load_ip_ban_list_from_directory};
fn test_file(path_from_repo_root: &str) -> PathBuf {
@@ -1,10 +1,12 @@
use crate::middleware::banned_ip_filter::ip_ban_list::ip_set::IpSet;
use errors::AnyhowResult;
use std::collections::HashSet;
use std::fs::File;
use std::io::{BufRead, BufReader};
use std::path::Path;
use errors::AnyhowResult;
use crate::middleware::banned_ip_filter::ip_ban_list::ip_set::IpSet;
pub fn load_ip_set_from_file<P: AsRef<Path>>(path: P) -> AnyhowResult<IpSet> {
let file = File::open(path)?;
let reader = BufReader::new(file);
@@ -21,6 +23,7 @@ pub fn load_ip_set_from_file<P: AsRef<Path>>(path: P) -> AnyhowResult<IpSet> {
#[cfg(test)]
mod tests {
use std::path::PathBuf;
use crate::middleware::banned_ip_filter::ip_ban_list::load_ip_set_from_file::load_ip_set_from_file;
fn test_file(path_from_repo_root: &str) -> PathBuf {
@@ -1,9 +1,10 @@
use actix_web::Error;
use actix_web::dev::{Service, Transform};
use actix_web::dev::{ServiceRequest, ServiceResponse};
use actix_web::Error;
use futures_util::future::{ok, Ready};
use crate::middleware::disabled_endpoint_filter::disabled_endpoint_filter_middleware::DisabledEndpointFilterMiddleware;
use crate::middleware::disabled_endpoint_filter::disabled_endpoints::disabled_endpoints::DisabledEndpoints;
use futures_util::future::{ok, Ready};
// There are two steps in middleware processing.
// 1. Middleware initialization, middleware factory gets called with
@@ -1,9 +1,11 @@
use actix_web::Error;
use actix_web::dev::Service;
use actix_web::dev::{ServiceRequest, ServiceResponse};
use actix_web::dev::Service;
use actix_web::Error;
use futures_util::future::{Either, err, Ready};
use crate::middleware::disabled_endpoint_filter::disabled_endpoints::disabled_endpoints::DisabledEndpoints;
use crate::middleware::disabled_endpoint_filter::disabled_error::DisabledError;
use futures_util::future::{err, Either, Ready};
//use std::task::{Context, Poll};
// There are two steps in middleware processing.
@@ -1,6 +1,7 @@
use std::sync::Arc;
use crate::middleware::disabled_endpoint_filter::disabled_endpoints::exact_match_disabled_endpoints::ExactMatchDisabledEndpoints;
use crate::middleware::disabled_endpoint_filter::disabled_endpoints::prefix_disabled_endpoints::PrefixDisabledEndpoints;
use std::sync::Arc;
#[derive(Clone)]
pub struct DisabledEndpoints {
@@ -1,9 +1,10 @@
use errors::AnyhowResult;
use std::collections::HashSet;
use std::fs::File;
use std::io::{BufRead, BufReader};
use std::path::Path;
use errors::AnyhowResult;
pub struct ExactMatchDisabledEndpoints {
endpoints: HashSet<String>
}
@@ -1,9 +1,10 @@
use errors::AnyhowResult;
use std::collections::HashSet;
use std::fs::File;
use std::io::{BufRead, BufReader};
use std::path::Path;
use errors::AnyhowResult;
pub struct PrefixDisabledEndpoints {
endpoint_prefixes: HashSet<String>
}
@@ -1,8 +1,8 @@
use actix_http::body::BoxBody;
use actix_http::header::CONTENT_TYPE;
use actix_web::http::StatusCode;
use actix_web::http::header::ContentType;
use actix_web::{HttpResponse, HttpResponseBuilder, ResponseError};
use actix_web::http::header::ContentType;
use actix_web::http::StatusCode;
#[derive(Debug)]
pub struct DisabledError;
@@ -1,7 +1,7 @@
use actix_web::HttpResponse;
use actix_web::HttpResponseBuilder;
use actix_web::error::ResponseError;
use actix_web::http::header::ContentType;
use actix_web::HttpResponse;
use actix_web::HttpResponseBuilder;
use serde::Serialize;
/// Turn error responses into JSON HTTP responses with appropriate status code
@@ -1,8 +1,8 @@
use actix_http::body::MessageBody;
use actix_service::ServiceFactory;
use actix_web::{App, FromRequest, HttpResponse, Responder, web};
use actix_web::dev::{Handler, ServiceRequest, ServiceResponse};
use actix_web::error::Error;
use actix_web::{App, web, HttpResponse, FromRequest, Responder};
// TODO: Check that routes don't overlap.
// TODO: Properly handle scoped routes in a nice DSL.
@@ -1,3 +1,6 @@
use std::path::Path;
use std::time::Duration;
use anyhow::anyhow;
use anyhow::bail;
use log::info;
@@ -5,13 +8,8 @@ use log::warn;
use s3::bucket::Bucket;
use s3::creds::Credentials;
use s3::region::Region;
use std::io::Read;
use std::path::{PathBuf, Path};
use std::str::FromStr;
use std::time::Duration;
use tokio::fs::File;
use tokio::io::AsyncBufReadExt;
use tokio::io::{AsyncBufRead, BufReader, AsyncReadExt};
use tokio::io::AsyncReadExt;
#[derive(Clone)]
pub struct BucketClient {
@@ -1,7 +1,7 @@
use buckets::util::hashed_directory_path_short_string::hashed_directory_path_short_string;
use container_common::anyhow_result::AnyhowResult;
use std::path::PathBuf;
use buckets::util::hashed_directory_path_short_string::hashed_directory_path_short_string;
/// This is designed to make it centrally configurable where
/// different types of objects are stored.
#[deprecated(note = "see the 'buckets' crate for a better approach")]
@@ -261,9 +261,10 @@ impl BucketPathUnifier {
#[cfg(test)]
mod tests {
use crate::bucket_path_unifier::BucketPathUnifier;
use std::path::PathBuf;
use crate::bucket_path_unifier::BucketPathUnifier;
fn get_instance() -> BucketPathUnifier {
BucketPathUnifier {
// TTS
@@ -1,13 +1,15 @@
use backoff::future::retry;
use backoff::{ExponentialBackoff, ExponentialBackoffBuilder};
use crate::api::tts_inference::{CreateTtsInferenceRequest, CreateTtsInferenceResponse, TtsInferenceJobStatus};
use crate::credentials::FakeYouCredentials;
use errors::{anyhow, AnyhowError, AnyhowResult};
use reqwest::cookie::Jar;
use reqwest::{Client, ClientBuilder, RequestBuilder, StatusCode, Url};
use std::sync::Arc;
use std::time::Duration;
use backoff::{ExponentialBackoff, ExponentialBackoffBuilder};
use backoff::future::retry;
use errors::{anyhow, AnyhowError, AnyhowResult};
use log::{error, warn};
use reqwest::{Client, ClientBuilder, RequestBuilder, StatusCode, Url};
use reqwest::cookie::Jar;
use crate::api::tts_inference::{CreateTtsInferenceRequest, CreateTtsInferenceResponse, TtsInferenceJobStatus};
use crate::credentials::FakeYouCredentials;
const AUTHORIZATION_HEADER: &str = "Authorization";
const SESSION_COOKIE_NAME : &str = "session";
@@ -1,12 +1,12 @@
use std::process::Command;
use anyhow::anyhow;
use log::info;
use tempdir::TempDir;
use container_common::anyhow_result::AnyhowResult;
use container_common::token::random_crockford_token::random_crockford_token;
use log::{info, warn};
use std::io::{BufReader, Read};
use std::path::{PathBuf, Path};
use std::process::Command;
use subprocess_common::docker_options::DockerOptions;
use tempdir::TempDir;
/// This is a Python script that uses the `gdown` package to download from Google Drive.
/// We're using this because it's a hack that gets around OAuth gateways. All the Rust
@@ -1,5 +1,6 @@
use once_cell::sync::Lazy;
use std::collections::HashSet;
use once_cell::sync::Lazy;
use regex::Regex;
// NB: This can be used as a nice, succinct macro with once_cell:
@@ -1,5 +1,5 @@
use twitch_oauth2::{ClientId, ClientSecret, Scope};
use twitch_oauth2::tokens::UserTokenBuilder;
use twitch_oauth2::{Scope, ClientSecret, ClientId, CsrfToken};
use twitch_oauth2::url::Url;
/// Get the token builder with the scopes our app needs
+4 -2
View File
@@ -1,7 +1,9 @@
use std::path::Path;
use log::info;
use errors::{anyhow, AnyhowResult};
use server_environment::ServerEnvironment;
use std::path::Path;
use log::info;
pub struct BootstrapArgs<'a, P: AsRef<Path>> {
/// The name of the application or service
@@ -1,9 +1,11 @@
use anyhow::bail;
use errors::AnyhowResult;
use lru_time_cache::LruCache;
use std::sync::{Arc, Mutex};
use std::time::Duration;
use anyhow::bail;
use lru_time_cache::LruCache;
use errors::AnyhowResult;
/// Essentially a wrapper around LruCache.
#[derive(Clone)]
pub struct MultiItemTtlCache<K: Ord + Clone, V: Clone + ?Sized> {
@@ -1,9 +1,11 @@
use anyhow::bail;
use errors::AnyhowResult;
use lru_time_cache::LruCache;
use std::sync::{Arc, Mutex};
use std::time::Duration;
use anyhow::bail;
use lru_time_cache::LruCache;
use errors::AnyhowResult;
/// NB: There's only ONE ITEM of ONE TYPE in the cache. We can use a single key.
const CACHE_KEY : &str = "ITEM";
@@ -73,6 +75,7 @@ impl <T: Clone + ?Sized> SingleItemTtlCache<T> {
mod tests {
use std::thread;
use std::time::Duration;
use crate::single_item_ttl_cache::SingleItemTtlCache;
#[test]
@@ -1,9 +1,11 @@
use anyhow::bail;
use errors::AnyhowResult;
use lru_time_cache::LruCache;
use std::sync::{Arc, Mutex};
use std::time::Duration;
use anyhow::bail;
use lru_time_cache::LruCache;
use errors::AnyhowResult;
/// Maintain counters for keys with a TTL
#[derive(Clone)]
pub struct TtlKeyCounter {
@@ -40,9 +42,10 @@ impl TtlKeyCounter {
#[cfg(test)]
mod tests {
use std::thread;
use crate::ttl_key_counter::TtlKeyCounter;
use std::time::Duration;
use crate::ttl_key_counter::TtlKeyCounter;
#[test]
fn test_key_first_count() {
let counter = TtlKeyCounter::create_with_duration(Duration::from_secs(2));
@@ -1,8 +1,10 @@
use std::future::Future;
use r2d2_redis::RedisConnectionManager;
use r2d2_redis::r2d2::{Pool, PooledConnection};
use r2d2_redis::redis::Commands;
use r2d2_redis::RedisConnectionManager;
use serde::{Deserialize, Serialize};
use errors::AnyhowResult;
const DEFAULT_TTL_SECONDS : usize = 60;
@@ -29,6 +29,7 @@ impl RelaxedAtomicBool {
mod tests {
use std::thread;
use std::time::{Duration, Instant};
use crate::relaxed_atomic_bool::RelaxedAtomicBool;
#[test]
@@ -1,6 +1,7 @@
use crate::{CROCKFORD_LOWERCASE_CHARSET, CROCKFORD_UPPERCASE_CHARSET};
use rand::Rng;
use crate::{CROCKFORD_LOWERCASE_CHARSET, CROCKFORD_UPPERCASE_CHARSET};
// TODO: Modify these routines to filter out intra-string swear words.
/// Generate a crockford-encoded entropy string (uppercase)
@@ -26,6 +27,7 @@ fn crockford_entropy(length: usize, character_set: &[u8]) -> String {
#[cfg(test)]
mod tests {
use std::collections::HashSet;
use crate::crockford_entropy::{crockford_entropy_lower, crockford_entropy_upper};
#[test]
+4 -4
View File
@@ -17,6 +17,10 @@
#![allow(dead_code)]
#![allow(non_snake_case)]
pub use crockford_entropy::crockford_entropy_lower;
// Re-export
pub use crockford_entropy::crockford_entropy_upper;
/// Crockford characters (uppercase)
const CROCKFORD_UPPERCASE_CHARSET: &[u8] = b"0123456789ABCDEFGHJKMNPQRSTVWXYZ";
@@ -25,7 +29,3 @@ const CROCKFORD_LOWERCASE_CHARSET: &[u8] = b"0123456789abcdefghjkmnpqrstvwxyz";
mod crockford_entropy;
// Re-export
pub use crockford_entropy::crockford_entropy_upper;
pub use crockford_entropy::crockford_entropy_lower;
@@ -1,9 +1,11 @@
use crate::anyhow_result::AnyhowResult;
use serde::de::DeserializeOwned;
use std::fs::File;
use std::io::Read;
use std::path::Path;
use serde::de::DeserializeOwned;
use crate::anyhow_result::AnyhowResult;
/// Read a TOML file into a struct.
pub fn read_toml_file_to_struct<D, P>(filename: P) -> AnyhowResult<D>
where
@@ -20,11 +22,13 @@ where
#[cfg(test)]
mod tests {
use crate::files::read_toml_file_to_struct::read_toml_file_to_struct;
use serde::Deserialize;
use std::io::Write;
use serde::Deserialize;
use tempfile::NamedTempFile;
use crate::files::read_toml_file_to_struct::read_toml_file_to_struct;
#[derive(Deserialize)]
struct TestStruct {
name: String,
@@ -1,7 +1,9 @@
use anyhow::bail;
use crate::anyhow_result::AnyhowResult;
use std::path::PathBuf;
use anyhow::bail;
use crate::anyhow_result::AnyhowResult;
pub fn check_directory_exists(path: &PathBuf) -> AnyhowResult<()> {
if !path.exists() {
bail!("Path doesn't exist: {:?}", path);
@@ -1,7 +1,9 @@
use anyhow::bail;
use crate::anyhow_result::AnyhowResult;
use std::path::PathBuf;
use anyhow::bail;
use crate::anyhow_result::AnyhowResult;
pub fn check_file_exists(path: &PathBuf) -> AnyhowResult<()> {
if !path.exists() {
bail!("Path doesn't exist: {:?}", path);
@@ -1,6 +1,7 @@
use crate::filesystem::safe_delete_temp_file::safe_delete_temp_file;
use std::path::Path;
use crate::filesystem::safe_delete_temp_file::safe_delete_temp_file;
pub fn safe_delete_possible_temp_file<P: AsRef<Path>>(maybe_file_path: Option<P>) {
if let Some(file_path) = maybe_file_path {
safe_delete_temp_file(file_path)
@@ -1,8 +1,9 @@
use log::info;
use log::warn;
use std::fs;
use std::path::Path;
use log::info;
use log::warn;
pub fn safe_delete_temp_directory<P: AsRef<Path>>(directory_path: P) {
// NB: We should be using a tempdir, but to make absolutely certain we don't overflow the disk...
let printable_name = directory_path.as_ref().to_str().unwrap_or("bad directory");
@@ -1,8 +1,9 @@
use log::info;
use log::warn;
use std::fs;
use std::path::Path;
use log::info;
use log::warn;
pub fn safe_delete_temp_file<P: AsRef<Path>>(file_path: P) {
// NB: We should be using a tempdir, but to make absolutely certain we don't overflow the disk...
let printable_name = file_path.as_ref().to_str().unwrap_or("bad filename");
@@ -1,5 +1,6 @@
use std::collections::{HashMap, HashSet};
use once_cell::sync::Lazy;
use std::collections::{HashSet, HashMap};
/// These are language tags we try to support.
static SUPPORTED_LANGUAGES_FOR_MODELS : Lazy<HashSet<String>> = Lazy::new(|| {
@@ -57,11 +57,11 @@ pub fn isize_to_unsigned_zeroing_negatives(num: isize) -> usize {
#[cfg(test)]
mod tests {
use crate::numerics::signed_to_unsigned::i8_to_unsigned_zeroing_negatives;
use crate::numerics::signed_to_unsigned::i128_to_unsigned_zeroing_negatives;
use crate::numerics::signed_to_unsigned::i16_to_unsigned_zeroing_negatives;
use crate::numerics::signed_to_unsigned::i32_to_unsigned_zeroing_negatives;
use crate::numerics::signed_to_unsigned::i64_to_unsigned_zeroing_negatives;
use crate::numerics::signed_to_unsigned::i128_to_unsigned_zeroing_negatives;
use crate::numerics::signed_to_unsigned::i8_to_unsigned_zeroing_negatives;
use crate::numerics::signed_to_unsigned::isize_to_unsigned_zeroing_negatives;
#[test]
@@ -1,7 +1,9 @@
use anyhow::anyhow;
use crate::anyhow_result::AnyhowResult;
use std::sync::{Arc, RwLock};
use std::time::{Instant, Duration};
use std::time::{Duration, Instant};
use anyhow::anyhow;
use crate::anyhow_result::AnyhowResult;
/// Sometimes I need to kill a thread from somewhere else. This is a mechanism
/// that enables it. This utility can be combined with logic that will kill a
Loaded 100 of 695 files, more files were not shown because too many files have changed in this diff. Show more