feat: config_loader, mock_state, state_machine (v0.1.0)
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
"""
|
||||
config_loader.py — загрузка сгенерированных YAML-конфигов сервисов.
|
||||
|
||||
Читает все .yaml из services/, строит два индекса:
|
||||
- services: {service_id: service_def}
|
||||
- ops_index: {svcOperationId: service_def} (для поиска по opId)
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
import yaml
|
||||
|
||||
YAML_EXTS = (".yaml", ".yml")
|
||||
|
||||
|
||||
def load_services(services_dir="services"):
|
||||
"""Загружает все сервисы из директории YAML-конфигов.
|
||||
|
||||
Возвращает (services, ops_index):
|
||||
services — dict[service_id] = service_def
|
||||
ops_index — dict[svcOperationId] = service_def
|
||||
|
||||
service_def содержит:
|
||||
name, service_id, service_display_name, service_short_name,
|
||||
lifecycle, operations, cfsParams, cfsParamsByOp,
|
||||
stateParams, stateOut
|
||||
"""
|
||||
if not os.path.isdir(services_dir):
|
||||
raise FileNotFoundError(f"Services directory not found: {services_dir}")
|
||||
|
||||
services = {}
|
||||
ops_index = {}
|
||||
|
||||
for fname in sorted(os.listdir(services_dir)):
|
||||
if not fname.lower().endswith(YAML_EXTS):
|
||||
continue
|
||||
|
||||
path = os.path.join(services_dir, fname)
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
cfg = yaml.safe_load(f)
|
||||
|
||||
if not cfg:
|
||||
continue
|
||||
|
||||
svc_id = cfg["service_id"]
|
||||
services[svc_id] = cfg
|
||||
|
||||
# Индекс по svcOperationId — для поиска «какому сервису принадлежит операция»
|
||||
for op in cfg.get("operations", []):
|
||||
ops_index[op["svcOperationId"]] = cfg
|
||||
|
||||
return services, ops_index
|
||||
Reference in New Issue
Block a user