roots.mojo (2378B)
1 from hyf_runtime.errors import raise_runtime_contract_error 2 from hyf_runtime.namespace import join_runtime_path 3 from hyf_runtime.platform import ( 4 interactive_user_base_root, 5 service_host_cache_root, 6 service_host_config_root, 7 service_host_data_root, 8 service_host_logs_root, 9 service_host_run_root, 10 service_host_secrets_root, 11 ) 12 from hyf_runtime.profile import ( 13 interactive_user_profile, 14 repo_local_profile, 15 service_host_profile, 16 validate_runtime_profile, 17 ) 18 19 20 @fieldwise_init 21 struct RuntimeRootSet(Copyable, Movable): 22 var config_root: String 23 var data_root: String 24 var cache_root: String 25 var logs_root: String 26 var run_root: String 27 var secrets_root: String 28 29 30 def runtime_roots_from_base_root(base_root: String) raises -> RuntimeRootSet: 31 if String(base_root).strip() == "": 32 raise_runtime_contract_error("base root must not be empty") 33 34 return RuntimeRootSet( 35 config_root=join_runtime_path(base_root, "config"), 36 data_root=join_runtime_path(base_root, "data"), 37 cache_root=join_runtime_path(base_root, "cache"), 38 logs_root=join_runtime_path(base_root, "logs"), 39 run_root=join_runtime_path(base_root, "run"), 40 secrets_root=join_runtime_path(base_root, "secrets"), 41 ) 42 43 44 def interactive_user_runtime_roots(user_home: String) raises -> RuntimeRootSet: 45 return runtime_roots_from_base_root(interactive_user_base_root(user_home)) 46 47 48 def service_host_runtime_roots() -> RuntimeRootSet: 49 return RuntimeRootSet( 50 config_root=service_host_config_root(), 51 data_root=service_host_data_root(), 52 cache_root=service_host_cache_root(), 53 logs_root=service_host_logs_root(), 54 run_root=service_host_run_root(), 55 secrets_root=service_host_secrets_root(), 56 ) 57 58 59 def runtime_roots_for_unix_profile( 60 profile: String, 61 user_home: String, 62 repo_local_base_root: String, 63 ) raises -> RuntimeRootSet: 64 validate_runtime_profile(profile) 65 66 if profile == interactive_user_profile(): 67 return interactive_user_runtime_roots(user_home) 68 69 if profile == service_host_profile(): 70 return service_host_runtime_roots() 71 72 if String(repo_local_base_root).strip() == "": 73 raise_runtime_contract_error("repo_local profile requires a base root") 74 return runtime_roots_from_base_root(repo_local_base_root)