Browse Source

Add ci file

devel
Rohan Sircar 3 years ago
parent
commit
0fd1137361
  1. 98
      .github/workflows/ci.yml
  2. 1
      src/actions/users.rs
  3. 10
      src/errors/domain_error.rs
  4. 3
      src/main.rs
  5. 2
      src/models/users.rs
  6. 2
      src/routes/users.rs
  7. 4
      src/services/user_service.rs
  8. 7
      src/utils/auth.rs

98
.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 }}

1
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,

10
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,

3
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};

2
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,
}

2
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

4
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 {

7
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,

Loading…
Cancel
Save