Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,4 @@ jobs:
provenance-name: provenance-id-${{ matrix.os }}.intoto.jsonl
base64-subjects: "${{ needs.build.outputs[format('hash-{0}', matrix.os)] }}"
upload-assets: true # Optional: Upload to a new release
draft-release: true # Optional: Upload to a draft release
6 changes: 3 additions & 3 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bourso-cli"
version = "0.5.2"
version = "0.5.3"
edition = "2021"
repository = "https://github.com/azerpas/bourso-api"

Expand All @@ -18,6 +18,7 @@ serde_json = { version = "1.0.107" }
tracing = { version = "0.1.41" }
tracing-subscriber = { version = "0.3.20", features = ["fmt", "env-filter", "json"] }
futures-util = { version = "0.3.31" }
qrcode = { version = "0.14.1" }

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(tarpaulin_include)'] }
3 changes: 1 addition & 2 deletions src/bourso_api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bourso_api"
version = "0.5.2"
version = "0.5.3"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -19,7 +19,6 @@ chrono = { version = "0.4.39" }
tracing = { version = "0.1.41" }
futures-util = { version = "0.3.31" }
async-stream = { version = "0.3.6" }
qrcode = { version = "0.14.1" }
rand = { version = "0.9.2" }

[lints.rust]
Expand Down
2 changes: 2 additions & 0 deletions src/bourso_api/src/client/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::fmt;
pub enum ClientError {
InvalidCredentials,
MfaRequired,
QRCodeRequired(String),
InvalidMfa,
}

Expand All @@ -12,6 +13,7 @@ impl fmt::Display for ClientError {
match self {
ClientError::InvalidCredentials => write!(f, "Invalid credentials"),
ClientError::MfaRequired => write!(f, "MFA required"),
ClientError::QRCodeRequired(msg) => write!(f, "{}", msg),
ClientError::InvalidMfa => write!(f, "Invalid MFA"),
}
}
Expand Down
15 changes: 3 additions & 12 deletions src/bourso_api/src/client/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
pub mod account;
pub mod config;
pub mod error;
pub mod qrcode;
pub mod trade;
pub mod transfer;
pub mod virtual_pad;
Expand Down Expand Up @@ -516,17 +515,9 @@ impl BoursoWebClient {
debug!("⏳ MFA not yet validated");

if json_body["qrcode"].is_string() {
match qrcode::generate_qr_code(json_body["qrcode"].as_str().unwrap()) {
Ok(qr) => {
println!();
println!("{}", qrcode::render_to_terminal(&qr));
println!();
}
Err(e) => bail!("Could not render the QR code {}", e),
}
info!(
"Please scan the latest QR code in your BoursoBank app to validate the login request."
);
bail!(ClientError::QRCodeRequired(
json_body["qrcode"].as_str().unwrap().to_string()
));
}

Ok(false)
Expand Down
59 changes: 44 additions & 15 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use clap::ArgMatches;
use futures_util::{pin_mut, StreamExt};
use tracing::{debug, info, warn};

pub mod qrcode;
pub mod settings;
pub mod validate;

Expand Down Expand Up @@ -174,28 +175,56 @@ pub async fn parse_matches(matches: ArgMatches) -> Result<()> {
"Checking MFA status... (waited {}s/{})",
wait_time, max_wait_time
);
let mfa_validated = web_client
match web_client
.check_mfa(
mfa_type.clone(),
otp_id.clone(),
form_state.clone(),
token.clone(),
)
.await?;

if mfa_validated {
break;
}

if wait_time >= max_wait_time {
return Err(anyhow::anyhow!(
"MFA validation timed out after {} seconds",
max_wait_time
));
.await
{
Ok(mfa_validated) => {
if mfa_validated {
break;
}

if wait_time >= max_wait_time {
return Err(anyhow::anyhow!(
"MFA validation timed out after {} seconds",
max_wait_time
));
}

wait_time += wait_interval;
tokio::time::sleep(std::time::Duration::from_secs(wait_interval)).await;
}
Err(e) => match e.downcast_ref() {
Some(bourso_api::client::error::ClientError::QRCodeRequired(code)) => {
match qrcode::generate_qr_code(code) {
Ok(qr) => {
println!();
println!("{}", qrcode::render_to_terminal(&qr));
println!();
}
Err(e) => {
debug!("{:#?}", e);
return Err(e);
}
}
info!(
"Please scan the latest QR code in your BoursoBank app to validate the login request."
);
wait_time += wait_interval;
tokio::time::sleep(std::time::Duration::from_secs(wait_interval))
.await;
}
_ => {
debug!("{:#?}", e);
return Err(e);
}
},
}

wait_time += wait_interval;
tokio::time::sleep(std::time::Duration::from_secs(wait_interval)).await;
}

info!("MFA successful ✅");
Expand Down
File renamed without changes.