Skip to content

Commit

Permalink
Merge pull request #664 from DefGuard/dev
Browse files Browse the repository at this point in the history
merge dev -> main
  • Loading branch information
t-aleksander authored Jul 8, 2024
2 parents 39015c7 + f28c602 commit add6d2e
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 78 deletions.
110 changes: 55 additions & 55 deletions Cargo.lock

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

24 changes: 14 additions & 10 deletions src/db/models/user.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{string::ToString, time::SystemTime};
use std::{fmt, time::SystemTime};

use argon2::{
password_hash::{
Expand Down Expand Up @@ -39,15 +39,19 @@ pub enum MFAMethod {
Email,
}

impl ToString for MFAMethod {
fn to_string(&self) -> String {
match self {
MFAMethod::None => "None".into(),
MFAMethod::OneTimePassword => "TOTP".into(),
MFAMethod::Web3 => "Web3".into(),
MFAMethod::Webauthn => "WebAuthn".into(),
MFAMethod::Email => "Email".into(),
}
impl fmt::Display for MFAMethod {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"{}",
match self {
MFAMethod::None => "None",
MFAMethod::OneTimePassword => "TOTP",
MFAMethod::Web3 => "Web3",
MFAMethod::Webauthn => "WebAuthn",
MFAMethod::Email => "Email",
}
)
}
}

Expand Down
21 changes: 15 additions & 6 deletions src/grpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use tokio::{
},
time::sleep,
};
use tokio_stream::{wrappers::UnboundedReceiverStream, StreamExt};
use tokio_stream::wrappers::UnboundedReceiverStream;
use tonic::{
transport::{Certificate, ClientTlsConfig, Endpoint, Identity, Server, ServerTlsConfig},
Status,
Expand Down Expand Up @@ -381,10 +381,14 @@ pub async fn run_grpc_bidi_stream(
};
info!("Connected to proxy at {}", endpoint.uri());
let mut resp_stream = response.into_inner();
while let Some(received) = resp_stream.next().await {
info!("Received message from proxy");
match received {
Ok(received) => {
'message: loop {
match resp_stream.message().await {
Ok(None) => {
info!("stream was closed by the sender");
break 'message;
}
Ok(Some(received)) => {
info!("Received message from proxy");
let payload = match received.payload {
// rpc StartEnrollment (EnrollmentStartRequest) returns (EnrollmentStartResponse)
Some(core_request::Payload::EnrollmentStart(request)) => {
Expand Down Expand Up @@ -509,7 +513,12 @@ pub async fn run_grpc_bidi_stream(
};
tx.send(req).unwrap();
}
Err(err) => error!("stream error {err}"),
Err(err) => {
error!("stream error: {err}");
debug!("waiting 10s to re-establish the connection");
sleep(TEN_SECS).await;
break 'message;
}
}
}
}
Expand Down
Loading

0 comments on commit add6d2e

Please sign in to comment.