Ver Fonte

Add disabled flag to service config — skips registration without bad credentials

ZiB há 4 meses atrás
pai
commit
1ab031168a
2 ficheiros alterados com 8 adições e 0 exclusões
  1. 2 0
      room_cal/_utils.py
  2. 6 0
      room_cal/service_api/client.py

+ 2 - 0
room_cal/_utils.py

@@ -158,6 +158,7 @@ class ServiceConfig:
   account_id: str = ''
   hotel_id: str = ''
   rate_id: str = ''
+  disabled: bool = False
   fees: ServiceFees = field(default_factory=ServiceFees)
   taxes: ServiceTaxes = field(default_factory=ServiceTaxes)
 
@@ -170,6 +171,7 @@ class ServiceConfig:
       account_id=str(d.get('account_id', '')),
       hotel_id=str(d.get('hotel_id', '')),
       rate_id=str(d.get('rate_id', '')),
+      disabled=bool(d.get('disabled', False)),
       fees=ServiceFees.from_dict(d.get('fees', {})),
       taxes=ServiceTaxes.from_dict(d.get('taxes', {})),
     )

+ 6 - 0
room_cal/service_api/client.py

@@ -24,13 +24,19 @@ class ServiceAPI:
     if clients is not None:
       self._clients: dict[str, ServiceClient] = clients
       return
+    from room_cal._utils import get_config
     self._clients = {}
     self._disabled: dict[str, str] = {}
+    svc_cfg = get_config().services
     for key, factory in {
       'airbnb': _AirbnbClient.from_env,
       'booking': _BookingClient.from_env,
       'homestay': _HomestayClient.from_env,
     }.items():
+      if (cfg := svc_cfg.get(key)) and cfg.disabled:
+        _log.info('service %s disabled by config', key)
+        self._disabled[key] = 'disabled in config'
+        continue
       try:
         self._clients[key] = factory()
       except Exception as e: