Skip to content

Commit

Permalink
Provide gRPC communication with gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
moubctez committed Oct 29, 2024
1 parent 068f979 commit b71d901
Show file tree
Hide file tree
Showing 57 changed files with 1,609 additions and 1,513 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 17 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion migrations/20241015074303_network_gateways.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ CREATE TABLE gateway (
id bigserial PRIMARY KEY,
network_id bigint NOT NULL,
url text NOT NULL,
connected boolean NOT NULL DEFAULT false,
hostname text NULL,
connected_at timestamp without time zone NULL,
disconnected_at timestamp without time zone NULL,
Expand Down
10 changes: 5 additions & 5 deletions src/auth/failed_login.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use std::{collections::HashMap, sync::Mutex};

use chrono::{DateTime, Duration, Local};
use chrono::{DateTime, Local, TimeDelta};
use thiserror::Error;
use utoipa::ToSchema;

// Time window in seconds
const FAILED_LOGIN_WINDOW: Duration = Duration::seconds(60);
const FAILED_LOGIN_WINDOW: TimeDelta = TimeDelta::seconds(60);
// Failed login count threshold
const FAILED_LOGIN_COUNT: u32 = 5;
// How long (in seconds) to lock users out after crossing the threshold
const FAILED_LOGIN_TIMEOUT: Duration = Duration::seconds(5 * 60);
const FAILED_LOGIN_TIMEOUT: TimeDelta = TimeDelta::seconds(5 * 60);

#[derive(Debug, Error, ToSchema)]
#[error("Too many login attempts")]
Expand All @@ -35,12 +35,12 @@ impl Default for FailedLogin {

impl FailedLogin {
// How much time has elapsed since first failed login attempt
fn time_since_first_attempt(&self) -> Duration {
fn time_since_first_attempt(&self) -> TimeDelta {
Local::now().signed_duration_since(self.first_attempt)
}

// How much time has elapsed since last failed login attempt
fn time_since_last_attempt(&self) -> Duration {
fn time_since_last_attempt(&self) -> TimeDelta {
Local::now().signed_duration_since(self.last_attempt)
}

Expand Down
9 changes: 6 additions & 3 deletions src/auth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ use crate::{
appstate::AppState,
db::{
models::{
group::Group, oauth2authorizedapp::OAuth2AuthorizedApp, oauth2token::OAuth2Token,
group::Group,
oauth2authorizedapp::OAuth2AuthorizedApp,
oauth2token::OAuth2Token,
session::{Session, SessionState},
user::User,
},
Id, Session, SessionState,
Id,
},
error::WebError,
handlers::SESSION_COOKIE_NAME,
Expand All @@ -50,7 +53,7 @@ pub enum ClaimsType {
/// Standard claims: https://www.iana.org/assignments/jwt/jwt.xhtml
#[derive(Deserialize, Serialize)]
pub struct Claims {
#[serde(skip_serializing, skip_deserializing)]
#[serde(skip)]
secret: String,
// issuer
pub iss: String,
Expand Down
Loading

0 comments on commit b71d901

Please sign in to comment.