Content-Length: 380440 | pFad | https://github.com/sebadob/rauthy/commit/4fc3382929e65780fb20a78994233357423f0aab

CF Merge pull request #173 from sebadob/impl-opt-panic-on-matrix-error · sebadob/rauthy@4fc3382 · GitHub
Skip to content

Commit

Permalink
Merge pull request #173 from sebadob/impl-opt-panic-on-matrix-error
Browse files Browse the repository at this point in the history
Impl opt panic on matrix error
  • Loading branch information
sebadob authored Nov 15, 2023
2 parents 3cdf81c + 6d9637e commit 4fc3382
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 9 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

11 changes: 11 additions & 0 deletions rauthy-book/src/config/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,17 @@ ENABLE_WEB_ID=true
# May be set to disable the TLS validation for the Matrix client.
# default: false
#EVENT_MATRIX_DANGER_DISABLE_TLS_VALIDATION=false
# The default behavior is, that Rauthy will panic at startup if it cannot connect
# to a configured Matrix server. The reason is that event notifications cannot be
# dropped silently.
# However, if you use a self-hosted Matrix server which uses Rauthy as its OIDC
# provider and both instances went offline, you will have a chicken and egg problem:
# - Rauthy cannot connect to Matrix and will panic
# - Your Matrix server cannot connect to Rauthy and will panic
# To solve this issue, you can temporarily set this value to 'true' and revert
# back, after the system is online again.
# default: false
#EVENT_MATRIX_ERROR_NO_PANIC=false
# The Webhook for Slack Notifications.
# If left empty, no messages will be sent to Slack.
Expand Down
32 changes: 25 additions & 7 deletions rauthy-models/src/events/notifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::email;
use crate::email::EMail;
use crate::events::event::{Event, EventLevel, EventType};
use async_trait::async_trait;
use rauthy_common::constants::EVENT_MATRIX_ERROR_NO_PANIC;
use rauthy_common::error_response::ErrorResponse;
use rauthy_notify::matrix::NotifierMatrix;
use rauthy_notify::slack::NotifierSlack;
Expand Down Expand Up @@ -130,20 +131,37 @@ impl EventNotifier {
.expect("Cannot parse EVENT_MATRIX_DANGER_DISABLE_TLS_VALIDATION to bool");
let root_ca_path = env::var("EVENT_MATRIX_ROOT_CA_PATH").ok();

let notifier = NotifierMatrix::try_new(
match NotifierMatrix::try_new(
&user_id,
&room_id,
access_token,
user_password,
disable_tls_validation,
root_ca_path.as_deref(),
)
.await?;
NOTIFIER_MATRIX
.set((level.value(), notifier))
.expect("init_notifiers should only be called once");

info!("Event Notifications will be sent to Matrix");
.await
{
Ok(notifier) => {
NOTIFIER_MATRIX
.set((level.value(), notifier))
.expect("init_notifiers should only be called once");

info!("Event Notifications will be sent to Matrix");
}
Err(err) => {
let no_panic = env::var("EVENT_MATRIX_ERROR_NO_PANIC")
.unwrap_or_else(|_| "false".to_string())
.parse::<bool>()
.expect("Cannot parse EVENT_MATRIX_ERROR_NO_PANIC to bool");

let msg = format!("Error creating the Matrix Notifier: {:?}", err.message);
if no_panic {
error!(msg);
} else {
panic!(msg);
}
}
};
}

Ok(())
Expand Down
5 changes: 4 additions & 1 deletion rauthy-models/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ pub struct AppVersionResponse {
#[cfg(test)]
mod tests {
use rstest::rstest;
use std::env;

use crate::{entity::webids::WebId, response::WebIdResponse};

Expand All @@ -602,9 +603,11 @@ mod tests {
<http://www.w3.org/ns/solid/terms#oidcIssuer>
<http://localhost:8080/auth/v1> .
"#),
"<http://localhost:8080/auth/webid/SomeId123/profile> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/PersonalProfileDocument> ;\n\t<http://xmlns.com/foaf/0.1/primaryTopic> <http://localhost:8080/auth/webid/SomeId123/profile#me> .\n<http://localhost:8080/auth/webid/SomeId123/profile#me> <http://www.w3.org/ns/solid/terms#oidcIssuer> <http://localhost:8080/auth/v1> ;\n\t<http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> ;\n\t<http://xmlns.com/foaf/0.1/givenname> \"Given\" ;\n\t<http://xmlns.com/foaf/0.1/family_name> \"Family\" ;\n\t<http://xmlns.com/foaf/0.1/mbox> <mailto:mail@example.com> .\n<http://localhost:8080/auth/webid/za9UxpH7XVxqrtpEbThoqvn2/profile#me> <http://www.w3.org/ns/solid/terms#oidcIssuer> <http://localhost:8080/auth/v1> .\n"
"<http://localhost:8081/auth/SomeId123/profile> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/PersonalProfileDocument> ;\n\t<http://xmlns.com/foaf/0.1/primaryTopic> <http://localhost:8081/auth/SomeId123/profile#me> .\n<http://localhost:8081/auth/SomeId123/profile#me> <http://www.w3.org/ns/solid/terms#oidcIssuer> <http://localhost:8080/auth/v1> ;\n\t<http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> ;\n\t<http://xmlns.com/foaf/0.1/givenname> \"Given\" ;\n\t<http://xmlns.com/foaf/0.1/family_name> \"Family\" ;\n\t<http://xmlns.com/foaf/0.1/mbox> <mailto:mail@example.com> .\n<http://localhost:8080/auth/webid/za9UxpH7XVxqrtpEbThoqvn2/profile#me> <http://www.w3.org/ns/solid/terms#oidcIssuer> <http://localhost:8080/auth/v1> .\n"
)]
fn test_web_id_response(#[case] custom_triples: Option<&str>, #[case] expected_resp: &str) {
env::set_var("PUB_URL", "localhost:8081".to_string());

let resp = WebIdResponse {
webid: WebId::try_new("SomeId123".to_string(), custom_triples, true)
.expect("Invalid cusyom triples in test case"),
Expand Down
13 changes: 12 additions & 1 deletion rauthy.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# if 'true', the data store will be initialized with DEV values (default: false)
# !!! DO NOT USE IN PRODUCTION !!!
DEV_MODE=false
DEV_MODE=true

# Can be set to 'true' during local development to allow an HTTP scheme for the DPoP 'htu' claim
# Will only be applied if `DEV_MODE == true` as well.
Expand Down Expand Up @@ -278,6 +278,17 @@ EPHEMERAL_CLIENTS_CACHE_LIFETIME=3600
# May be set to disable the TLS validation for the Matrix client.
# default: false
#EVENT_MATRIX_DANGER_DISABLE_TLS_VALIDATION=false
# The default behavior is, that Rauthy will panic at startup if it cannot connect
# to a configured Matrix server. The reason is that event notifications cannot be
# dropped silently.
# However, if you use a self-hosted Matrix server which uses Rauthy as its OIDC
# provider and both instances went offline, you will have a chicken and egg problem:
# - Rauthy cannot connect to Matrix and will panic
# - Your Matrix server cannot connect to Rauthy and will panic
# To solve this issue, you can temporarily set this value to 'true' and revert
# back, after the system is online again.
# default: false
EVENT_MATRIX_ERROR_NO_PANIC=true

# The Webhook for Slack Notifications.
# If left empty, no messages will be sent to Slack.
Expand Down

0 comments on commit 4fc3382

Please sign in to comment.








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/sebadob/rauthy/commit/4fc3382929e65780fb20a78994233357423f0aab

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy