forked from almalinux/cas_wrapper
Added ability to authenticate artifact by hash
This commit is contained in:
parent
0a94dc6f8f
commit
036d5c589a
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user