Skip to content

Commit

Permalink
fix warnings and clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
fzzzy committed Oct 21, 2020
1 parent cf524f1 commit 7310f13
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 36 deletions.
24 changes: 0 additions & 24 deletions src/web/extractors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ use actix_web::{
web::{Data, Json, Query},
Error, FromRequest, HttpMessage, HttpRequest,
};
use actix_web_httpauth::extractors::bearer::BearerAuth;
use actix_web_httpauth::headers::authorization;

use futures::future::{self, FutureExt, LocalBoxFuture, Ready, TryFutureExt};

Expand Down Expand Up @@ -1757,28 +1755,6 @@ where
Ok(None)
}

// Tokenserver extractor
#[derive(Debug, Default, Clone, Deserialize)]
pub struct TokenServerRequest {
auth: String,
// TODO extract required headers from the request into this struct.
}

impl FromRequest for TokenServerRequest {
type Config = ();
type Error = Error;
type Future = LocalBoxFuture<'static, Result<Self, Self::Error>>;

/// Extract and validate the precondition headers
fn from_request(req: &HttpRequest, _payload: &mut Payload) -> Self::Future {
Box::pin(async move {
Ok(Self {
auth: "asdf".to_string(),
})
})
}
}

#[cfg(test)]
mod tests {
use actix_http::h1;
Expand Down
19 changes: 7 additions & 12 deletions src/web/tokenserver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,17 @@ use actix_web::HttpResponse;
use actix_web_httpauth::extractors::bearer::BearerAuth;

use futures::future::{Future, TryFutureExt};
use futures::TryStreamExt;

use crate::error::{ApiError, ApiErrorKind};
use crate::web::extractors::TokenServerRequest;

use diesel::mysql::MysqlConnection;
use diesel::prelude::*;
use diesel::sql_types::*;
use diesel::{QueryDsl, RunQueryDsl};
use diesel::RunQueryDsl;
use std::env;

use jsonwebtoken::errors::ErrorKind;
use jsonwebtoken::{
decode, encode, Algorithm, DecodingKey, EncodingKey, Header, TokenData, Validation,
decode, Algorithm, DecodingKey, Validation,
};
use pyo3::prelude::*;
use pyo3::types::IntoPyDict;
Expand Down Expand Up @@ -73,18 +70,16 @@ pub struct Claims {
}

pub fn get(
request: TokenServerRequest,
auth: BearerAuth,
) -> impl Future<Output = Result<HttpResponse, BlockingError<ApiError>>> {
block(move || get_sync(request, &auth).map_err(Into::into)).map_ok(move |result| {
block(move || get_sync(&auth).map_err(Into::into)).map_ok(move |result| {
HttpResponse::Ok()
.content_type("application/json")
.body(serde_json::to_string(&result).unwrap())
})
}

pub fn get_sync(
_request: TokenServerRequest,
auth: &BearerAuth,
) -> Result<TokenServerResult, ApiError> {
// the public rsa components come from
Expand All @@ -106,7 +101,7 @@ pub fn get_sync(
env::var("TOKENSERVER_DATABASE_URL").expect("TOKENSERVER_DATABASE_URL must be set");

let connection = MysqlConnection::establish(&database_url)
.expect(&format!("Error connecting to {}", database_url));
.unwrap_or_else(|_| panic!("Error connecting to {}", database_url));
let user_record = diesel::sql_query(
"select users.uid, services.pattern, users.email, users.generation, users.client_state, users.created_at, users.replaced_at, nodes.node, users.keys_changed_at from users, services, nodes where users.email = ? and services.id = users.service and nodes.id = users.nodeid and nodes.service = services.id")
.bind::<Text, _>(email)
Expand Down Expand Up @@ -165,10 +160,10 @@ def get_derived_secret(plaintext, shared_secret):
println!("python result {:}", python_result);
let api_endpoint = format!("{:}/1.5/{:}/", user_record[0].node, token_data.claims.sub);
Ok(TokenServerResult {
id: python_result.to_string(),
key: python_derived_result.to_string(),
id: python_result,
key: python_derived_result,
uid: token_data.claims.sub,
api_endpoint: api_endpoint,
api_endpoint,
duration: "300".to_string(),
})
}

0 comments on commit 7310f13

Please sign in to comment.