Skip to content

Commit c4ad584

Browse files
sign in radas function implementation init
1 parent cfdd37f commit c4ad584

File tree

2 files changed

+59
-16
lines changed

2 files changed

+59
-16
lines changed

charon/cmd/cmd_sign.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from typing import List
1717

1818
from charon.config import get_config, RadasConfig
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,10 @@ 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+
sign_in_radas(repo_url, requester, sign_key, result_path, ignore_patterns, radas_conf)
130131
except Exception:
131132
print(traceback.format_exc())
132133
sys.exit(2) # distinguish between exception and bad config or bad state
133134
finally:
134135
if not debug and tmp_dir:
135136
_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/pkgs/radas_signature_handler.py

Lines changed: 57 additions & 2 deletions
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
23-
from charon.config import get_config
24+
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

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

100102

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

0 commit comments

Comments
 (0)