Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions charon/cmd/cmd_sign.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"""
from typing import List

from charon.config import get_config, RadasConfig
from charon.config import get_config
from charon.pkgs.radas_signature_handler import sign_in_radas
from charon.cmd.internal import (
_decide_mode, _safe_delete
)
Expand Down Expand Up @@ -126,23 +127,22 @@ def sign(
if not radas_conf or not radas_conf.validate():
logger.error("The configuration for radas is not valid!")
sys.exit(1)
sign_in_radas(repo_url, requester, sign_key, result_path, radas_conf)
# All ignore files in global config should also be ignored in signing.
ig_patterns = conf.get_ignore_patterns()
if ignore_patterns:
ig_patterns.extend(ignore_patterns)
args = {
"repo_url": repo_url,
"requester": requester,
"sign_key": sign_key,
"result_path": result_path,
"ignore_patterns": ig_patterns,
"radas_config": radas_conf
}
sign_in_radas(**args) # type: ignore
except Exception:
print(traceback.format_exc())
sys.exit(2) # distinguish between exception and bad config or bad state
sys.exit(2)
finally:
if not debug and tmp_dir:
_safe_delete(tmp_dir)


def sign_in_radas(repo_url: str,
requester: str,
sign_key: str,
result_path: str,
radas_config: RadasConfig):
'''This function will be responsible to do the overall controlling of the whole process,
like trigger the send and register the receiver, and control the wait and timeout there.
'''
logger.debug("params. repo_url: %s, requester: %s, sign_key: %s, result_path: %s,"
"radas_config: %s", repo_url, requester, sign_key, result_path, radas_config)
logger.info("Not implemented yet!")
12 changes: 7 additions & 5 deletions charon/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,12 @@ def __init__(self, data: Dict):
self.__ignore_signature_suffix: Dict = data.get("ignore_signature_suffix", None)
self.__signature_command: str = data.get("detach_signature_command", None)
self.__aws_cf_enable: bool = data.get("aws_cf_enable", False)
self.__radas_config__: Optional[RadasConfig] = None
radas_config: Dict = data.get("radas", None)
if radas_config:
self.__radas_config__ = RadasConfig(radas_config)
self.__radas_config = RadasConfig(radas_config)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ligangty If no Optional to initialize the __radas_config, I'm afraid it will report AttributeError: CharonConfig object has no attribute radas_config when the method get_radas_config is called without radas_config there, we have some places that call this method.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds reasonable. I'll correct it. Thanks

self.__radas_enabled = bool(self.__radas_config and self.__radas_config.validate())
else:
self.__radas_enabled = False

def get_ignore_patterns(self) -> List[str]:
return self.__ignore_patterns
Expand Down Expand Up @@ -159,10 +161,10 @@ def is_aws_cf_enable(self) -> bool:
return self.__aws_cf_enable

def is_radas_enabled(self) -> bool:
return bool(self.__radas_config__ and self.__radas_config__.validate())
return self.__radas_enabled

def get_radas_config(self) -> Optional[RadasConfig]:
return self.__radas_config__
def get_radas_config(self) -> RadasConfig:
return self.__radas_config


def get_config(cfgPath=None) -> CharonConfig:
Expand Down
16 changes: 13 additions & 3 deletions charon/pkgs/radas_signature_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@
import asyncio
import sys
from typing import List, Any, Tuple, Callable, Dict
from charon.config import get_config
from charon.config import get_config, RadasConfig
from charon.pkgs.oras_client import OrasClient
from proton import Event
from proton.handlers import MessagingHandler

logger = logging.getLogger(__name__)


class UmbListener(MessagingHandler):
class RadasReceiver(MessagingHandler):
"""
UmbListener class (AMQP version), register this when setup UmbClient
This receiver will listen to UMB message queue to receive signing message for
signing result.
Attributes:
sign_result_loc (str): Local save path (e.g. “/tmp/sign”) for oras pull result,
this value transfers from the cmd flag, should register UmbListener when the client starts
Expand Down Expand Up @@ -179,3 +180,12 @@ def __do_path_cut_and(
loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.gather(*tasks))
return (failed_paths, generated_signs)


def sign_in_radas(repo_url: str,
requester: str,
sign_key: str,
result_path: str,
ignore_patterns: List[str],
radas_config: RadasConfig):
logger.info("Start signing for %s", repo_url)