From 036d5c589ad9730aa732f6a68146d9ead76a0244 Mon Sep 17 00:00:00 2001 From: Daniil Anfimov Date: Wed, 29 Jun 2022 12:16:47 +0200 Subject: [PATCH] Added ability to authenticate artifact by hash --- cas_wrapper.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/cas_wrapper.py b/cas_wrapper.py index 7968685..0284389 100644 --- a/cas_wrapper.py +++ b/cas_wrapper.py @@ -83,22 +83,24 @@ class CasWrapper: self, local_path: str, return_json: bool = False, + use_hash: bool = False, ): """ Wrapper around `cas authenticate` :param local_path: path to a local Git repo (should be started from `git://`) - or to a single local file + or to a single local file or hash + :param return_json: flag for return json response + :param use_hash: flag for authenticate by hash :return: true if a commit is trusted, vice versa - false or dict with result if return_json param is True :rtype: bool or dict """ - command = self._cas[ - 'authenticate', - local_path, - '-o', - 'json', - ] + command_args = ['authenticate', local_path] + if use_hash: + command_args = ['authenticate', '--hash', local_path] + command_args.extend(('-o', 'json')) + command = self._cas[command_args] try: with local.env( CAS_API_KEY=self._cas_api_key, @@ -139,11 +141,13 @@ class CasWrapper: def authenticate_artifact( self, local_path: str, + use_hash: bool = False, ) -> bool: is_authenticated = False with self as cas: try: - is_authenticated = cas.authenticate(local_path) + is_authenticated = cas.authenticate(local_path, + use_hash=use_hash) # we can fall with ProcessExecutionError, # because source can be not notarized except ProcessExecutionError: