Skip to content

Commit 29804ca

Browse files
sign in radas function implementation init
1 parent bf01903 commit 29804ca

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

charon/cmd/cmd_sign.py

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

18+
<<<<<<< HEAD
1819
from charon.config import get_config
20+
=======
21+
from charon.config import get_config, RadasConfig
22+
>>>>>>> c4ad584 (sign in radas function implementation init)
1923
from charon.pkgs.radas_signature_handler import sign_in_radas
2024
from charon.cmd.internal import (
2125
_decide_mode, _safe_delete

charon/pkgs/radas_signature_handler.py

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@
1919
import os
2020
import asyncio
2121
import sys
22+
import uuid
2223
from typing import List, Any, Tuple, Callable, Dict
2324
from charon.config import get_config, RadasConfig
2425
from charon.pkgs.oras_client import OrasClient
25-
from proton import Event
26+
from proton import SSLDomain, SSLException, Message, Event
2627
from proton.handlers import MessagingHandler
28+
from proton.utils import BlockingConnection
2729

2830
logger = logging.getLogger(__name__)
2931

@@ -111,6 +113,59 @@ def _process_message(self, msg: Any) -> None:
111113
logger.info("Number of files pulled: %d, path: %s", len(files), files[0])
112114

113115

116+
def sign_in_radas(repo_url: str,
117+
requester: str,
118+
sign_key: str,
119+
result_path: str,
120+
ignore_patterns: List[str],
121+
radas_config: RadasConfig):
122+
"""
123+
This function will be responsible to do the overall controlling of the whole process,
124+
like trigger the send and register the receiver, and control the wait and timeout there.
125+
"""
126+
logger.debug("params. repo_url: %s, requester: %s, sign_key: %s, result_path: %s,"
127+
"radas_config: %s", repo_url, requester, sign_key, result_path, radas_config)
128+
request_id = str(uuid.uuid4())
129+
exclude = list(ignore_patterns) if ignore_patterns else []
130+
131+
payload = {
132+
"request_id": request_id,
133+
"requested_by": requester,
134+
"type": "mrrc",
135+
"file_reference": repo_url,
136+
"sig_keyname": sign_key,
137+
"exclude": exclude
138+
}
139+
140+
try:
141+
ssl_domain = SSLDomain(SSLDomain.MODE_CLIENT)
142+
ssl_domain.set_credentials(
143+
radas_config.client_ca(),
144+
radas_config.client_key(),
145+
radas_config.client_key_password()
146+
)
147+
ssl_domain.set_trusted_ca_db(radas_config.root_ca())
148+
ssl_domain.set_peer_authentication(SSLDomain.VERIFY_PEER)
149+
150+
conn = BlockingConnection(radas_config.umb_target(), ssl_domain=ssl_domain)
151+
try:
152+
sender = conn.create_sender(radas_config.request_queue())
153+
message = Message(body=json.dumps(payload))
154+
sender.send(message)
155+
logger.info("Successfully sent signing request ID: %s", request_id)
156+
finally:
157+
conn.close()
158+
159+
except SSLException as e:
160+
logger.error("SSL connection failed: %s", str(e))
161+
sys.exit(1)
162+
except Exception as e:
163+
logger.error("Failed to send signing request: %s", str(e))
164+
sys.exit(1)
165+
166+
# wait for AMQP message to be consumed then get response message from UMB
167+
168+
114169
def generate_radas_sign(top_level: str, sign_result_loc: str) -> Tuple[List[str], List[str]]:
115170
"""
116171
Generate .asc files based on RADAS sign result json file

0 commit comments

Comments
 (0)