@@ -42,9 +42,14 @@ def _lazy_sdk() -> Any:
4242 type = click .Path (dir_okay = False , writable = True ),
4343 help = "Write YAML to a file instead of stdout." ,
4444)
45+ @click .option (
46+ "--include-secrets" ,
47+ is_flag = True ,
48+ help = "Include sensitive registry authentication fields in exported YAML." ,
49+ )
4550@click .pass_context
4651@handle_errors
47- def export_cmd (ctx , name , file_path ):
52+ def export_cmd (ctx , name , file_path , include_secrets ):
4853 rt_cls = _lazy_sdk ()
4954 profile , region = ctx_cfg (ctx )
5055 build_sdk_config (profile_name = profile , region = region )
@@ -53,7 +58,7 @@ def export_cmd(ctx, name, file_path):
5358 echo_error ("ResourceNotFound" , f"AgentRuntime { name !r} not found." )
5459 raise SystemExit (EXIT_NOT_FOUND )
5560 try :
56- data = runtime_to_yaml_doc (runtime )
61+ data = runtime_to_yaml_doc (runtime , include_secrets = include_secrets )
5762 except RuntimeExportError as exc :
5863 echo_error ("UnsupportedRuntime" , str (exc ))
5964 raise SystemExit (EXIT_BAD_INPUT ) from exc
@@ -66,7 +71,9 @@ def export_cmd(ctx, name, file_path):
6671 click .echo (text , nl = False )
6772
6873
69- def runtime_to_yaml_doc (runtime : Any ) -> dict [str , Any ]:
74+ def runtime_to_yaml_doc (
75+ runtime : Any , * , include_secrets : bool = False
76+ ) -> dict [str , Any ]:
7077 artifact_type = _enum_value (_get (runtime , "artifact_type" , "artifactType" ))
7178 if artifact_type and artifact_type != "Container" :
7279 raise RuntimeExportError (
@@ -91,7 +98,9 @@ def runtime_to_yaml_doc(runtime: Any) -> dict[str, Any]:
9198 metadata , "workspace" , _get (runtime , "workspace_name" , "workspaceName" )
9299 )
93100
94- spec : dict [str , Any ] = {"container" : _export_container (container )}
101+ spec : dict [str , Any ] = {
102+ "container" : _export_container (container , include_secrets = include_secrets )
103+ }
95104 for yaml_key , attr in [
96105 ("cpu" , "cpu" ),
97106 ("memory" , "memory" ),
@@ -145,7 +154,9 @@ def runtime_to_yaml_doc(runtime: Any) -> dict[str, Any]:
145154 )
146155
147156 if hasattr (runtime , "list_endpoints" ):
148- spec ["endpoints" ] = [_export_endpoint (ep ) for ep in runtime .list_endpoints ()]
157+ endpoints = [_export_endpoint (ep ) for ep in runtime .list_endpoints ()]
158+ if endpoints :
159+ spec ["endpoints" ] = endpoints
149160
150161 return {
151162 "apiVersion" : "agentrun/v1" ,
@@ -155,7 +166,7 @@ def runtime_to_yaml_doc(runtime: Any) -> dict[str, Any]:
155166 }
156167
157168
158- def _export_container (container : Any ) -> dict [str , Any ]:
169+ def _export_container (container : Any , * , include_secrets : bool ) -> dict [str , Any ]:
159170 out : dict [str , Any ] = {"image" : _get (container , "image" )}
160171 command = _get (container , "command" )
161172 if command :
@@ -172,19 +183,23 @@ def _export_container(container: Any) -> dict[str, Any]:
172183 _set_if_present (
173184 out ,
174185 "registryConfig" ,
175- _export_registry (_get (container , "registry_config" , "registryConfig" )),
186+ _export_registry (
187+ _get (container , "registry_config" , "registryConfig" ),
188+ include_secrets = include_secrets ,
189+ ),
176190 )
177191 return out
178192
179193
180- def _export_registry (registry : Any ) -> dict [str , Any ] | None :
194+ def _export_registry (registry : Any , * , include_secrets : bool ) -> dict [str , Any ] | None :
181195 if registry is None :
182196 return None
183197 out : dict [str , Any ] = {}
184198 auth = _get (registry , "auth_config" , "authConfig" , "auth" )
185199 auth_out : dict [str , Any ] = {}
186200 _set_if_present (auth_out , "userName" , _get (auth , "user_name" , "userName" ))
187- _set_if_present (auth_out , "password" , _get (auth , "password" ))
201+ if include_secrets :
202+ _set_if_present (auth_out , "password" , _get (auth , "password" ))
188203 _set_if_present (out , "auth" , auth_out )
189204
190205 cert = _get (registry , "cert_config" , "certConfig" , "cert" )
0 commit comments