mirror of
https://github.com/OMGeeky/twba.uploader.git
synced 2025-12-30 16:13:30 +01:00
send login message to webhook
This commit is contained in:
17
Cargo.lock
generated
17
Cargo.lock
generated
@@ -2504,18 +2504,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.198"
|
||||
version = "1.0.200"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9846a40c979031340571da2545a4e5b7c4163bdae79b301d5f86d03979451fcc"
|
||||
checksum = "ddc6f9cc94d67c0e21aaf7eda3a010fd3af78ebf6e096aa6e2e13c79749cce4f"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.198"
|
||||
version = "1.0.200"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e88edab869b01783ba905e7d0153f9fc1a6505a96e4ad3018011eedb838566d9"
|
||||
checksum = "856f046b9400cee3c8c94ed572ecdb752444c24528c035cd35882aad6f492bcb"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -3356,8 +3356,8 @@ checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
|
||||
|
||||
[[package]]
|
||||
name = "twba-backup-config"
|
||||
version = "0.1.6"
|
||||
source = "git+https://github.com/OMGeeky/backup_config.git#60092672b4b45667ef21073b3c43c062715ce486"
|
||||
version = "0.1.7"
|
||||
source = "git+https://github.com/OMGeeky/backup_config.git#fc38fbc800071ca0bddf8d15714b8eb6df17d750"
|
||||
dependencies = [
|
||||
"confique",
|
||||
"serde",
|
||||
@@ -3367,9 +3367,10 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "twba-common"
|
||||
version = "0.2.0"
|
||||
source = "git+https://github.com/OMGeeky/twba.common.git#153196685ced86bf063b0a98cbb726f15b269dd3"
|
||||
version = "0.2.3"
|
||||
source = "git+https://github.com/OMGeeky/twba.common.git#3e502063cc36b06c0d2aa41bddd89f999f35d6e8"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"tracing",
|
||||
"tracing-appender",
|
||||
"tracing-subscriber",
|
||||
|
||||
@@ -21,7 +21,7 @@ tokio = { version = "1.33", features = ["rt", "rt-multi-thread", "macros"] }
|
||||
thiserror = "1.0"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
reqwest = { version = "0.11" }
|
||||
reqwest = { version = "0.11", features = ["json"] }
|
||||
chrono = "0.4"
|
||||
futures = "0.3"
|
||||
futures-util = "0.3"
|
||||
|
||||
@@ -8,6 +8,7 @@ use std::{
|
||||
};
|
||||
use tracing::instrument;
|
||||
use twba_backup_config::Conf;
|
||||
use twba_common::notify::NotificationRequest;
|
||||
use yup_oauth2::authenticator_delegate::InstalledFlowDelegate;
|
||||
|
||||
pub struct CustomFlowDelegate<USER: EasyString> {
|
||||
@@ -50,17 +51,7 @@ impl<USER: EasyString> InstalledFlowDelegate for CustomFlowDelegate<USER> {
|
||||
impl<USER: EasyString> CustomFlowDelegate<USER> {
|
||||
#[tracing::instrument(skip(self, url, need_code))]
|
||||
async fn present_user_url(&self, url: &str, need_code: bool) -> StdResult<String, String> {
|
||||
let user: String = self
|
||||
.user
|
||||
.clone()
|
||||
.map(|x| x.into())
|
||||
.unwrap_or_else(|| "unknown".into());
|
||||
let message = format!(
|
||||
"Please open this URL in your browser to authenticate for {}:\n{}\n",
|
||||
user, url
|
||||
);
|
||||
println!("{}", message);
|
||||
info!("{}", message);
|
||||
self.print_url(url).await?;
|
||||
if need_code {
|
||||
let mut code = String::new();
|
||||
if crate::CONF.google.use_file_auth_response {
|
||||
@@ -81,6 +72,29 @@ impl<USER: EasyString> CustomFlowDelegate<USER> {
|
||||
Ok("".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
async fn print_url(&self, url: &str) -> StdResult<(), String> {
|
||||
let user: String = self
|
||||
.user
|
||||
.clone()
|
||||
.map(|x| x.into())
|
||||
.unwrap_or_else(|| "unknown".into());
|
||||
let message = format!(
|
||||
"Please open this URL in your browser to authenticate for {}:\n{}\n",
|
||||
user, url
|
||||
);
|
||||
println!("{}", message);
|
||||
info!("{}", message);
|
||||
if let Some(webhook) = &crate::CONF.notifier.webhook_url {
|
||||
reqwest::Client::new()
|
||||
.post(webhook)
|
||||
.json(&NotificationRequest { message })
|
||||
.send()
|
||||
.await
|
||||
.map_err(|e| format!("Error sending request: {:?}", e))?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
#[instrument]
|
||||
async fn get_auth_code() -> Result<String> {
|
||||
|
||||
Reference in New Issue
Block a user