From 7093f13a10f1489b1f1a8e817a9cd52a5bfab3d6 Mon Sep 17 00:00:00 2001 From: Vasily Kleschov Date: Wed, 14 Sep 2022 18:58:37 +0300 Subject: [PATCH 1/2] Added notarize_no_exc method to return success state instead of raising the exception --- cas_wrapper.py | 15 +++++++++++++++ setup.py | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/cas_wrapper.py b/cas_wrapper.py index 945e7bc..e2f7baf 100644 --- a/cas_wrapper.py +++ b/cas_wrapper.py @@ -79,6 +79,21 @@ class CasWrapper: result_of_execution = command() return json.loads(result_of_execution)['hash'] + def notarize_no_exc( + self, + local_path: str, + metadata: typing.Dict = None, + ) -> typing.Tuple[bool, str]: + success = False + try: + cas_hash = self.notarize(local_path, metadata=metadata) + success = True + except Exception: + self._logger.exception('Cannot notarize artifact: %s', + local_path) + cas_hash = '' + return success, cas_hash + def authenticate( self, local_path: str, diff --git a/setup.py b/setup.py index 8cca4ab..08ed08a 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup setup( name="cas_wrapper", - version="0.0.4", + version="0.0.5", author="Stepan Oksanichenko", author_email="soksanichenko@almalinux.org", description="The python wrapper around binary cas from " From de5d91217f5029234182d8057f671c2605f561e0 Mon Sep 17 00:00:00 2001 From: Vasily Kleschov Date: Wed, 14 Sep 2022 19:28:45 +0300 Subject: [PATCH 2/2] Fixed review comments --- cas_wrapper.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cas_wrapper.py b/cas_wrapper.py index e2f7baf..8e7b26a 100644 --- a/cas_wrapper.py +++ b/cas_wrapper.py @@ -84,6 +84,15 @@ class CasWrapper: local_path: str, metadata: typing.Dict = None, ) -> typing.Tuple[bool, str]: + """ + Wrapper for avoiding raising exceptions during notarization. + Return `success` flag instead for library user to react respectively. + :param local_path: path to a local Git repo + :param metadata: additional metadata + :return: boolean flag for operation success and the hash + of the notarized artifact. + :rtype: tuple + """ success = False try: cas_hash = self.notarize(local_path, metadata=metadata)