From 46d2c82ccb73ed5c9a9c0a9ffeefd390de93e9d3 Mon Sep 17 00:00:00 2001 From: Lasse Yledahl Date: Thu, 5 Dec 2024 15:51:21 +0000 Subject: [PATCH 1/2] add MsgRelay to bankid, eidas and freja_eid --- src/eduid/webapp/bankid/app.py | 2 ++ src/eduid/webapp/bankid/settings/common.py | 2 ++ src/eduid/webapp/eidas/app.py | 2 ++ src/eduid/webapp/eidas/settings/common.py | 2 ++ src/eduid/webapp/freja_eid/app.py | 2 ++ src/eduid/webapp/freja_eid/settings/common.py | 2 ++ 6 files changed, 12 insertions(+) diff --git a/src/eduid/webapp/bankid/app.py b/src/eduid/webapp/bankid/app.py index bc252036e..dd6afea2c 100644 --- a/src/eduid/webapp/bankid/app.py +++ b/src/eduid/webapp/bankid/app.py @@ -5,6 +5,7 @@ from eduid.common.config.parsers import load_config from eduid.common.rpc.am_relay import AmRelay +from eduid.common.rpc.msg_relay import MsgRelay from eduid.userdb.logs.db import ProofingLog from eduid.userdb.proofing.db import BankIDProofingUserDB from eduid.webapp.bankid.settings.common import BankIDConfig @@ -28,6 +29,7 @@ def __init__(self, config: BankIDConfig, **kwargs: Any) -> None: # Init celery self.am_relay = AmRelay(config) + self.msg_relay = MsgRelay(config) current_bankid_app: BankIDApp = cast(BankIDApp, current_app) diff --git a/src/eduid/webapp/bankid/settings/common.py b/src/eduid/webapp/bankid/settings/common.py index a1d0ec067..0ad1ce9a5 100644 --- a/src/eduid/webapp/bankid/settings/common.py +++ b/src/eduid/webapp/bankid/settings/common.py @@ -10,6 +10,7 @@ ErrorsConfigMixin, FrontendActionMixin, MagicCookieMixin, + MsgConfigMixin, ProofingConfigMixin, Pysaml2SPConfigMixin, ) @@ -23,6 +24,7 @@ class BankIDConfig( ProofingConfigMixin, Pysaml2SPConfigMixin, FrontendActionMixin, + MsgConfigMixin, ): """ Configuration for the eidas app diff --git a/src/eduid/webapp/eidas/app.py b/src/eduid/webapp/eidas/app.py index e3accd73c..fdd0e4788 100644 --- a/src/eduid/webapp/eidas/app.py +++ b/src/eduid/webapp/eidas/app.py @@ -5,6 +5,7 @@ from eduid.common.config.parsers import load_config from eduid.common.rpc.am_relay import AmRelay +from eduid.common.rpc.msg_relay import MsgRelay from eduid.userdb.logs.db import ProofingLog from eduid.userdb.proofing.db import EidasProofingUserDB from eduid.webapp.common.authn.middleware import AuthnBaseApp @@ -28,6 +29,7 @@ def __init__(self, config: EidasConfig, **kwargs: Any) -> None: # Init celery self.am_relay = AmRelay(config) + self.msg_relay = MsgRelay(config) current_eidas_app: EidasApp = cast(EidasApp, current_app) diff --git a/src/eduid/webapp/eidas/settings/common.py b/src/eduid/webapp/eidas/settings/common.py index 3c6e20919..abcec0bdb 100644 --- a/src/eduid/webapp/eidas/settings/common.py +++ b/src/eduid/webapp/eidas/settings/common.py @@ -12,6 +12,7 @@ ErrorsConfigMixin, FrontendActionMixin, MagicCookieMixin, + MsgConfigMixin, ProofingConfigMixin, Pysaml2SPConfigMixin, ) @@ -25,6 +26,7 @@ class EidasConfig( ProofingConfigMixin, Pysaml2SPConfigMixin, FrontendActionMixin, + MsgConfigMixin, ): """ Configuration for the eidas app diff --git a/src/eduid/webapp/freja_eid/app.py b/src/eduid/webapp/freja_eid/app.py index d87970bb3..186544714 100644 --- a/src/eduid/webapp/freja_eid/app.py +++ b/src/eduid/webapp/freja_eid/app.py @@ -6,6 +6,7 @@ from eduid.common.config.parsers import load_config from eduid.common.rpc.am_relay import AmRelay +from eduid.common.rpc.msg_relay import MsgRelay from eduid.userdb.logs import ProofingLog from eduid.userdb.proofing.db import FrejaEIDProofingUserDB from eduid.webapp.common.authn.middleware import AuthnBaseApp @@ -25,6 +26,7 @@ def __init__(self, config: FrejaEIDConfig, **kwargs: Any) -> None: self.proofing_log = ProofingLog(config.mongo_uri) # Init celery self.am_relay = AmRelay(config) + self.msg_relay = MsgRelay(config) # Initialize the oidc_client self.oidc_client = OAuth(self, cache=SessionOAuthCache()) diff --git a/src/eduid/webapp/freja_eid/settings/common.py b/src/eduid/webapp/freja_eid/settings/common.py index bcbc9c2de..bd8bc3715 100644 --- a/src/eduid/webapp/freja_eid/settings/common.py +++ b/src/eduid/webapp/freja_eid/settings/common.py @@ -7,6 +7,7 @@ ErrorsConfigMixin, FrontendActionMixin, MagicCookieMixin, + MsgConfigMixin, ProofingConfigMixin, ) @@ -37,6 +38,7 @@ class FrejaEIDConfig( ErrorsConfigMixin, MagicCookieMixin, FrontendActionMixin, + MsgConfigMixin, ): """ Configuration for the svipe_id app From e646ed3fda91460893b394d0d169646a9ab1cdde Mon Sep 17 00:00:00 2001 From: Lasse Yledahl Date: Thu, 5 Dec 2024 15:52:30 +0000 Subject: [PATCH 2/2] add error handling, just in case --- src/eduid/webapp/common/api/utils.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/eduid/webapp/common/api/utils.py b/src/eduid/webapp/common/api/utils.py index 22e7b170a..9174e52d4 100644 --- a/src/eduid/webapp/common/api/utils.py +++ b/src/eduid/webapp/common/api/utils.py @@ -301,7 +301,14 @@ def get_reference_nin_from_navet_data(nin: str) -> str | None: """ Check if the NIN has changed in Navet data. """ - msg_relay = get_from_current_app("msg_relay", MsgRelay) + try: + msg_relay = get_from_current_app("msg_relay", MsgRelay) + except AttributeError: + # If for some reason the msg_relay is not in the current app, return None. + # This should not happen, but if it does, we don't want to crash the service. + # Instead, we log the error and return None. + logger.error("Could not get msg_relay from current app") + return None navet_data = msg_relay.get_all_navet_data(nin=nin) if navet_data.person.reference_national_identity_number: