Skip to content

Commit f90557c

Browse files
yma955ligangty
authored andcommitted
Some changes on sign cmd and config
1 parent cfdd37f commit f90557c

File tree

3 files changed

+36
-24
lines changed

3 files changed

+36
-24
lines changed

charon/cmd/cmd_sign.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"""
1616
from typing import List
1717

18-
from charon.config import get_config, RadasConfig
18+
from charon.config import get_config
19+
from charon.pkgs.radas_signature_handler import sign_in_radas
1920
from charon.cmd.internal import (
2021
_decide_mode, _safe_delete
2122
)
@@ -126,23 +127,22 @@ def sign(
126127
if not radas_conf or not radas_conf.validate():
127128
logger.error("The configuration for radas is not valid!")
128129
sys.exit(1)
129-
sign_in_radas(repo_url, requester, sign_key, result_path, radas_conf)
130+
# All ignore files in global config should also be ignored in signing.
131+
ig_patterns = conf.get_ignore_patterns()
132+
if ignore_patterns:
133+
ig_patterns.extend(ignore_patterns)
134+
args = {
135+
"repo_url": repo_url,
136+
"requester": requester,
137+
"sign_key": sign_key,
138+
"result_path": result_path,
139+
"ignore_patterns": ig_patterns,
140+
"radas_config": radas_conf
141+
}
142+
sign_in_radas(**args) # type: ignore
130143
except Exception:
131144
print(traceback.format_exc())
132-
sys.exit(2) # distinguish between exception and bad config or bad state
145+
sys.exit(2)
133146
finally:
134147
if not debug and tmp_dir:
135148
_safe_delete(tmp_dir)
136-
137-
138-
def sign_in_radas(repo_url: str,
139-
requester: str,
140-
sign_key: str,
141-
result_path: str,
142-
radas_config: RadasConfig):
143-
'''This function will be responsible to do the overall controlling of the whole process,
144-
like trigger the send and register the receiver, and control the wait and timeout there.
145-
'''
146-
logger.debug("params. repo_url: %s, requester: %s, sign_key: %s, result_path: %s,"
147-
"radas_config: %s", repo_url, requester, sign_key, result_path, radas_config)
148-
logger.info("Not implemented yet!")

charon/config.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,12 @@ def __init__(self, data: Dict):
126126
self.__ignore_signature_suffix: Dict = data.get("ignore_signature_suffix", None)
127127
self.__signature_command: str = data.get("detach_signature_command", None)
128128
self.__aws_cf_enable: bool = data.get("aws_cf_enable", False)
129-
self.__radas_config__: Optional[RadasConfig] = None
130129
radas_config: Dict = data.get("radas", None)
131130
if radas_config:
132-
self.__radas_config__ = RadasConfig(radas_config)
131+
self.__radas_config = RadasConfig(radas_config)
132+
self.__radas_enabled = bool(self.__radas_config and self.__radas_config.validate())
133+
else:
134+
self.__radas_enabled = False
133135

134136
def get_ignore_patterns(self) -> List[str]:
135137
return self.__ignore_patterns
@@ -159,10 +161,10 @@ def is_aws_cf_enable(self) -> bool:
159161
return self.__aws_cf_enable
160162

161163
def is_radas_enabled(self) -> bool:
162-
return bool(self.__radas_config__ and self.__radas_config__.validate())
164+
return self.__radas_enabled
163165

164-
def get_radas_config(self) -> Optional[RadasConfig]:
165-
return self.__radas_config__
166+
def get_radas_config(self) -> RadasConfig:
167+
return self.__radas_config
166168

167169

168170
def get_config(cfgPath=None) -> CharonConfig:

charon/pkgs/radas_signature_handler.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,18 @@
2020
import asyncio
2121
import sys
2222
from typing import List, Any, Tuple, Callable, Dict
23-
from charon.config import get_config
23+
from charon.config import get_config, RadasConfig
2424
from charon.pkgs.oras_client import OrasClient
2525
from proton import Event
2626
from proton.handlers import MessagingHandler
2727

2828
logger = logging.getLogger(__name__)
2929

3030

31-
class UmbListener(MessagingHandler):
31+
class RadasReceiver(MessagingHandler):
3232
"""
33-
UmbListener class (AMQP version), register this when setup UmbClient
33+
This receiver will listen to UMB message queue to receive signing message for
34+
signing result.
3435
Attributes:
3536
sign_result_loc (str): Local save path (e.g. “/tmp/sign”) for oras pull result,
3637
this value transfers from the cmd flag, should register UmbListener when the client starts
@@ -179,3 +180,12 @@ def __do_path_cut_and(
179180
loop = asyncio.get_event_loop()
180181
loop.run_until_complete(asyncio.gather(*tasks))
181182
return (failed_paths, generated_signs)
183+
184+
185+
def sign_in_radas(repo_url: str,
186+
requester: str,
187+
sign_key: str,
188+
result_path: str,
189+
ignore_patterns: List[str],
190+
radas_config: RadasConfig):
191+
logger.info("Start signing for %s", repo_url)

0 commit comments

Comments
 (0)