vw_small

Hardened fork of Vaultwarden (https://github.com/dani-garcia/vaultwarden) with fewer features.
git clone https://git.philomathiclife.com/repos/vw_small
Log | Files | Refs | README

commit 3e5971b9dbfa0eabe69b682d848009741b435758
parent 47c2625d38f902c200e083da4ea58fc40bfe3775
Author: Jake Howard <git@theorangeone.net>
Date:   Sat, 27 Mar 2021 15:07:26 +0000

Remove unnecessary result return types

Diffstat:
Msrc/api/admin.rs | 14+++++++-------
Msrc/api/core/accounts.rs | 11++++++-----
Msrc/api/core/ciphers.rs | 14+++++++-------
Msrc/api/core/folders.rs | 6+++---
Msrc/api/core/mod.rs | 21+++++++++++----------
Msrc/api/core/organizations.rs | 50+++++++++++++++++++++++++-------------------------
Msrc/api/core/two_factor/mod.rs | 6+++---
Msrc/api/notifications.rs | 8++++----
8 files changed, 66 insertions(+), 64 deletions(-)

diff --git a/src/api/admin.rs b/src/api/admin.rs @@ -13,7 +13,7 @@ use rocket::{ use rocket_contrib::json::Json; use crate::{ - api::{ApiResult, EmptyResult, JsonResult, NumberOrString}, + api::{ApiResult, EmptyResult, NumberOrString}, auth::{decode_admin, encode_jwt, generate_admin_claims, ClientIp}, config::ConfigBuilder, db::{backup_database, models::*, DbConn, DbConnType}, @@ -291,17 +291,17 @@ fn test_smtp(data: Json<InviteData>, _token: AdminToken) -> EmptyResult { } #[get("/logout")] -fn logout(mut cookies: Cookies, referer: Referer) -> Result<Redirect, ()> { +fn logout(mut cookies: Cookies, referer: Referer) -> Redirect { cookies.remove(Cookie::named(COOKIE_NAME)); - Ok(Redirect::to(admin_url(referer))) + Redirect::to(admin_url(referer)) } #[get("/users")] -fn get_users_json(_token: AdminToken, conn: DbConn) -> JsonResult { +fn get_users_json(_token: AdminToken, conn: DbConn) -> Json<Value> { let users = User::get_all(&conn); let users_json: Vec<Value> = users.iter().map(|u| u.to_json(&conn)).collect(); - Ok(Json(Value::Array(users_json))) + Json(Value::Array(users_json)) } #[get("/users/overview")] @@ -548,9 +548,9 @@ fn diagnostics(_token: AdminToken, _conn: DbConn) -> ApiResult<Html<String>> { } #[get("/diagnostics/config")] -fn get_diagnostics_config(_token: AdminToken) -> JsonResult { +fn get_diagnostics_config(_token: AdminToken) -> Json<Value> { let support_json = CONFIG.get_support_json(); - Ok(Json(support_json)) + Json(support_json) } #[post("/config", data = "<data>")] diff --git a/src/api/core/accounts.rs b/src/api/core/accounts.rs @@ -1,5 +1,6 @@ use chrono::Utc; use rocket_contrib::json::Json; +use serde_json::Value; use crate::{ api::{EmptyResult, JsonResult, JsonUpcase, Notify, NumberOrString, PasswordData, UpdateType}, @@ -148,8 +149,8 @@ fn register(data: JsonUpcase<RegisterData>, conn: DbConn) -> EmptyResult { } #[get("/accounts/profile")] -fn profile(headers: Headers, conn: DbConn) -> JsonResult { - Ok(Json(headers.user.to_json(&conn))) +fn profile(headers: Headers, conn: DbConn) -> Json<Value> { + Json(headers.user.to_json(&conn)) } #[derive(Deserialize, Debug)] @@ -610,7 +611,7 @@ struct PreloginData { } #[post("/accounts/prelogin", data = "<data>")] -fn prelogin(data: JsonUpcase<PreloginData>, conn: DbConn) -> JsonResult { +fn prelogin(data: JsonUpcase<PreloginData>, conn: DbConn) -> Json<Value> { let data: PreloginData = data.into_inner().data; let (kdf_type, kdf_iter) = match User::find_by_mail(&data.Email, &conn) { @@ -618,10 +619,10 @@ fn prelogin(data: JsonUpcase<PreloginData>, conn: DbConn) -> JsonResult { None => (User::CLIENT_KDF_TYPE_DEFAULT, User::CLIENT_KDF_ITER_DEFAULT), }; - Ok(Json(json!({ + Json(json!({ "Kdf": kdf_type, "KdfIterations": kdf_iter - }))) + })) } #[derive(Deserialize)] #[allow(non_snake_case)] diff --git a/src/api/core/ciphers.rs b/src/api/core/ciphers.rs @@ -84,7 +84,7 @@ struct SyncData { } #[get("/sync?<data..>")] -fn sync(data: Form<SyncData>, headers: Headers, conn: DbConn) -> JsonResult { +fn sync(data: Form<SyncData>, headers: Headers, conn: DbConn) -> Json<Value> { let user_json = headers.user.to_json(&conn); let folders = Folder::find_by_user(&headers.user.uuid, &conn); @@ -113,10 +113,10 @@ fn sync(data: Form<SyncData>, headers: Headers, conn: DbConn) -> JsonResult { let domains_json = if data.exclude_domains { Value::Null } else { - api::core::_get_eq_domains(headers, true).unwrap().into_inner() + api::core::_get_eq_domains(headers, true).into_inner() }; - Ok(Json(json!({ + Json(json!({ "Profile": user_json, "Folders": folders_json, "Collections": collections_json, @@ -125,11 +125,11 @@ fn sync(data: Form<SyncData>, headers: Headers, conn: DbConn) -> JsonResult { "Domains": domains_json, "Sends": sends_json, "Object": "sync" - }))) + })) } #[get("/ciphers")] -fn get_ciphers(headers: Headers, conn: DbConn) -> JsonResult { +fn get_ciphers(headers: Headers, conn: DbConn) -> Json<Value> { let ciphers = Cipher::find_by_user_visible(&headers.user.uuid, &conn); let ciphers_json: Vec<Value> = ciphers @@ -137,11 +137,11 @@ fn get_ciphers(headers: Headers, conn: DbConn) -> JsonResult { .map(|c| c.to_json(&headers.host, &headers.user.uuid, &conn)) .collect(); - Ok(Json(json!({ + Json(json!({ "Data": ciphers_json, "Object": "list", "ContinuationToken": null - }))) + })) } #[get("/ciphers/<uuid>")] diff --git a/src/api/core/folders.rs b/src/api/core/folders.rs @@ -20,16 +20,16 @@ pub fn routes() -> Vec<rocket::Route> { } #[get("/folders")] -fn get_folders(headers: Headers, conn: DbConn) -> JsonResult { +fn get_folders(headers: Headers, conn: DbConn) -> Json<Value> { let folders = Folder::find_by_user(&headers.user.uuid, &conn); let folders_json: Vec<Value> = folders.iter().map(Folder::to_json).collect(); - Ok(Json(json!({ + Json(json!({ "Data": folders_json, "Object": "list", "ContinuationToken": null, - }))) + })) } #[get("/folders/<uuid>")] diff --git a/src/api/core/mod.rs b/src/api/core/mod.rs @@ -34,17 +34,18 @@ pub fn routes() -> Vec<Route> { // use rocket::Route; use rocket_contrib::json::Json; +use rocket::response::Response; use serde_json::Value; use crate::{ - api::{EmptyResult, JsonResult, JsonUpcase}, + api::{JsonResult, JsonUpcase}, auth::Headers, db::DbConn, error::Error, }; #[put("/devices/identifier/<uuid>/clear-token")] -fn clear_device_token(uuid: String) -> EmptyResult { +fn clear_device_token<'a>(uuid: String) -> Response<'a> { // This endpoint doesn't have auth header let _ = uuid; @@ -53,11 +54,11 @@ fn clear_device_token(uuid: String) -> EmptyResult { // This only clears push token // https://github.com/bitwarden/core/blob/master/src/Api/Controllers/DevicesController.cs#L109 // https://github.com/bitwarden/core/blob/master/src/Core/Services/Implementations/DeviceService.cs#L37 - Ok(()) + Response::new() } #[put("/devices/identifier/<uuid>/token", data = "<data>")] -fn put_device_token(uuid: String, data: JsonUpcase<Value>, headers: Headers) -> JsonResult { +fn put_device_token(uuid: String, data: JsonUpcase<Value>, headers: Headers) -> Json<Value> { let _data: Value = data.into_inner().data; // Data has a single string value "PushToken" let _ = uuid; @@ -65,13 +66,13 @@ fn put_device_token(uuid: String, data: JsonUpcase<Value>, headers: Headers) -> // TODO: This should save the push token, but we don't have push functionality - Ok(Json(json!({ + Json(json!({ "Id": headers.device.uuid, "Name": headers.device.name, "Type": headers.device.atype, "Identifier": headers.device.uuid, "CreationDate": crate::util::format_date(&headers.device.created_at), - }))) + })) } #[derive(Serialize, Deserialize, Debug)] @@ -85,11 +86,11 @@ struct GlobalDomain { const GLOBAL_DOMAINS: &str = include_str!("../../static/global_domains.json"); #[get("/settings/domains")] -fn get_eq_domains(headers: Headers) -> JsonResult { +fn get_eq_domains(headers: Headers) -> Json<Value> { _get_eq_domains(headers, false) } -fn _get_eq_domains(headers: Headers, no_excluded: bool) -> JsonResult { +fn _get_eq_domains(headers: Headers, no_excluded: bool) -> Json<Value> { let user = headers.user; use serde_json::from_str; @@ -106,11 +107,11 @@ fn _get_eq_domains(headers: Headers, no_excluded: bool) -> JsonResult { globals.retain(|g| !g.Excluded); } - Ok(Json(json!({ + Json(json!({ "EquivalentDomains": equivalent_domains, "GlobalEquivalentDomains": globals, "Object": "domains", - }))) + })) } #[derive(Deserialize, Debug)] diff --git a/src/api/core/organizations.rs b/src/api/core/organizations.rs @@ -192,8 +192,8 @@ fn post_organization( // GET /api/collections?writeOnly=false #[get("/collections")] -fn get_user_collections(headers: Headers, conn: DbConn) -> JsonResult { - Ok(Json(json!({ +fn get_user_collections(headers: Headers, conn: DbConn) -> Json<Value> { + Json(json!({ "Data": Collection::find_by_user_uuid(&headers.user.uuid, &conn) .iter() @@ -201,12 +201,12 @@ fn get_user_collections(headers: Headers, conn: DbConn) -> JsonResult { .collect::<Value>(), "Object": "list", "ContinuationToken": null, - }))) + })) } #[get("/organizations/<org_id>/collections")] -fn get_org_collections(org_id: String, _headers: AdminHeaders, conn: DbConn) -> JsonResult { - Ok(Json(json!({ +fn get_org_collections(org_id: String, _headers: AdminHeaders, conn: DbConn) -> Json<Value> { + Json(json!({ "Data": Collection::find_by_organization(&org_id, &conn) .iter() @@ -214,7 +214,7 @@ fn get_org_collections(org_id: String, _headers: AdminHeaders, conn: DbConn) -> .collect::<Value>(), "Object": "list", "ContinuationToken": null, - }))) + })) } #[post("/organizations/<org_id>/collections", data = "<data>")] @@ -441,30 +441,30 @@ struct OrgIdData { } #[get("/ciphers/organization-details?<data..>")] -fn get_org_details(data: Form<OrgIdData>, headers: Headers, conn: DbConn) -> JsonResult { +fn get_org_details(data: Form<OrgIdData>, headers: Headers, conn: DbConn) -> Json<Value> { let ciphers = Cipher::find_by_org(&data.organization_id, &conn); let ciphers_json: Vec<Value> = ciphers .iter() .map(|c| c.to_json(&headers.host, &headers.user.uuid, &conn)) .collect(); - Ok(Json(json!({ + Json(json!({ "Data": ciphers_json, "Object": "list", "ContinuationToken": null, - }))) + })) } #[get("/organizations/<org_id>/users")] -fn get_org_users(org_id: String, _headers: ManagerHeadersLoose, conn: DbConn) -> JsonResult { +fn get_org_users(org_id: String, _headers: ManagerHeadersLoose, conn: DbConn) -> Json<Value> { let users = UserOrganization::find_by_org(&org_id, &conn); let users_json: Vec<Value> = users.iter().map(|c| c.to_json_user_details(&conn)).collect(); - Ok(Json(json!({ + Json(json!({ "Data": users_json, "Object": "list", "ContinuationToken": null, - }))) + })) } #[derive(Deserialize)] @@ -930,15 +930,15 @@ fn post_org_import( } #[get("/organizations/<org_id>/policies")] -fn list_policies(org_id: String, _headers: AdminHeaders, conn: DbConn) -> JsonResult { +fn list_policies(org_id: String, _headers: AdminHeaders, conn: DbConn) -> Json<Value> { let policies = OrgPolicy::find_by_org(&org_id, &conn); let policies_json: Vec<Value> = policies.iter().map(OrgPolicy::to_json).collect(); - Ok(Json(json!({ + Json(json!({ "Data": policies_json, "Object": "list", "ContinuationToken": null - }))) + })) } #[get("/organizations/<org_id>/policies/token?<token>")] @@ -1017,8 +1017,8 @@ fn get_organization_tax(org_id: String, _headers: Headers, _conn: DbConn) -> Emp } #[get("/plans")] -fn get_plans(_headers: Headers, _conn: DbConn) -> JsonResult { - Ok(Json(json!({ +fn get_plans(_headers: Headers, _conn: DbConn) -> Json<Value> { + Json(json!({ "Object": "list", "Data": [ { @@ -1065,17 +1065,17 @@ fn get_plans(_headers: Headers, _conn: DbConn) -> JsonResult { } ], "ContinuationToken": null - }))) + })) } #[get("/plans/sales-tax-rates")] -fn get_plans_tax_rates(_headers: Headers, _conn: DbConn) -> JsonResult { +fn get_plans_tax_rates(_headers: Headers, _conn: DbConn) -> Json<Value> { // Prevent a 404 error, which also causes Javascript errors. - Ok(Json(json!({ + Json(json!({ "Object": "list", "Data": [], "ContinuationToken": null - }))) + })) } #[derive(Deserialize, Debug)] @@ -1128,7 +1128,7 @@ fn import(org_id: String, data: JsonUpcase<OrgImportData>, headers: Headers, con // If user is not part of the organization, but it exists } else if UserOrganization::find_by_email_and_org(&user_data.Email, &org_id, &conn).is_none() { if let Some (user) = User::find_by_mail(&user_data.Email, &conn) { - + let user_org_status = if CONFIG.mail_enabled() { UserOrgStatus::Invited as i32 } else { @@ -1157,18 +1157,18 @@ fn import(org_id: String, data: JsonUpcase<OrgImportData>, headers: Headers, con Some(headers.user.email.clone()), )?; } - } + } } } // If this flag is enabled, any user that isn't provided in the Users list will be removed (by default they will be kept unless they have Deleted == true) if data.OverwriteExisting { - for user_org in UserOrganization::find_by_org_and_type(&org_id, UserOrgType::User as i32, &conn) { + for user_org in UserOrganization::find_by_org_and_type(&org_id, UserOrgType::User as i32, &conn) { if let Some (user_email) = User::find_by_uuid(&user_org.user_uuid, &conn).map(|u| u.email) { if !data.Users.iter().any(|u| u.Email == user_email) { user_org.delete(&conn)?; } - } + } } } diff --git a/src/api/core/two_factor/mod.rs b/src/api/core/two_factor/mod.rs @@ -38,15 +38,15 @@ pub fn routes() -> Vec<Route> { } #[get("/two-factor")] -fn get_twofactor(headers: Headers, conn: DbConn) -> JsonResult { +fn get_twofactor(headers: Headers, conn: DbConn) -> Json<Value> { let twofactors = TwoFactor::find_by_user(&headers.user.uuid, &conn); let twofactors_json: Vec<Value> = twofactors.iter().map(TwoFactor::to_json_provider).collect(); - Ok(Json(json!({ + Json(json!({ "Data": twofactors_json, "Object": "list", "ContinuationToken": null, - }))) + })) } #[post("/two-factor/get-recover", data = "<data>")] diff --git a/src/api/notifications.rs b/src/api/notifications.rs @@ -5,7 +5,7 @@ use rocket_contrib::json::Json; use serde_json::Value as JsonValue; use crate::{ - api::{EmptyResult, JsonResult}, + api::EmptyResult, auth::Headers, db::DbConn, Error, CONFIG, @@ -31,7 +31,7 @@ fn websockets_err() -> EmptyResult { } #[post("/hub/negotiate")] -fn negotiate(_headers: Headers, _conn: DbConn) -> JsonResult { +fn negotiate(_headers: Headers, _conn: DbConn) -> Json<JsonValue> { use crate::crypto; use data_encoding::BASE64URL; @@ -47,10 +47,10 @@ fn negotiate(_headers: Headers, _conn: DbConn) -> JsonResult { // Rocket SSE support: https://github.com/SergioBenitez/Rocket/issues/33 // {"transport":"ServerSentEvents", "transferFormats":["Text"]}, // {"transport":"LongPolling", "transferFormats":["Text","Binary"]} - Ok(Json(json!({ + Json(json!({ "connectionId": conn_id, "availableTransports": available_transports - }))) + })) } //