Skip to content

Commit

Permalink
Bumping versions using actix-web 4
Browse files Browse the repository at this point in the history
  • Loading branch information
enaut committed Oct 11, 2021
1 parent c148e83 commit d5160ba
Show file tree
Hide file tree
Showing 9 changed files with 621 additions and 605 deletions.
1,084 changes: 548 additions & 536 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ keywords = ["url", "link", "webpage", "actix", "web"]
license = "MIT OR Apache-2.0"
readme = "README.md"
repository = "https://github.com/enaut/pslink/"
version = "0.4.3"
version = "0.4.4"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
crate-type = ["cdylib", "rlib"]

[dependencies]
fluent = "0.15"
fluent = "0.16"
seed = "0.8"
serde = {version="1.0", features = ["derive"]}
unic-langid = "0.9"
strum_macros = "0.21"
strum = "0.21"
strum_macros = "0.22"
strum = "0.22"
enum-map = "1"
qrcode = "0.12"
image = "0.23"
Expand Down
4 changes: 2 additions & 2 deletions locales/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ keywords = ["url", "link", "webpage", "actix", "web"]
license = "MIT OR Apache-2.0"
readme = "README.md"
repository = "https://github.com/enaut/pslink/"
version = "0.4.3"
version = "0.4.4"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html


[dependencies]
fluent = "0.15"
fluent = "0.16"
serde = {version="1.0", features = ["derive"]}
unic-langid = "0.9"

Expand Down
33 changes: 18 additions & 15 deletions pslink/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,36 @@ license = "MIT OR Apache-2.0"
name = "pslink"
readme = "README.md"
repository = "https://github.com/enaut/pslink/"
version = "0.4.3"
version = "0.4.4"

[build-dependencies]
actix-web-static-files = "3.0"
actix-web-static-files = { path = "../../actix-web-static-files" }
static-files = { version = "0.2", default-features = false }

[dependencies]
actix-identity = "0.3"
actix-rt = "1.1"
actix-web = "3"
actix-web-static-files = "3"
actix-files = "0.5"
actix-identity = "0.4.0-beta.2"
actix-rt = "2.2"
actix-web = "4.0.0-beta.9"
actix-web-static-files = { path = "../../actix-web-static-files" }
actix-files = "0.6.0-beta.7"
argonautica = "0.2"
clap = "2.33"
dotenv = "0.15.0"
fluent-langneg = "0.13"
image = "0.23"
opentelemetry = "0.14"
opentelemetry-jaeger = "0.12"
opentelemetry = "0.16"
opentelemetry-jaeger = "0.15"
qrcode = "0.12"
rand = "0.8"
rpassword = "5.0"
serde = {version="1.0", features = ["derive"]}
static-files = { version = "0.2", default-features = false }
thiserror = "1.0"
tracing-actix-web = "0.2.1"
tracing-opentelemetry = "0.12"
tracing-actix-web = "0.4.0-beta.13"
tracing-opentelemetry = "0.15"
async-trait = "0.1"
enum-map = {version="1", features = ["serde"]}
indexmap = "~1.6.2"

pslink-shared = {version="0.4", path = "../shared" }

Expand All @@ -48,7 +51,7 @@ version = "0.6"

[dependencies.sqlx]
features = ["sqlite", "macros", "runtime-actix-rustls", "chrono", "migrate", "offline"]
version = "0.4"
version = "0.5"

[dependencies.tracing]
features = ["log"]
Expand All @@ -62,11 +65,11 @@ version = "0.2.17"
actix-server = "1.0.4"
tempdir = "0.3"
test_bin = "0.3"
tokio = "0.2.25"
assert_cmd = "1.0.7"
tokio = "1.12"
assert_cmd = "2.0"
predicates = "2.0.0"


[dev-dependencies.reqwest]
features = ["cookies", "json"]
version = "0.10.10"
version = "0.11"
2 changes: 1 addition & 1 deletion pslink/build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use actix_web_static_files::resource_dir;
use static_files::resource_dir;

fn main() {
resource_dir("./static/").build().unwrap();
Expand Down
9 changes: 6 additions & 3 deletions pslink/src/bin/pslink/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ mod views;

use actix_files::Files;
use actix_identity::{CookieIdentityPolicy, IdentityService};
use actix_web::middleware::Compat;
use actix_web::web::Data;
use actix_web::{web, App, HttpServer};
use pslink::ServerConfig;

Expand Down Expand Up @@ -32,7 +34,7 @@ pub fn get_subscriber(name: &str, env_filter: &str) -> impl Subscriber + Send +
let otel_layer = OpenTelemetryLayer::new(tracer);

// Use the tracing subscriber `Registry`, or any other subscriber
// that impls `LookupSpan`
// that implements `LookupSpan`
Registry::default()
.with(otel_layer)
.with(env_filter)
Expand Down Expand Up @@ -105,9 +107,10 @@ pub async fn webservice(

let server = HttpServer::new(move || {
let generated = generate();
let logger = Compat::new(TracingLogger::default());
App::new()
.data(server_config.clone())
.wrap(TracingLogger)
.app_data(Data::new(server_config.clone()))
.wrap(logger)
.wrap(IdentityService::new(
CookieIdentityPolicy::new(&[0; 32])
.name("auth-cookie")
Expand Down
52 changes: 27 additions & 25 deletions pslink/src/bin/pslink/views.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ use pslink::ServerError;
#[instrument]
fn redirect_builder(target: &str) -> HttpResponse {
HttpResponse::SeeOther()
.set(CacheControl(vec![
.insert_header(CacheControl(vec![
CacheDirective::NoCache,
CacheDirective::NoStore,
CacheDirective::MustRevalidate,
]))
.set(Expires(SystemTime::now().into()))
.set_header(actix_web::http::header::LOCATION, target)
.insert_header(Expires(SystemTime::now().into()))
.insert_header((actix_web::http::header::LOCATION, target))
.body(format!("Redirect to {}", target))
}

Expand Down Expand Up @@ -112,7 +112,7 @@ pub async fn index_json(
) -> Result<HttpResponse, ServerError> {
info!("Listing Links to Json api");
match queries::list_all_allowed(&id, &config, form.0).await {
Ok(links) => Ok(HttpResponse::Ok().json2(&links.list)),
Ok(links) => Ok(HttpResponse::Ok().json(&links.list)),
Err(e) => {
error!("Failed to access database: {:?}", e);
warn!("Not logged in - redirecting to login page");
Expand All @@ -129,7 +129,7 @@ pub async fn index_users_json(
) -> Result<HttpResponse, ServerError> {
info!("Listing Users to Json api");
if let Ok(users) = queries::list_users(&id, &config, form.0).await {
Ok(HttpResponse::Ok().json2(&users.list))
Ok(HttpResponse::Ok().json(&users.list))
} else {
Ok(redirect_builder("/admin/login"))
}
Expand All @@ -145,7 +145,7 @@ pub async fn get_logged_user_json(
Ok(HttpResponse::Unauthorized().finish())
}
RoleGuard::Regular { user } | RoleGuard::Admin { user } => {
Ok(HttpResponse::Ok().json2(&user))
Ok(HttpResponse::Ok().json(&user))
}
}
}
Expand All @@ -156,7 +156,7 @@ pub async fn download_png(
config: web::Data<crate::ServerConfig>,
link_code: web::Path<String>,
) -> Result<HttpResponse, ServerError> {
match queries::get_link(&id, &link_code.0, &config).await {
match queries::get_link(&id, &link_code, &config).await {
Ok(query) => {
let qr = QrCode::with_error_correction_level(
&format!("http://{}/{}", config.public_url, &query.item.code),
Expand All @@ -169,7 +169,9 @@ pub async fn download_png(
.write_to(&mut temporary_data, ImageOutputFormat::Png)
.unwrap();
let image_data = temporary_data.into_inner();
Ok(HttpResponse::Ok().set(ContentType::png()).body(image_data))
Ok(HttpResponse::Ok()
.insert_header(ContentType::png())
.body(image_data))
}
Err(e) => Err(e),
}
Expand All @@ -183,7 +185,7 @@ pub async fn process_create_user_json(
) -> Result<HttpResponse, ServerError> {
info!("Listing Users to Json api");
match queries::create_user(&id, data.into_inner(), &config).await {
Ok(item) => Ok(HttpResponse::Ok().json2(&Status::Success(Message {
Ok(item) => Ok(HttpResponse::Ok().json(&Status::Success(Message {
message: format!("Successfully saved user: {}", item.item.username),
}))),
Err(e) => Err(e),
Expand All @@ -198,7 +200,7 @@ pub async fn process_update_user_json(
) -> Result<HttpResponse, ServerError> {
info!("Listing Users to Json api");
match queries::update_user(&id, &form, &config).await {
Ok(item) => Ok(HttpResponse::Ok().json2(&Status::Success(Message {
Ok(item) => Ok(HttpResponse::Ok().json(&Status::Success(Message {
message: format!("Successfully saved user: {}", item.item.username),
}))),
Err(e) => Err(e),
Expand All @@ -212,7 +214,7 @@ pub async fn toggle_admin(
id: Identity,
) -> Result<HttpResponse, ServerError> {
let update = queries::toggle_admin(&id, user.id, &config).await?;
Ok(HttpResponse::Ok().json2(&Status::Success(Message {
Ok(HttpResponse::Ok().json(&Status::Success(Message {
message: format!(
"Successfully changed privileges or user: {}",
update.item.username
Expand All @@ -230,14 +232,14 @@ pub async fn get_language(
let user = authenticate(&id, &config).await?;
match user {
RoleGuard::NotAuthenticated | RoleGuard::Disabled => {
Ok(HttpResponse::Ok().json2(&detect_language(&req)?))
Ok(HttpResponse::Ok().json(&detect_language(&req)?))
}
RoleGuard::Regular { user } | RoleGuard::Admin { user } => {
Ok(HttpResponse::Ok().json2(&user.language))
Ok(HttpResponse::Ok().json(&user.language))
}
}
} else {
Ok(HttpResponse::Ok().json2(&detect_language(&req)?))
Ok(HttpResponse::Ok().json(&detect_language(&req)?))
}
}

Expand All @@ -248,7 +250,7 @@ pub async fn set_language(
id: Identity,
) -> Result<HttpResponse, ServerError> {
queries::set_language(&id, data.0, &config).await?;
Ok(HttpResponse::Ok().json2(&data.0))
Ok(HttpResponse::Ok().json(&data.0))
}

#[instrument(skip(id))]
Expand Down Expand Up @@ -278,23 +280,23 @@ pub async fn process_login_json(
info!("Log-in of user: {}", &u.username);
let session_token = u.username.clone();
id.remember(session_token);
Ok(HttpResponse::Ok().json2(&u))
Ok(HttpResponse::Ok().json(&u))
} else {
info!("Invalid password for user: {}", &u.username);
Ok(HttpResponse::Unauthorized().json2(&Status::Error(Message {
Ok(HttpResponse::Unauthorized().json(&Status::Error(Message {
message: "Failed to Login".to_string(),
})))
}
} else {
// should fail earlier if secret is missing.
Ok(HttpResponse::Unauthorized().json2(&Status::Error(Message {
Ok(HttpResponse::Unauthorized().json(&Status::Error(Message {
message: "Failed to Login".to_string(),
})))
}
}
Err(e) => {
info!("Failed to login: {}", e);
Ok(HttpResponse::Unauthorized().json2(&Status::Error(Message {
Ok(HttpResponse::Unauthorized().json(&Status::Error(Message {
message: "Failed to Login".to_string(),
})))
}
Expand All @@ -311,7 +313,7 @@ pub async fn logout(id: Identity) -> Result<HttpResponse, ServerError> {
#[instrument()]
pub async fn to_admin() -> Result<HttpResponse, ServerError> {
let response = HttpResponse::PermanentRedirect()
.set_header(actix_web::http::header::LOCATION, "/app/")
.insert_header((actix_web::http::header::LOCATION, "/app/"))
.body(r#"The admin interface moved to <a href="/app/">/app/</a>"#);

Ok(response)
Expand All @@ -324,7 +326,7 @@ pub async fn redirect(
req: HttpRequest,
) -> Result<HttpResponse, ServerError> {
info!("Redirecting to {:?}", data);
let link = queries::get_link_simple(&data.0, &config).await;
let link = queries::get_link_simple(&data, &config).await;
info!("link: {:?}", link);
match link {
Ok(link) => {
Expand All @@ -334,7 +336,7 @@ pub async fn redirect(
Err(ServerError::Database(e)) => {
info!(
"Link was not found: http://{}/{} \n {}",
&config.public_url, &data.0, e
&config.public_url, &data, e
);
Ok(HttpResponse::NotFound().body(
r#"<!DOCTYPE html>
Expand Down Expand Up @@ -373,7 +375,7 @@ pub async fn process_create_link_json(
) -> Result<HttpResponse, ServerError> {
let new_link = queries::create_link(&id, data.into_inner(), &config).await;
match new_link {
Ok(item) => Ok(HttpResponse::Ok().json2(&Status::Success(Message {
Ok(item) => Ok(HttpResponse::Ok().json(&Status::Success(Message {
message: format!("Successfully saved link: {}", item.item.code),
}))),
Err(e) => Err(e),
Expand All @@ -388,7 +390,7 @@ pub async fn process_update_link_json(
) -> Result<HttpResponse, ServerError> {
let new_link = queries::update_link(&id, data.into_inner(), &config).await;
match new_link {
Ok(item) => Ok(HttpResponse::Ok().json2(&Status::Success(Message {
Ok(item) => Ok(HttpResponse::Ok().json(&Status::Success(Message {
message: format!("Successfully updated link: {}", item.item.code),
}))),
Err(e) => Err(e),
Expand All @@ -402,7 +404,7 @@ pub async fn process_delete_link_json(
data: web::Json<LinkDelta>,
) -> Result<HttpResponse, ServerError> {
queries::delete_link(&id, &data.code, &config).await?;
Ok(HttpResponse::Ok().json2(&Status::Success(Message {
Ok(HttpResponse::Ok().json(&Status::Success(Message {
message: format!("Successfully deleted link: {}", &data.code),
})))
}
6 changes: 3 additions & 3 deletions shared/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ license = "MIT OR Apache-2.0"
name = "pslink-shared"
readme = "../pslink/README.md"
repository = "https://github.com/enaut/pslink/"
version = "0.4.3"
version = "0.4.4"

[dependencies]
serde = {version="1.0", features = ["derive"]}
chrono = {version = "0.4", features = ["serde"] }
enum-map = {version="1", features = ["serde"]}
strum_macros = "0.21"
strum = "0.21"
strum_macros = "0.22"
strum = "0.22"
Loading

0 comments on commit d5160ba

Please sign in to comment.