From 02f30c9a9038277f8b7a2f87c6817e769c3a0146 Mon Sep 17 00:00:00 2001 From: jkriwet Date: Tue, 11 Jul 2023 09:59:46 +0200 Subject: [PATCH] Added version checker for correct cb version #190 --- filip/clients/ngsi_v2/cb.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/filip/clients/ngsi_v2/cb.py b/filip/clients/ngsi_v2/cb.py index 3d7fe1bf..44b09890 100644 --- a/filip/clients/ngsi_v2/cb.py +++ b/filip/clients/ngsi_v2/cb.py @@ -12,6 +12,7 @@ PositiveFloat, \ AnyHttpUrl from typing import Any, Dict, List , Optional, TYPE_CHECKING, Union +from packaging import version import re import requests from urllib.parse import urljoin @@ -74,6 +75,8 @@ def __init__(self, fiware_header=fiware_header, **kwargs) + self._check_correct_cb_version() + def __pagination(self, *, method: PaginationMethod = PaginationMethod.GET, @@ -157,6 +160,22 @@ def get_version(self) -> Dict: self.logger.error(err) raise + def _check_correct_cb_version(self) -> None: + """ + Checks whether Orion version is >= 3.6.0, since breaking change was introduced there which introduced new + option, which is implemented in FiLiP, but won't work with lower orion versions. + """ + orion_version = self.get_version()['orion']['version'] + if version.parse(orion_version) < version.parse('3.6.0'): + warnings.warn( + f"You are using orion version {orion_version}. There was a breaking change in Orion Version 3.6.0," + f"which changed the default metadata update semantics and introduced the 'overrideMetadata' option. " + f"See https://github.com/telefonicaid/fiware-orion/releases/tag/3.6.0 for further details. " + f"In your used version {orion_version}, this option is not supported. This will only be a problem, if" + f" you try to set the 'overrideMetadata' option in FiLiP (implemented since v0.2.3)." + ) + + def get_resources(self) -> Dict: """ Gets reo