@@ -724,6 +724,63 @@ def command_repository(args: argparse.Namespace) -> int:
724724 return 0
725725
726726
727+ ACCOUNT_SYNC_CONTROL_FIELDS = {
728+ "DCA_MODE" : "dca_mode" ,
729+ "DCA_BASE_INVESTMENT_USD" : "dca_base_investment_usd" ,
730+ "IBIT_ZSCORE_EXIT_MODE" : "ibit_zscore_exit_mode" ,
731+ }
732+
733+
734+ def _service_target_entry_matches (runtime_target : dict [str , Any ], entry : dict [str , Any ]) -> bool :
735+ service_name = str (runtime_target .get ("service_name" ) or "" ).strip ()
736+ account_scope = str (runtime_target .get ("account_scope" ) or "" ).strip ()
737+ entry_runtime = entry .get ("runtime_target" ) if isinstance (entry .get ("runtime_target" ), dict ) else {}
738+ candidates = {
739+ str (entry .get ("service" ) or "" ).strip (),
740+ str (entry .get ("service_name" ) or "" ).strip (),
741+ str (entry_runtime .get ("service_name" ) or "" ).strip (),
742+ str (entry_runtime .get ("account_scope" ) or "" ).strip (),
743+ str (entry .get ("ACCOUNT_GROUP" ) or "" ).strip (),
744+ }
745+ return service_name in candidates or account_scope in candidates
746+
747+
748+ def extract_account_sync_controls (target : dict [str , Any ]) -> dict [str , str ]:
749+ extra_variables = dict (target .get ("extra_variables" ) or {})
750+ controls : dict [str , str ] = {}
751+ for source_key , payload_key in ACCOUNT_SYNC_CONTROL_FIELDS .items ():
752+ value = extra_variables .get (source_key )
753+ if value not in (None , "" ):
754+ controls [payload_key ] = str (value ).strip ()
755+
756+ service_targets = extra_variables .get ("CLOUD_RUN_SERVICE_TARGETS_JSON" )
757+ if isinstance (service_targets , str ):
758+ try :
759+ service_targets = json .loads (service_targets )
760+ except json .JSONDecodeError :
761+ service_targets = None
762+
763+ runtime_target = target .get ("runtime_target" ) if isinstance (target .get ("runtime_target" ), dict ) else {}
764+ if isinstance (service_targets , dict ):
765+ entries = service_targets .get ("targets" ) if isinstance (service_targets .get ("targets" ), list ) else []
766+ matched = next (
767+ (
768+ entry
769+ for entry in entries
770+ if isinstance (entry , dict ) and _service_target_entry_matches (runtime_target , entry )
771+ ),
772+ None ,
773+ )
774+ if matched :
775+ for source_key , payload_key in ACCOUNT_SYNC_CONTROL_FIELDS .items ():
776+ if payload_key in controls :
777+ continue
778+ value = matched .get (source_key )
779+ if value not in (None , "" ):
780+ controls [payload_key ] = str (value ).strip ()
781+ return controls
782+
783+
727784def build_parser () -> argparse .ArgumentParser :
728785 parser = argparse .ArgumentParser (description = __doc__ )
729786 subparsers = parser .add_subparsers (dest = "command" , required = True )
0 commit comments