diff options
author | Bryan Newbold <bnewbold@robocracy.org> | 2019-01-09 00:12:16 -0800 |
---|---|---|
committer | Bryan Newbold <bnewbold@robocracy.org> | 2019-01-09 00:12:16 -0800 |
commit | 5dca65fa0992bedb826aa7a762dc69e1beaed2de (patch) | |
tree | 2f736147f38543632ec2c2135fc48d382f727ec0 /rust | |
parent | 9979d34df0cdef3be2fb40b6da4c4eaddeb5ba79 (diff) | |
download | fatcat-5dca65fa0992bedb826aa7a762dc69e1beaed2de.tar.gz fatcat-5dca65fa0992bedb826aa7a762dc69e1beaed2de.zip |
some clippy nits
Diffstat (limited to 'rust')
-rw-r--r-- | rust/src/auth.rs | 43 | ||||
-rw-r--r-- | rust/src/bin/fatcat-export.rs | 7 | ||||
-rw-r--r-- | rust/src/editing.rs | 8 | ||||
-rw-r--r-- | rust/src/endpoints.rs | 11 | ||||
-rw-r--r-- | rust/src/entity_crud.rs | 41 | ||||
-rw-r--r-- | rust/src/identifiers.rs | 2 | ||||
-rw-r--r-- | rust/src/lib.rs | 3 |
7 files changed, 58 insertions, 57 deletions
diff --git a/rust/src/auth.rs b/rust/src/auth.rs index 255da8dd..07dfb4f6 100644 --- a/rust/src/auth.rs +++ b/rust/src/auth.rs @@ -110,7 +110,7 @@ fn new_auth_ironerror(m: &str) -> iron::error::IronError { ) } -#[derive(Debug)] +#[derive(Debug, Default)] pub struct OpenAuthMiddleware; impl OpenAuthMiddleware { @@ -131,7 +131,7 @@ impl iron::middleware::BeforeMiddleware for OpenAuthMiddleware { } } -#[derive(Debug)] +#[derive(Debug, Default)] pub struct MacaroonAuthMiddleware; impl MacaroonAuthMiddleware { @@ -183,17 +183,17 @@ impl AuthConfectionary { pub fn new( location: String, identifier: String, - key_base64: String, + key_base64: &str, ) -> Result<AuthConfectionary> { macaroon::initialize().unwrap(); let key = BASE64.decode(key_base64.as_bytes())?; let mut root_keys = HashMap::new(); root_keys.insert(identifier.clone(), key.clone()); Ok(AuthConfectionary { - location: location, - identifier: identifier, - key: key, - root_keys: root_keys, + location, + identifier, + key, + root_keys, }) } @@ -201,12 +201,12 @@ impl AuthConfectionary { AuthConfectionary::new( "test.fatcat.wiki".to_string(), "dummy".to_string(), - BASE64.encode(DUMMY_KEY), + &BASE64.encode(DUMMY_KEY), ) .unwrap() } - pub fn add_keypair(&mut self, identifier: String, key_base64: String) -> Result<()> { + pub fn add_keypair(&mut self, identifier: String, key_base64: &str) -> Result<()> { let key = BASE64.decode(key_base64.as_bytes())?; self.root_keys.insert(identifier, key); Ok(()) @@ -392,7 +392,7 @@ impl AuthConfectionary { let editor_row = self.parse_macaroon_token(conn, &token, endpoint)?; Ok(Some(AuthContext { editor_id: FatCatId::from_uuid(&editor_row.id), - editor_row: editor_row, + editor_row, })) } @@ -476,20 +476,17 @@ pub fn env_confectionary() -> Result<AuthConfectionary> { let auth_key = env::var("AUTH_SECRET_KEY").expect("AUTH_SECRET_KEY must be set"); let auth_key_ident = env::var("AUTH_KEY_IDENT").expect("AUTH_KEY_IDENT must be set"); info!("Loaded primary auth key: {}", auth_key_ident); - let mut confectionary = AuthConfectionary::new(auth_location, auth_key_ident, auth_key)?; - match env::var("AUTH_ALT_KEYS") { - Ok(var) => { - for pair in var.split(",") { - let pair: Vec<&str> = pair.split(":").collect(); - if pair.len() != 2 { - println!("{:#?}", pair); - bail!("couldn't parse keypair from AUTH_ALT_KEYS (expected 'ident:key' pairs separated by commas)"); - } - info!("Loading alt auth key: {}", pair[0]); - confectionary.add_keypair(pair[0].to_string(), pair[1].to_string())?; + let mut confectionary = AuthConfectionary::new(auth_location, auth_key_ident, &auth_key)?; + if let Ok(var) = env::var("AUTH_ALT_KEYS") { + for pair in var.split(',') { + let pair: Vec<&str> = pair.split(':').collect(); + if pair.len() != 2 { + println!("{:#?}", pair); + bail!("couldn't parse keypair from AUTH_ALT_KEYS (expected 'ident:key' pairs separated by commas)"); } + info!("Loading alt auth key: {}", pair[0]); + confectionary.add_keypair(pair[0].to_string(), pair[1])?; } - Err(_) => (), - } + }; Ok(confectionary) } diff --git a/rust/src/bin/fatcat-export.rs b/rust/src/bin/fatcat-export.rs index 889d7dff..157070e5 100644 --- a/rust/src/bin/fatcat-export.rs +++ b/rust/src/bin/fatcat-export.rs @@ -1,5 +1,8 @@ //! JSON Export Helper +// using closures as a Result/? hack +#![allow(clippy::redundant_closure_call)] + #[macro_use] extern crate clap; #[macro_use] @@ -100,7 +103,7 @@ fn loop_printer( let mut buf_output = BufWriter::new(output); for line in output_receiver { buf_output.write_all(&line.into_bytes())?; - buf_output.write(b"\n")?; + buf_output.write_all(b"\n")?; buf_output.flush()?; } drop(done_sender); @@ -108,7 +111,7 @@ fn loop_printer( } fn parse_line(s: &str) -> Result<IdentRow> { - let fields: Vec<String> = s.split("\t").map(|v| v.to_string()).collect(); + let fields: Vec<String> = s.split('\t').map(|v| v.to_string()).collect(); if fields.len() != 3 { bail!("Invalid input line"); } diff --git a/rust/src/editing.rs b/rust/src/editing.rs index e3777e24..b501a6cf 100644 --- a/rust/src/editing.rs +++ b/rust/src/editing.rs @@ -26,7 +26,7 @@ impl EditContext { if count > 0 { return Err(ErrorKind::EditgroupAlreadyAccepted(self.editgroup_id.to_string()).into()); } - return Ok(()); + Ok(()) } } @@ -48,10 +48,10 @@ pub fn make_edit_context( (None, false) => FatCatId::from_uuid(&get_or_create_editgroup(editor_id.to_uuid(), conn)?), }; Ok(EditContext { - editor_id: editor_id, - editgroup_id: editgroup_id, + editor_id, + editgroup_id, extra_json: None, - autoaccept: autoaccept, + autoaccept, }) } diff --git a/rust/src/endpoints.rs b/rust/src/endpoints.rs index 91db1027..c1033bc7 100644 --- a/rust/src/endpoints.rs +++ b/rust/src/endpoints.rs @@ -4,6 +4,9 @@ //! response types (mapping to HTTP statuses. Some contain actual endpoint implementations, but //! most implementation lives in the server module. +// using closures as a Result/? hack +#![allow(clippy::redundant_closure_call)] + use crate::auth::*; use crate::database_models::EntityEditRow; use crate::editing::*; @@ -1075,10 +1078,10 @@ impl Api for Server { let mut entity = entity.clone(); match entity.editor_id.clone() { Some(editor_id) => { - if !auth_context.has_role(FatcatRole::Admin) { - if editor_id != auth_context.editor_id.to_string() { - bail!("not authorized to create editgroups in others' names"); - } + if editor_id != auth_context.editor_id.to_string() + && !auth_context.has_role(FatcatRole::Admin) + { + bail!("not authorized to create editgroups in others' names"); } } None => { diff --git a/rust/src/entity_crud.rs b/rust/src/entity_crud.rs index d5c8081b..186ee20c 100644 --- a/rust/src/entity_crud.rs +++ b/rust/src/entity_crud.rs @@ -103,7 +103,7 @@ pub struct ExpandFlags { impl FromStr for ExpandFlags { type Err = Error; fn from_str(param: &str) -> Result<ExpandFlags> { - let list: Vec<&str> = param.split_terminator(",").collect(); + let list: Vec<&str> = param.split_terminator(',').collect(); Ok(ExpandFlags::from_str_list(&list)) } } @@ -189,7 +189,7 @@ pub struct HideFlags { impl FromStr for HideFlags { type Err = Error; fn from_str(param: &str) -> Result<HideFlags> { - let list: Vec<&str> = param.split_terminator(",").collect(); + let list: Vec<&str> = param.split_terminator(',').collect(); Ok(HideFlags::from_str_list(&list)) } } @@ -363,7 +363,7 @@ macro_rules! generic_db_create_batch { .map(|(rev_id, ident_id)| Self::EditNewRow { editgroup_id: edit_context.editgroup_id.to_uuid(), rev_id: Some(rev_id), - ident_id: ident_id, + ident_id, redirect_id: None, prev_rev: None, extra_json: edit_context.extra_json.clone(), @@ -809,7 +809,7 @@ impl EntityCrud for ContainerEntity { name: Some(rev_row.name), abbrev: rev_row.abbrev, coden: rev_row.coden, - state: state, + state, ident: ident_id, revision: Some(rev_row.id.to_string()), redirect: redirect_id, @@ -920,7 +920,7 @@ impl EntityCrud for CreatorEntity { surname: rev_row.surname, orcid: rev_row.orcid, wikidata_qid: rev_row.wikidata_qid, - state: state, + state, ident: ident_id, revision: Some(rev_row.id.to_string()), redirect: redirect_id, @@ -1052,7 +1052,7 @@ impl EntityCrud for FileEntity { urls: Some(urls), mimetype: rev_row.mimetype, release_ids: Some(release_ids.iter().map(|fcid| fcid.to_string()).collect()), - state: state, + state, ident: ident_id, revision: Some(rev_row.id.to_string()), redirect: redirect_id, @@ -1235,7 +1235,7 @@ impl EntityCrud for FilesetEntity { manifest: Some(manifest), urls: Some(urls), release_ids: Some(release_ids.iter().map(|fcid| fcid.to_string()).collect()), - state: state, + state, ident: ident_id, revision: Some(rev_row.id.to_string()), redirect: redirect_id, @@ -1448,7 +1448,7 @@ impl EntityCrud for WebcaptureEntity { original_url: Some(rev_row.original_url), timestamp: Some(chrono::DateTime::from_utc(rev_row.timestamp, chrono::Utc)), release_ids: Some(release_ids.iter().map(|fcid| fcid.to_string()).collect()), - state: state, + state, ident: ident_id, revision: Some(rev_row.id.to_string()), redirect: redirect_id, @@ -1762,7 +1762,7 @@ impl EntityCrud for ReleaseEntity { .map(|(rev_id, ident_id)| Self::EditNewRow { editgroup_id: edit_context.editgroup_id.to_uuid(), rev_id: Some(rev_id), - ident_id: ident_id, + ident_id, redirect_id: None, prev_rev: None, extra_json: edit_context.extra_json.clone(), @@ -1837,9 +1837,10 @@ impl EntityCrud for ReleaseEntity { ), }; - let abstracts: Option<Vec<ReleaseEntityAbstracts>> = match hide.abstracts { - true => None, - false => Some( + let abstracts: Option<Vec<ReleaseEntityAbstracts>> = if hide.abstracts { + None + } else { + Some( release_rev_abstract::table .inner_join(abstracts::table) .filter(release_rev_abstract::release_rev.eq(rev_row.id)) @@ -1854,7 +1855,7 @@ impl EntityCrud for ReleaseEntity { }, ) .collect(), - ), + ) }; Ok(ReleaseEntity { @@ -1882,10 +1883,10 @@ impl EntityCrud for ReleaseEntity { publisher: rev_row.publisher, language: rev_row.language, work_id: Some(FatCatId::from_uuid(&rev_row.work_ident_id).to_string()), - refs: refs, - contribs: contribs, - abstracts: abstracts, - state: state, + refs, + contribs, + abstracts, + state, ident: ident_id, revision: Some(rev_row.id.to_string()), redirect: redirect_id, @@ -1979,7 +1980,7 @@ impl EntityCrud for ReleaseEntity { .iter() .map(|r| { Ok(ReleaseRefNewRow { - release_rev: rev_id.clone(), + release_rev: *rev_id, target_release_ident_id: match r.target_release_id.clone() { None => None, Some(v) => Some(FatCatId::from_str(&v)?.to_uuid()), @@ -2005,7 +2006,7 @@ impl EntityCrud for ReleaseEntity { .iter() .map(|c| { Ok(ReleaseContribNewRow { - release_rev: rev_id.clone(), + release_rev: *rev_id, creator_ident_id: match c.creator_id.clone() { None => None, Some(v) => Some(FatCatId::from_str(&v)?.to_uuid()), @@ -2136,7 +2137,7 @@ impl EntityCrud for WorkEntity { }; Ok(WorkEntity { - state: state, + state, ident: ident_id, revision: Some(rev_row.id.to_string()), redirect: redirect_id, diff --git a/rust/src/identifiers.rs b/rust/src/identifiers.rs index adb9f413..386570b9 100644 --- a/rust/src/identifiers.rs +++ b/rust/src/identifiers.rs @@ -17,7 +17,7 @@ impl ToString for FatCatId { impl FromStr for FatCatId { type Err = Error; fn from_str(s: &str) -> Result<FatCatId> { - fcid2uuid(s).map(|u| FatCatId(u)) + fcid2uuid(s).map(FatCatId) } } diff --git a/rust/src/lib.rs b/rust/src/lib.rs index df3d6f51..90a1f250 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -20,6 +20,3 @@ pub mod entity_crud; pub mod errors; pub mod identifiers; pub mod server; - -// TODO: will probably remove these as a public export? -pub use crate::server::{create_server, create_test_server}; |