ALBS-444 #2

Merged
anfimovdm merged 9 commits from ALBS-444 into master 2022-07-01 14:25:17 +00:00
Showing only changes of commit 07becc78df - Show all commits

View File

@ -113,19 +113,22 @@ class CasWrapper:
self, self,
local_path: str, local_path: str,
) -> typing.Tuple[bool, typing.Optional[str]]: ) -> typing.Tuple[bool, typing.Optional[str]]:
"""
Authenticates source by git path.
Returns authenticate result and source commit hash.
"""
is_authenticated = False is_authenticated = False
commit_cas_hash = None commit_cas_hash = None
self.ensure_login() self.ensure_login()
try: try:
result_json = self.authenticate(local_path, return_json=True) result_json = self.authenticate(local_path, return_json=True)
anfimovdm marked this conversation as resolved
Review

You don't get hash because use_hash equals to Fasle by default

You don't get hash because use_hash equals to Fasle by default
Review

I can get hash here, because when I use return_json flag, self.authenticate returns full JSON response

I can get hash here, because when I use `return_json` flag, `self.authenticate` returns full JSON response
# it should return 0 for authenticated and trusted commits # it should return 0 for authenticated and trusted commits
is_authenticated = not bool( is_authenticated = not bool(result_json['status'])
result_json.get('status', 1)) commit_cas_hash = result_json['hash']
commit_cas_hash = result_json.get('hash')
# we can fall with ProcessExecutionError, # we can fall with ProcessExecutionError,
# because source can be not notarized # because source can be not notarized
except ProcessExecutionError: except ProcessExecutionError:
self._logger.exception('Cannot authenticate %s:', local_path) self._logger.exception('Cannot authenticate: %s', local_path)
return is_authenticated, commit_cas_hash return is_authenticated, commit_cas_hash
def authenticate_artifact( def authenticate_artifact(
@ -134,6 +137,10 @@ class CasWrapper:
use_hash: bool = False, use_hash: bool = False,
return_json: bool = False, return_json: bool = False,
) -> bool: ) -> bool:
"""
Authenticates artifact by artifact path or hash if `use_hash` is True.
Returns authenticate result.
"""
is_authenticated = False is_authenticated = False
self.ensure_login() self.ensure_login()
try: try:
@ -145,7 +152,7 @@ class CasWrapper:
# we can fall with ProcessExecutionError, # we can fall with ProcessExecutionError,
# because source can be not notarized # because source can be not notarized
except ProcessExecutionError: except ProcessExecutionError:
self._logger.exception('Cannot authenticate %s:', local_path) self._logger.exception('Cannot authenticate: %s', local_path)
return is_authenticated return is_authenticated
def notarize_artifacts( def notarize_artifacts(
@ -153,6 +160,11 @@ class CasWrapper:
artifact_paths: typing.List[str], artifact_paths: typing.List[str],
metadata: typing.Dict[str, typing.Any], metadata: typing.Dict[str, typing.Any],
) -> typing.Tuple[bool, typing.Dict[str, str]]: ) -> typing.Tuple[bool, typing.Dict[str, str]]:
"""
Notarize artifacts by their paths.
Returns `True` if all artifacts was succesful notarizated
and dict with CAS hashes.
"""
all_artifacts_is_notarized = True all_artifacts_is_notarized = True
notarized_artifacts = {} notarized_artifacts = {}
anfimovdm marked this conversation as resolved Outdated

Add name of an artifact to the logging message

Add name of an artifact to the logging message
self.ensure_login() self.ensure_login()
@ -166,7 +178,8 @@ class CasWrapper:
try: try:
cas_artifact_hash = future.result() cas_artifact_hash = future.result()
except Exception: except Exception:
self._logger.exception('Cannot notarize artifact:') self._logger.exception('Cannot notarize artifact: %s',
artifact_path)
all_artifacts_is_notarized = False all_artifacts_is_notarized = False
continue continue
notarized_artifacts[artifact_path] = cas_artifact_hash notarized_artifacts[artifact_path] = cas_artifact_hash