|
19 | 19 | import os |
20 | 20 | import asyncio |
21 | 21 | import sys |
| 22 | +import uuid |
22 | 23 | from typing import List, Any, Tuple, Callable, Dict |
23 | | -from charon.config import get_config |
| 24 | +from charon.config import get_config, RadasConfig |
24 | 25 | from charon.pkgs.oras_client import OrasClient |
25 | | -from proton import Event |
| 26 | +from proton import SSLDomain, SSLException, Message, Event |
26 | 27 | from proton.handlers import MessagingHandler |
| 28 | +from proton.utils import BlockingConnection |
27 | 29 |
|
28 | 30 | logger = logging.getLogger(__name__) |
29 | 31 |
|
@@ -98,6 +100,59 @@ def _process_message(self, msg: Any) -> None: |
98 | 100 | logger.info("Number of files pulled: %d, path: %s", len(files), files[0]) |
99 | 101 |
|
100 | 102 |
|
| 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 | + |
101 | 156 | def generate_radas_sign(top_level: str, sign_result_loc: str) -> Tuple[List[str], List[str]]: |
102 | 157 | """ |
103 | 158 | Generate .asc files based on RADAS sign result json file |
|
0 commit comments