0
0
Fork 0
mirror of https://github.com/dani-garcia/vaultwarden synced 2024-12-15 18:13:43 +01:00

Remove unnecessary clones and other clippy fixes

This commit is contained in:
Daniel García 2019-11-02 17:39:01 +01:00
parent e2e3712921
commit d29b6bee28
No known key found for this signature in database
GPG key ID: FC8A7D14C3CD543A
8 changed files with 23 additions and 35 deletions

View file

@ -59,7 +59,7 @@ pub struct FolderData {
fn post_folders(data: JsonUpcase<FolderData>, headers: Headers, conn: DbConn, nt: Notify) -> JsonResult { fn post_folders(data: JsonUpcase<FolderData>, headers: Headers, conn: DbConn, nt: Notify) -> JsonResult {
let data: FolderData = data.into_inner().data; let data: FolderData = data.into_inner().data;
let mut folder = Folder::new(headers.user.uuid.clone(), data.Name); let mut folder = Folder::new(headers.user.uuid, data.Name);
folder.save(&conn)?; folder.save(&conn)?;
nt.send_folder_update(UpdateType::FolderCreate, &folder); nt.send_folder_update(UpdateType::FolderCreate, &folder);

View file

@ -77,7 +77,7 @@ fn create_organization(headers: Headers, data: JsonUpcase<OrgData>, conn: DbConn
let data: OrgData = data.into_inner().data; let data: OrgData = data.into_inner().data;
let org = Organization::new(data.Name, data.BillingEmail); let org = Organization::new(data.Name, data.BillingEmail);
let mut user_org = UserOrganization::new(headers.user.uuid.clone(), org.uuid.clone()); let mut user_org = UserOrganization::new(headers.user.uuid, org.uuid.clone());
let collection = Collection::new(org.uuid.clone(), data.CollectionName); let collection = Collection::new(org.uuid.clone(), data.CollectionName);
user_org.akey = data.Key; user_org.akey = data.Key;
@ -221,7 +221,7 @@ fn post_organization_collections(
None => err!("Can't find organization details"), None => err!("Can't find organization details"),
}; };
let collection = Collection::new(org.uuid.clone(), data.Name); let collection = Collection::new(org.uuid, data.Name);
collection.save(&conn)?; collection.save(&conn)?;
Ok(Json(collection.to_json())) Ok(Json(collection.to_json()))
@ -262,7 +262,7 @@ fn post_organization_collection_update(
err!("Collection is not owned by organization"); err!("Collection is not owned by organization");
} }
collection.name = data.Name.clone(); collection.name = data.Name;
collection.save(&conn)?; collection.save(&conn)?;
Ok(Json(collection.to_json())) Ok(Json(collection.to_json()))
@ -581,7 +581,7 @@ fn reinvite_user(org_id: String, user_org: String, headers: AdminHeaders, conn:
Some(headers.user.email), Some(headers.user.email),
)?; )?;
} else { } else {
let invitation = Invitation::new(user.email.clone()); let invitation = Invitation::new(user.email);
invitation.save(&conn)?; invitation.save(&conn)?;
} }

View file

@ -167,7 +167,7 @@ fn activate_duo(data: JsonUpcase<EnableDuoData>, headers: Headers, conn: DbConn)
}; };
let type_ = TwoFactorType::Duo; let type_ = TwoFactorType::Duo;
let twofactor = TwoFactor::new(headers.user.uuid.clone(), type_, data_str); let twofactor = TwoFactor::new(headers.user.uuid, type_, data_str);
twofactor.save(&conn)?; twofactor.save(&conn)?;
Ok(Json(json!({ Ok(Json(json!({

View file

@ -164,7 +164,7 @@ fn activate_u2f(data: JsonUpcase<EnableU2FData>, headers: Headers, conn: DbConn)
err!("Error registering U2F token") err!("Error registering U2F token")
} }
let registration = U2F.register_response(challenge.clone(), response.into())?; let registration = U2F.register_response(challenge, response.into())?;
let full_registration = U2FRegistration { let full_registration = U2FRegistration {
id: data.Id.into_i32()?, id: data.Id.into_i32()?,
name: data.Name, name: data.Name,

View file

@ -65,9 +65,8 @@ fn icon(domain: String) -> Content<Vec<u8>> {
} }
fn check_icon_domain_is_blacklisted(domain: &str) -> bool { fn check_icon_domain_is_blacklisted(domain: &str) -> bool {
let mut is_blacklisted = false; let mut is_blacklisted = CONFIG.icon_blacklist_non_global_ips()
if CONFIG.icon_blacklist_non_global_ips() { && (domain, 0)
is_blacklisted = (domain, 0)
.to_socket_addrs() .to_socket_addrs()
.map(|x| { .map(|x| {
for ip_port in x { for ip_port in x {
@ -79,7 +78,6 @@ fn check_icon_domain_is_blacklisted(domain: &str) -> bool {
false false
}) })
.unwrap_or(false); .unwrap_or(false);
}
// Skip the regex check if the previous one is true already // Skip the regex check if the previous one is true already
if !is_blacklisted { if !is_blacklisted {
@ -279,11 +277,7 @@ fn get_page_with_cookies(url: &str, cookie_str: &str) -> Result<Response, Error>
} }
if cookie_str.is_empty() { if cookie_str.is_empty() {
CLIENT CLIENT.get(url).send()?.error_for_status().map_err(Into::into)
.get(url)
.send()?
.error_for_status()
.map_err(Into::into)
} else { } else {
CLIENT CLIENT
.get(url) .get(url)

View file

@ -118,7 +118,7 @@ pub fn generate_invite_claims(
uuid: String, uuid: String,
email: String, email: String,
org_id: Option<String>, org_id: Option<String>,
org_user_id: Option<String>, user_org_id: Option<String>,
invited_by_email: Option<String>, invited_by_email: Option<String>,
) -> InviteJWTClaims { ) -> InviteJWTClaims {
let time_now = Utc::now().naive_utc(); let time_now = Utc::now().naive_utc();
@ -126,11 +126,11 @@ pub fn generate_invite_claims(
nbf: time_now.timestamp(), nbf: time_now.timestamp(),
exp: (time_now + Duration::days(5)).timestamp(), exp: (time_now + Duration::days(5)).timestamp(),
iss: JWT_INVITE_ISSUER.to_string(), iss: JWT_INVITE_ISSUER.to_string(),
sub: uuid.clone(), sub: uuid,
email: email.clone(), email,
org_id: org_id.clone(), org_id,
user_org_id: org_user_id.clone(), user_org_id,
invited_by_email: invited_by_email.clone(), invited_by_email,
} }
} }

View file

@ -368,23 +368,17 @@ make_config! {
fn validate_config(cfg: &ConfigItems) -> Result<(), Error> { fn validate_config(cfg: &ConfigItems) -> Result<(), Error> {
let db_url = cfg.database_url.to_lowercase(); let db_url = cfg.database_url.to_lowercase();
if cfg!(feature = "sqlite") { if cfg!(feature = "sqlite") && (db_url.starts_with("mysql:") || db_url.starts_with("postgresql:")) {
if db_url.starts_with("mysql:") || db_url.starts_with("postgresql:") {
err!("`DATABASE_URL` is meant for MySQL or Postgres, while this server is meant for SQLite") err!("`DATABASE_URL` is meant for MySQL or Postgres, while this server is meant for SQLite")
} }
}
if cfg!(feature = "mysql") { if cfg!(feature = "mysql") && !db_url.starts_with("mysql:") {
if !db_url.starts_with("mysql:") {
err!("`DATABASE_URL` should start with mysql: when using the MySQL server") err!("`DATABASE_URL` should start with mysql: when using the MySQL server")
} }
}
if cfg!(feature = "postgresql") { if cfg!(feature = "postgresql") && !db_url.starts_with("postgresql:") {
if !db_url.starts_with("postgresql:") {
err!("`DATABASE_URL` should start with postgresql: when using the PostgreSQL server") err!("`DATABASE_URL` should start with postgresql: when using the PostgreSQL server")
} }
}
if let Some(ref token) = cfg.admin_token { if let Some(ref token) = cfg.admin_token {
if token.trim().is_empty() { if token.trim().is_empty() {

View file

@ -105,7 +105,7 @@ pub fn send_invite(
String::from(address), String::from(address),
org_id.clone(), org_id.clone(),
org_user_id.clone(), org_user_id.clone(),
invited_by_email.clone(), invited_by_email,
); );
let invite_token = encode_jwt(&claims); let invite_token = encode_jwt(&claims);