From 1717e925bcd368e9a1c2dcc53e2c3016ae3382bb Mon Sep 17 00:00:00 2001 From: Glenn Matthews Date: Tue, 4 Jun 2024 17:21:05 -0400 Subject: [PATCH] Fix #305, bump version to 2.2.2 (#306) --- docs/admin/release_notes/version_2.2.md | 6 +++++- .../handle_notifications/sources.py | 17 +++++++++++++---- pyproject.toml | 2 +- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/docs/admin/release_notes/version_2.2.md b/docs/admin/release_notes/version_2.2.md index 9fd0a7b5..3aa625c2 100644 --- a/docs/admin/release_notes/version_2.2.md +++ b/docs/admin/release_notes/version_2.2.md @@ -1,6 +1,11 @@ # v2.2 Release Notes +## [v2.2.2 (2024-06-04)](https://github.com/nautobot/nautobot-app-circuit-maintenance/releases/tag/v2.2.2) + +### Fixed + +- [#305](https://github.com/nautobot/nautobot-app-circuit-maintenance/issues/305) - Fixed an error at startup if `exchangelib` is not installed. ## [v2.2.1 (2024-06-04)](https://github.com/nautobot/nautobot-app-circuit-maintenance/releases/tag/v2.2.1) @@ -8,7 +13,6 @@ - [#303](https://github.com/nautobot/nautobot-app-circuit-maintenance/issues/303) - Added backwards-compatibility with Pydantic 1.x. - ## [v2.2.0 (2024-06-04)](https://github.com/nautobot/nautobot-app-circuit-maintenance/releases/tag/v2.2.0) ### Added diff --git a/nautobot_circuit_maintenance/handle_notifications/sources.py b/nautobot_circuit_maintenance/handle_notifications/sources.py index 121266a4..f434a978 100644 --- a/nautobot_circuit_maintenance/handle_notifications/sources.py +++ b/nautobot_circuit_maintenance/handle_notifications/sources.py @@ -18,7 +18,12 @@ from typing import Union from urllib.parse import urlparse -import exchangelib +try: + import exchangelib + + EXCHANGELIB_PRESENT = True +except ImportError: + EXCHANGELIB_PRESENT = False from django.conf import settings from google.auth.exceptions import RefreshError from google.auth.transport.requests import Request @@ -109,7 +114,7 @@ def test_authentication(self) -> Tuple[bool, str]: return is_authenticated, message @classmethod - def init(cls: Type[T], name: str) -> T: + def init(cls: Type[T], name: str) -> T: # pylint: disable=too-many-branches """Factory Pattern to get the specific Source Class depending on the scheme.""" for notification_source in settings.PLUGINS_CONFIG.get("nautobot_circuit_maintenance", {}).get( "notification_sources", [] @@ -137,6 +142,8 @@ def init(cls: Type[T], name: str) -> T: source_header=config.get("source_header", "From"), ) if scheme == "ews": + if not EXCHANGELIB_PRESENT: + raise ValueError("You must install 'exchangelib' to use the 'ews' scheme.") return ExchangeWebService( name=name, url=url, @@ -434,7 +441,7 @@ class ExchangeWebService(EmailSource): password: str server: str folder: Optional[str] = None - session: Optional[exchangelib.Account] = None + session: Optional["exchangelib.Account"] = None class Config: """Pydantic BaseModel config.""" @@ -443,6 +450,8 @@ class Config: def open_session(self): """Open session to EWS server.""" + if not EXCHANGELIB_PRESENT: + raise RuntimeError("You must install 'exchangelib' to use this source") if not self.session: credentials = exchangelib.Credentials( username=self.authentication_user, @@ -500,7 +509,7 @@ def receive_notifications( def get_notification_from_item( self, job: Job, - item: exchangelib.items.message.Message, + item: "exchangelib.items.message.Message", ) -> Optional[MaintenanceNotification]: """Return a MaintenanceNotification derived from a give email item.""" msg_id = item.id diff --git a/pyproject.toml b/pyproject.toml index 3d83866e..14a5ce5e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "nautobot-circuit-maintenance" -version = "2.2.1" +version = "2.2.2" description = "Nautobot app to automatically handle Circuit Maintenances Notifications" authors = ["Network to Code, LLC "] license = "Apache-2.0"