Compare commits

..

No commits in common. "master" and "0.0.3" have entirely different histories.

2 changed files with 6 additions and 51 deletions

View File

@ -13,20 +13,16 @@ class CasWrapper:
binary_name = 'cas' binary_name = 'cas'
@classmethod
def _is_binary_present(cls):
if cls.binary_name not in local:
raise FileNotFoundError(
'Binary CAS is not found in PATH on the machine',
)
def __init__( def __init__(
self, self,
cas_api_key: str, cas_api_key: str,
cas_signer_id: str, cas_signer_id: str,
logger: logging.Logger = None, logger: logging.Logger = None,
): ):
self._is_binary_present() if self.binary_name not in local:
raise FileNotFoundError(
'Binary CAS is not found in PATH on the machine',
)
self._cas_api_key = cas_api_key self._cas_api_key = cas_api_key
self._cas_signer_id = cas_signer_id self._cas_signer_id = cas_signer_id
self._cas = local['cas'] self._cas = local['cas']
@ -34,13 +30,6 @@ class CasWrapper:
if self._logger is None: if self._logger is None:
self._logger = logging.getLogger() self._logger = logging.getLogger()
@classmethod
def get_version(cls):
cls._is_binary_present()
command = local['cas']['--version']
version = command().split()[-1].split('v')[1]
return version
def ensure_login(self): def ensure_login(self):
with local.env( with local.env(
CAS_API_KEY=self._cas_api_key, CAS_API_KEY=self._cas_api_key,
@ -79,36 +68,11 @@ class CasWrapper:
result_of_execution = command() result_of_execution = command()
return json.loads(result_of_execution)['hash'] return json.loads(result_of_execution)['hash']
def notarize_no_exc(
self,
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)
success = True
except Exception:
self._logger.exception('Cannot notarize artifact: %s',
local_path)
cas_hash = ''
return success, cas_hash
def authenticate( def authenticate(
self, self,
local_path: str, local_path: str,
return_json: bool = False, return_json: bool = False,
use_hash: bool = False, use_hash: bool = False,
signer_id: str = None,
): ):
""" """
Wrapper around `cas authenticate` Wrapper around `cas authenticate`
@ -124,8 +88,6 @@ class CasWrapper:
command_args = ['authenticate', local_path] command_args = ['authenticate', local_path]
if use_hash: if use_hash:
command_args = ['authenticate', '--hash', local_path] command_args = ['authenticate', '--hash', local_path]
if signer_id:
command_args.extend(('--signerID', signer_id))
command_args.extend(('-o', 'json')) command_args.extend(('-o', 'json'))
command = self._cas[command_args] command = self._cas[command_args]
try: try:
@ -149,7 +111,6 @@ class CasWrapper:
def authenticate_source( def authenticate_source(
self, self,
local_path: str, local_path: str,
signer_id: str = None,
) -> typing.Tuple[bool, typing.Optional[str]]: ) -> typing.Tuple[bool, typing.Optional[str]]:
""" """
Authenticates source by git path. Authenticates source by git path.
@ -159,11 +120,7 @@ class CasWrapper:
commit_cas_hash = None commit_cas_hash = None
self.ensure_login() self.ensure_login()
try: try:
result_json = self.authenticate( result_json = self.authenticate(local_path, return_json=True)
local_path,
return_json=True,
signer_id=signer_id
)
is_authenticated = result_json['verified'] is_authenticated = result_json['verified']
commit_cas_hash = result_json['hash'] commit_cas_hash = result_json['hash']
# we can fall with ProcessExecutionError, # we can fall with ProcessExecutionError,
@ -176,7 +133,6 @@ class CasWrapper:
self, self,
local_path: str, local_path: str,
use_hash: bool = False, use_hash: bool = False,
signer_id: str = None,
) -> bool: ) -> bool:
""" """
Authenticates artifact by artifact path or hash if `use_hash` is True. Authenticates artifact by artifact path or hash if `use_hash` is True.
@ -189,7 +145,6 @@ class CasWrapper:
local_path, local_path,
use_hash=use_hash, use_hash=use_hash,
return_json=True, return_json=True,
signer_id=signer_id
)['verified'] )['verified']
# we can fall with ProcessExecutionError, # we can fall with ProcessExecutionError,
# because artifact can be not notarized # because artifact can be not notarized

View File

@ -2,7 +2,7 @@ from setuptools import setup
setup( setup(
name="cas_wrapper", name="cas_wrapper",
version="0.0.6", version="0.0.3",
author="Stepan Oksanichenko", author="Stepan Oksanichenko",
author_email="soksanichenko@almalinux.org", author_email="soksanichenko@almalinux.org",
description="The python wrapper around binary cas from " description="The python wrapper around binary cas from "