1313See the License for the specific language governing permissions and
1414limitations under the License.
1515"""
16+
1617import logging
1718import os
1819from typing import Dict , List , Optional
@@ -34,13 +35,20 @@ def __init__(self, data: Dict):
3435 self .__client_key : str = data .get ("client_key" , None )
3536 self .__client_key_pass_file : str = data .get ("client_key_pass_file" , None )
3637 self .__root_ca : str = data .get ("root_ca" , "/etc/pki/tls/certs/ca-bundle.crt" )
38+ self .__quay_radas_registry_config : Optional [str ] = data .get (
39+ "quay_radas_registry_config" , None
40+ )
41+ self .__radas_sign_timeout_retry_count : int = data .get ("radas_sign_timeout_retry_count" , 10 )
42+ self .__radas_sign_timeout_retry_interval : int = data .get (
43+ "radas_sign_timeout_retry_interval" , 60
44+ )
3745
3846 def validate (self ) -> bool :
3947 if not self .__umb_host :
4048 logger .error ("Missing host name setting for UMB!" )
4149 return False
4250 if not self .__result_queue :
43- logger .error ("Missing the queue setting to receive siging result in UMB!" )
51+ logger .error ("Missing the queue setting to receive signing result in UMB!" )
4452 return False
4553 if not self .__request_queue :
4654 logger .error ("Missing the queue setting to send signing request in UMB!" )
@@ -57,10 +65,17 @@ def validate(self) -> bool:
5765 if self .__root_ca and not os .access (self .__root_ca , os .R_OK ):
5866 logger .error ("The root ca file is not valid!" )
5967 return False
68+ if self .__quay_radas_registry_config and not os .access (
69+ self .__quay_radas_registry_config , os .R_OK
70+ ):
71+ self .__quay_radas_registry_config = None
72+ logger .warning (
73+ "The quay registry config for oras is not valid, will ignore the registry config!"
74+ )
6075 return True
6176
6277 def umb_target (self ) -> str :
63- return f' amqps://{ self .__umb_host } :{ self .__umb_host_port } '
78+ return f" amqps://{ self .__umb_host } :{ self .__umb_host_port } "
6479
6580 def result_queue (self ) -> str :
6681 return self .__result_queue
@@ -77,7 +92,7 @@ def client_key(self) -> str:
7792 def client_key_password (self ) -> str :
7893 pass_file = self .__client_key_pass_file
7994 if os .access (pass_file , os .R_OK ):
80- with open (pass_file , 'r' ) as f :
95+ with open (pass_file , "r" ) as f :
8196 return f .read ()
8297 elif pass_file :
8398 logger .warning ("The key password file is not accessible. Will ignore the password." )
@@ -86,6 +101,15 @@ def client_key_password(self) -> str:
86101 def root_ca (self ) -> str :
87102 return self .__root_ca
88103
104+ def quay_radas_registry_config (self ) -> Optional [str ]:
105+ return self .__quay_radas_registry_config
106+
107+ def radas_sign_timeout_retry_count (self ) -> int :
108+ return self .__radas_sign_timeout_retry_count
109+
110+ def radas_sign_timeout_retry_interval (self ) -> int :
111+ return self .__radas_sign_timeout_retry_interval
112+
89113
90114class CharonConfig (object ):
91115 """CharonConfig is used to store all configurations for charon
@@ -102,9 +126,10 @@ def __init__(self, data: Dict):
102126 self .__ignore_signature_suffix : Dict = data .get ("ignore_signature_suffix" , None )
103127 self .__signature_command : str = data .get ("detach_signature_command" , None )
104128 self .__aws_cf_enable : bool = data .get ("aws_cf_enable" , False )
129+ self .__radas_config__ : Optional [RadasConfig ] = None
105130 radas_config : Dict = data .get ("radas" , None )
106131 if radas_config :
107- self .__radas_config__ : RadasConfig = RadasConfig (radas_config )
132+ self .__radas_config__ = RadasConfig (radas_config )
108133
109134 def get_ignore_patterns (self ) -> List [str ]:
110135 return self .__ignore_patterns
@@ -133,22 +158,23 @@ def get_detach_signature_command(self) -> str:
133158 def is_aws_cf_enable (self ) -> bool :
134159 return self .__aws_cf_enable
135160
136- def get_radas_config (self ) -> RadasConfig :
161+ def is_radas_enabled (self ) -> bool :
162+ return bool (self .__radas_config__ and self .__radas_config__ .validate ())
163+
164+ def get_radas_config (self ) -> Optional [RadasConfig ]:
137165 return self .__radas_config__
138166
139167
140168def get_config (cfgPath = None ) -> CharonConfig :
141169 config_file_path = cfgPath
142170 if not config_file_path or not os .path .isfile (config_file_path ):
143171 config_file_path = os .path .join (os .getenv ("HOME" , "" ), ".charon" , CONFIG_FILE )
144- data = read_yaml_from_file_path (config_file_path , ' schemas/charon.json' )
172+ data = read_yaml_from_file_path (config_file_path , " schemas/charon.json" )
145173 return CharonConfig (data )
146174
147175
148176def get_template (template_file : str ) -> str :
149- template = os .path .join (
150- os .getenv ("HOME" , '' ), ".charon/template" , template_file
151- )
177+ template = os .path .join (os .getenv ("HOME" , "" ), ".charon/template" , template_file )
152178 if os .path .isfile (template ):
153179 with open (template , encoding = "utf-8" ) as file_ :
154180 return file_ .read ()
0 commit comments