From 49af9cf4f5f8264384c7fa9063299f44e7536068 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sat, 27 Mar 2021 14:26:32 +0000 Subject: [PATCH] Correctly camelCase acronyms https://rust-lang.github.io/rust-clippy/master/index.html#upper_case_acronyms --- src/api/notifications.rs | 20 ++++++++++---------- src/auth.rs | 36 ++++++++++++++++++------------------ src/db/models/device.rs | 6 +++--- src/error.rs | 8 ++++---- src/main.rs | 2 +- src/util.rs | 16 ++++++++-------- 6 files changed, 44 insertions(+), 44 deletions(-) diff --git a/src/api/notifications.rs b/src/api/notifications.rs index 3c61b053..ff3c0054 100644 --- a/src/api/notifications.rs +++ b/src/api/notifications.rs @@ -120,7 +120,7 @@ fn convert_option>(option: Option) -> Value { } // Server WebSocket handler -pub struct WSHandler { +pub struct WsHandler { out: Sender, user_uuid: Option, users: WebSocketUsers, @@ -140,7 +140,7 @@ const PING: Token = Token(1); const ACCESS_TOKEN_KEY: &str = "access_token="; -impl WSHandler { +impl WsHandler { fn err(&self, msg: &'static str) -> ws::Result<()> { self.out.close(ws::CloseCode::Invalid)?; @@ -176,7 +176,7 @@ impl WSHandler { } } -impl Handler for WSHandler { +impl Handler for WsHandler { fn on_open(&mut self, hs: Handshake) -> ws::Result<()> { // Path == "/notifications/hub?id===&access_token=" // @@ -240,13 +240,13 @@ impl Handler for WSHandler { } } -struct WSFactory { +struct WsFactory { pub users: WebSocketUsers, } -impl WSFactory { +impl WsFactory { pub fn init() -> Self { - WSFactory { + WsFactory { users: WebSocketUsers { map: Arc::new(CHashMap::new()), }, @@ -254,11 +254,11 @@ impl WSFactory { } } -impl Factory for WSFactory { - type Handler = WSHandler; +impl Factory for WsFactory { + type Handler = WsHandler; fn connection_made(&mut self, out: Sender) -> Self::Handler { - WSHandler { + WsHandler { out, user_uuid: None, users: self.users.clone(), @@ -405,7 +405,7 @@ use rocket::State; pub type Notify<'a> = State<'a, WebSocketUsers>; pub fn start_notification_server() -> WebSocketUsers { - let factory = WSFactory::init(); + let factory = WsFactory::init(); let users = factory.users.clone(); if CONFIG.websocket_enabled() { diff --git a/src/auth.rs b/src/auth.rs index d1398bbf..59d1370d 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -58,28 +58,28 @@ fn decode_jwt(token: &str, issuer: String) -> Result Result { +pub fn decode_login(token: &str) -> Result { decode_jwt(token, JWT_LOGIN_ISSUER.to_string()) } -pub fn decode_invite(token: &str) -> Result { +pub fn decode_invite(token: &str) -> Result { decode_jwt(token, JWT_INVITE_ISSUER.to_string()) } -pub fn decode_delete(token: &str) -> Result { +pub fn decode_delete(token: &str) -> Result { decode_jwt(token, JWT_DELETE_ISSUER.to_string()) } -pub fn decode_verify_email(token: &str) -> Result { +pub fn decode_verify_email(token: &str) -> Result { decode_jwt(token, JWT_VERIFYEMAIL_ISSUER.to_string()) } -pub fn decode_admin(token: &str) -> Result { +pub fn decode_admin(token: &str) -> Result { decode_jwt(token, JWT_ADMIN_ISSUER.to_string()) } #[derive(Debug, Serialize, Deserialize)] -pub struct LoginJWTClaims { +pub struct LoginJwtClaims { // Not before pub nbf: i64, // Expiration time @@ -110,7 +110,7 @@ pub struct LoginJWTClaims { } #[derive(Debug, Serialize, Deserialize)] -pub struct InviteJWTClaims { +pub struct InviteJwtClaims { // Not before pub nbf: i64, // Expiration time @@ -132,9 +132,9 @@ pub fn generate_invite_claims( org_id: Option, user_org_id: Option, invited_by_email: Option, -) -> InviteJWTClaims { +) -> InviteJwtClaims { let time_now = Utc::now().naive_utc(); - InviteJWTClaims { + InviteJwtClaims { nbf: time_now.timestamp(), exp: (time_now + Duration::days(5)).timestamp(), iss: JWT_INVITE_ISSUER.to_string(), @@ -147,7 +147,7 @@ pub fn generate_invite_claims( } #[derive(Debug, Serialize, Deserialize)] -pub struct DeleteJWTClaims { +pub struct DeleteJwtClaims { // Not before pub nbf: i64, // Expiration time @@ -158,9 +158,9 @@ pub struct DeleteJWTClaims { pub sub: String, } -pub fn generate_delete_claims(uuid: String) -> DeleteJWTClaims { +pub fn generate_delete_claims(uuid: String) -> DeleteJwtClaims { let time_now = Utc::now().naive_utc(); - DeleteJWTClaims { + DeleteJwtClaims { nbf: time_now.timestamp(), exp: (time_now + Duration::days(5)).timestamp(), iss: JWT_DELETE_ISSUER.to_string(), @@ -169,7 +169,7 @@ pub fn generate_delete_claims(uuid: String) -> DeleteJWTClaims { } #[derive(Debug, Serialize, Deserialize)] -pub struct VerifyEmailJWTClaims { +pub struct VerifyEmailJwtClaims { // Not before pub nbf: i64, // Expiration time @@ -180,9 +180,9 @@ pub struct VerifyEmailJWTClaims { pub sub: String, } -pub fn generate_verify_email_claims(uuid: String) -> DeleteJWTClaims { +pub fn generate_verify_email_claims(uuid: String) -> DeleteJwtClaims { let time_now = Utc::now().naive_utc(); - DeleteJWTClaims { + DeleteJwtClaims { nbf: time_now.timestamp(), exp: (time_now + Duration::days(5)).timestamp(), iss: JWT_VERIFYEMAIL_ISSUER.to_string(), @@ -191,7 +191,7 @@ pub fn generate_verify_email_claims(uuid: String) -> DeleteJWTClaims { } #[derive(Debug, Serialize, Deserialize)] -pub struct AdminJWTClaims { +pub struct AdminJwtClaims { // Not before pub nbf: i64, // Expiration time @@ -202,9 +202,9 @@ pub struct AdminJWTClaims { pub sub: String, } -pub fn generate_admin_claims() -> AdminJWTClaims { +pub fn generate_admin_claims() -> AdminJwtClaims { let time_now = Utc::now().naive_utc(); - AdminJWTClaims { + AdminJwtClaims { nbf: time_now.timestamp(), exp: (time_now + Duration::minutes(20)).timestamp(), iss: JWT_ADMIN_ISSUER.to_string(), diff --git a/src/db/models/device.rs b/src/db/models/device.rs index b3413ada..77837fca 100644 --- a/src/db/models/device.rs +++ b/src/db/models/device.rs @@ -80,8 +80,8 @@ impl Device { let orgmanager: Vec<_> = orgs.iter().filter(|o| o.atype == 3).map(|o| o.org_uuid.clone()).collect(); // Create the JWT claims struct, to send to the client - use crate::auth::{encode_jwt, LoginJWTClaims, DEFAULT_VALIDITY, JWT_LOGIN_ISSUER}; - let claims = LoginJWTClaims { + use crate::auth::{encode_jwt, LoginJwtClaims, DEFAULT_VALIDITY, JWT_LOGIN_ISSUER}; + let claims = LoginJwtClaims { nbf: time_now.timestamp(), exp: (time_now + *DEFAULT_VALIDITY).timestamp(), iss: JWT_LOGIN_ISSUER.to_string(), @@ -117,7 +117,7 @@ impl Device { pub fn save(&mut self, conn: &DbConn) -> EmptyResult { self.updated_at = Utc::now().naive_utc(); - db_run! { conn: + db_run! { conn: sqlite, mysql { crate::util::retry( || diesel::replace_into(devices::table).values(DeviceDb::to_db(self)).execute(conn), diff --git a/src/error.rs b/src/error.rs index fa90f1d3..a42b1809 100644 --- a/src/error.rs +++ b/src/error.rs @@ -38,11 +38,11 @@ use diesel::ConnectionError as DieselConErr; use diesel_migrations::RunMigrationsError as DieselMigErr; use diesel::r2d2::PoolError as R2d2Err; use handlebars::RenderError as HbErr; -use jsonwebtoken::errors::Error as JWTErr; +use jsonwebtoken::errors::Error as JwtErr; use regex::Error as RegexErr; use reqwest::Error as ReqErr; use serde_json::{Error as SerdeErr, Value}; -use std::io::Error as IOErr; +use std::io::Error as IoErr; use std::time::SystemTimeError as TimeErr; use u2f::u2ferror::U2fError as U2fErr; @@ -72,10 +72,10 @@ make_error! { R2d2Error(R2d2Err): _has_source, _api_error, U2fError(U2fErr): _has_source, _api_error, SerdeError(SerdeErr): _has_source, _api_error, - JWTError(JWTErr): _has_source, _api_error, + JWtError(JwtErr): _has_source, _api_error, TemplError(HbErr): _has_source, _api_error, //WsError(ws::Error): _has_source, _api_error, - IOError(IOErr): _has_source, _api_error, + IoError(IoErr): _has_source, _api_error, TimeError(TimeErr): _has_source, _api_error, ReqError(ReqErr): _has_source, _api_error, RegexError(RegexErr): _has_source, _api_error, diff --git a/src/main.rs b/src/main.rs index dd397d17..50975c66 100644 --- a/src/main.rs +++ b/src/main.rs @@ -326,7 +326,7 @@ fn launch_rocket(extra_debug: bool) { .manage(pool) .manage(api::start_notification_server()) .attach(util::AppHeaders()) - .attach(util::CORS()) + .attach(util::Cors()) .attach(util::BetterLogging(extra_debug)) .launch(); diff --git a/src/util.rs b/src/util.rs index de663583..06984c78 100644 --- a/src/util.rs +++ b/src/util.rs @@ -38,9 +38,9 @@ impl Fairing for AppHeaders { } } -pub struct CORS(); +pub struct Cors(); -impl CORS { +impl Cors { fn get_header(headers: &HeaderMap, name: &str) -> String { match headers.get_one(name) { Some(h) => h.to_string(), @@ -51,7 +51,7 @@ impl CORS { // Check a request's `Origin` header against the list of allowed origins. // If a match exists, return it. Otherwise, return None. fn get_allowed_origin(headers: &HeaderMap) -> Option { - let origin = CORS::get_header(headers, "Origin"); + let origin = Cors::get_header(headers, "Origin"); let domain_origin = CONFIG.domain_origin(); let safari_extension_origin = "file://"; if origin == domain_origin || origin == safari_extension_origin { @@ -62,10 +62,10 @@ impl CORS { } } -impl Fairing for CORS { +impl Fairing for Cors { fn info(&self) -> Info { Info { - name: "CORS", + name: "Cors", kind: Kind::Response, } } @@ -73,14 +73,14 @@ impl Fairing for CORS { fn on_response(&self, request: &Request, response: &mut Response) { let req_headers = request.headers(); - if let Some(origin) = CORS::get_allowed_origin(req_headers) { + if let Some(origin) = Cors::get_allowed_origin(req_headers) { response.set_header(Header::new("Access-Control-Allow-Origin", origin)); } // Preflight request if request.method() == Method::Options { - let req_allow_headers = CORS::get_header(req_headers, "Access-Control-Request-Headers"); - let req_allow_method = CORS::get_header(req_headers, "Access-Control-Request-Method"); + let req_allow_headers = Cors::get_header(req_headers, "Access-Control-Request-Headers"); + let req_allow_method = Cors::get_header(req_headers, "Access-Control-Request-Method"); response.set_header(Header::new("Access-Control-Allow-Methods", req_allow_method)); response.set_header(Header::new("Access-Control-Allow-Headers", req_allow_headers));