diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..4b49322 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,98 @@ +# Based on https://github.com/actions-rs/meta/blob/master/recipes/quickstart.md +# +# While our "example" application has the platform-specific code, +# for simplicity we are compiling and testing everything on the Ubuntu environment only. +# For multi-OS testing see the `cross.yml` workflow. + +on: [push, pull_request] + +name: Continuous Integration + +jobs: + check: + name: Check + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v2 + + - name: Install stable toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + + - name: Run cargo check + uses: actions-rs/cargo@v1 + with: + command: check + + test: + name: Test Suite + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v2 + + - name: Install stable toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + + - name: Run cargo test + uses: actions-rs/cargo@v1 + with: + command: test + + lints: + name: Lints + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v2 + + - name: Install stable toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + components: rustfmt, clippy + + - name: Run cargo fmt + uses: actions-rs/cargo@v1 + with: + command: fmt + args: --all -- --check + + - name: Run cargo clippy + uses: actions-rs/cargo@v1 + with: + command: clippy + args: -- -D warnings + + build: + name: Build Application + runs-on: ubuntu-latest + needs: [check, test, lints] + strategy: + matrix: + target: + - x86_64-unknown-linux-gnu + - aarch64-unknown-linux-gnu + - powerpc64-unknown-linux-gnu + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + target: ${{ matrix.target }} + override: true + - uses: actions-rs/cargo@v1 + with: + use-cross: true + command: build + args: --release --target=${{ matrix.target }} diff --git a/src/actions/users.rs b/src/actions/users.rs index e6b39f9..744f1fa 100644 --- a/src/actions/users.rs +++ b/src/actions/users.rs @@ -3,7 +3,6 @@ use diesel::prelude::*; use crate::errors; use crate::models; use bcrypt::{hash, verify, DEFAULT_COST}; -use std::rc::Rc; pub fn find_user_by_uid( uid: i32, diff --git a/src/errors/domain_error.rs b/src/errors/domain_error.rs index e67351f..62e1f54 100644 --- a/src/errors/domain_error.rs +++ b/src/errors/domain_error.rs @@ -53,12 +53,12 @@ impl ResponseError for DomainError { reason: format!("{} {}", err.to_string(), source).as_str(), }) } - DomainError::PasswordError { cause: _ } => HttpResponse::BadRequest() - .json(ErrorModel { + DomainError::PasswordError { cause: _ } => { + HttpResponse::BadRequest().json(ErrorModel { error_code: 400, - reason: format!("{}", err.to_string()) - .as_str(), - }), + reason: format!("{}", err.to_string()).as_str(), + }) + } DomainError::GenericError { cause } => HttpResponse::BadRequest() .json(ErrorModel { error_code: 400, diff --git a/src/main.rs b/src/main.rs index 64354ff..5e04c1e 100755 --- a/src/main.rs +++ b/src/main.rs @@ -9,12 +9,9 @@ extern crate validator; use actix_web::{cookie::SameSite, middleware, web, App, HttpServer}; -use actix_web_httpauth::middleware::HttpAuthentication; - use actix_files as fs; use actix_identity::{CookieIdentityPolicy, IdentityService}; use rand::Rng; -use services::UserServiceImpl; use diesel::prelude::*; use diesel::r2d2::{self, ConnectionManager}; diff --git a/src/models/users.rs b/src/models/users.rs index 1140374..6a5991e 100644 --- a/src/models/users.rs +++ b/src/models/users.rs @@ -2,7 +2,6 @@ use serde::{Deserialize, Serialize}; use crate::schema::users; use crate::utils::regexs; -use validator::Validate; use validator_derive::*; #[derive(Debug, Clone, Queryable, Identifiable, Deserialize)] @@ -26,4 +25,3 @@ pub struct UserDTO { pub name: String, pub registration_date: chrono::NaiveDateTime, } - diff --git a/src/routes/users.rs b/src/routes/users.rs index ce1b4b8..3f05f63 100644 --- a/src/routes/users.rs +++ b/src/routes/users.rs @@ -21,7 +21,7 @@ pub async fn get_user( actions::find_user_by_uid(u_id, &conn) }) .await - .map_err(|err| { + .map_err(|_err| { let res = DomainError::new_generic_error(format!( "No user found with uid: {}", u_id diff --git a/src/services/user_service.rs b/src/services/user_service.rs index 9d11bde..add8b10 100644 --- a/src/services/user_service.rs +++ b/src/services/user_service.rs @@ -1,7 +1,3 @@ -use std::rc::Rc; - -use diesel::SqliteConnection; - use crate::{actions, errors, models, types::DbPool}; pub trait UserService { diff --git a/src/utils/auth.rs b/src/utils/auth.rs index 6adf0ee..e94eae3 100755 --- a/src/utils/auth.rs +++ b/src/utils/auth.rs @@ -1,10 +1,3 @@ -use actix_web_httpauth::extractors::basic::BasicAuth; - -use crate::routes::validate_basic_auth; -use crate::AppConfig; - -use actix_web::{dev::ServiceRequest, web, Error}; - // pub async fn validator( // req: ServiceRequest, // credentials: BasicAuth,