1+ from abc import ABC , abstractmethod
12from collections import OrderedDict
23from functools import partial
34
1314)
1415
1516
16- class Skyflow :
17+ class ISkyflow (ABC ):
18+ @classmethod
19+ @abstractmethod
20+ def builder (cls ):
21+ raise NotImplementedError
22+
23+ @abstractmethod
24+ def add_vault_config (self , config ):
25+ raise NotImplementedError
26+
27+ @abstractmethod
28+ def remove_vault_config (self , vault_id ):
29+ raise NotImplementedError
30+
31+ @abstractmethod
32+ def update_vault_config (self , config ):
33+ raise NotImplementedError
34+
35+ @abstractmethod
36+ def get_vault_config (self , vault_id ):
37+ raise NotImplementedError
38+
39+ @abstractmethod
40+ def add_connection_config (self , config ):
41+ raise NotImplementedError
42+
43+ @abstractmethod
44+ def remove_connection_config (self , connection_id ):
45+ raise NotImplementedError
46+
47+ @abstractmethod
48+ def update_connection_config (self , config ):
49+ raise NotImplementedError
50+
51+ @abstractmethod
52+ def get_connection_config (self , connection_id ):
53+ raise NotImplementedError
54+
55+ @abstractmethod
56+ def add_skyflow_credentials (self , credentials ):
57+ raise NotImplementedError
58+
59+ @abstractmethod
60+ def update_skyflow_credentials (self , credentials ):
61+ raise NotImplementedError
62+
63+ @abstractmethod
64+ def set_log_level (self , log_level ):
65+ raise NotImplementedError
66+
67+ @abstractmethod
68+ def update_log_level (self , log_level ):
69+ raise NotImplementedError
70+
71+ @abstractmethod
72+ def get_log_level (self ):
73+ raise NotImplementedError
74+
75+ @abstractmethod
76+ def vault (self , vault_id = None ):
77+ raise NotImplementedError
78+
79+ @abstractmethod
80+ def connection (self , connection_id = None ):
81+ raise NotImplementedError
82+
83+ @abstractmethod
84+ def detect (self , vault_id = None ):
85+ raise NotImplementedError
86+
87+
88+ class BaseSkyflow (ISkyflow ):
89+
1790 def __init__ (self , builder ):
1891 self .__builder = builder
1992 log_info (self .__builder ._skyflow_messages .Info .CLIENT_INITIALIZED .value , self .__builder .get_logger ())
@@ -87,9 +160,10 @@ def detect(self, vault_id=None):
87160 vault_config = self .__builder .get_vault_config (vault_id )
88161 return vault_config .get (OptionField .DETECT_CONTROLLER )
89162
90- class Builder :
163+ class Builder ( ABC ) :
91164 # -- hooks, filled in per-variant by make_skyflow_class() -- left None here so using
92- # this template directly (rather than through make_skyflow_class()) fails fast.
165+ # this template directly (rather than through make_skyflow_class()) fails fast, with a
166+ # clear message (see _REQUIRED_HOOKS check in __init__ below).
93167 _vault_client_cls = None
94168 _vault_controller_cls = None
95169 _connection_cls = None
@@ -106,7 +180,21 @@ class Builder:
106180 _validate_credentials = None
107181 _set_active_log_level = None
108182
183+ # Connection/Detect support and their validators are legitimately optional per variant --
184+ # everything else must be supplied by make_skyflow_class() before this Builder is usable.
185+ _REQUIRED_HOOKS = (
186+ '_vault_client_cls' , '_vault_controller_cls' , '_logger_cls' , '_default_log_level' ,
187+ '_skyflow_messages' , '_skyflow_cls' , '_validate_vault_config' ,
188+ '_validate_update_vault_config' , '_validate_log_level' , '_validate_credentials' ,
189+ )
190+
109191 def __init__ (self ):
192+ missing = [hook for hook in self ._REQUIRED_HOOKS if getattr (self , hook ) is None ]
193+ if missing :
194+ raise NotImplementedError (
195+ "BaseSkyflow.Builder is an interface template -- build a concrete Skyflow "
196+ f"class via make_skyflow_class() instead of using it directly. Missing: { ', ' .join (missing )} "
197+ )
110198 self .__vault_configs = OrderedDict ()
111199 self .__vault_list = list ()
112200 self .__connection_configs = OrderedDict ()
@@ -326,7 +414,7 @@ def make_skyflow_class(*, vault_client_cls, vault_controller_cls, skyflow_messag
326414 '_validate_credentials' : staticmethod (validate_credentials ),
327415 '_set_active_log_level' : staticmethod (set_active_log_level ) if set_active_log_level else None ,
328416 }
329- variant_builder = type ('Builder' , (Skyflow .Builder ,), builder_attrs )
330- variant_skyflow = type ('Skyflow' , (Skyflow ,), {'Builder' : variant_builder })
417+ variant_builder = type ('Builder' , (BaseSkyflow .Builder ,), builder_attrs )
418+ variant_skyflow = type ('Skyflow' , (BaseSkyflow ,), {'Builder' : variant_builder })
331419 variant_builder ._skyflow_cls = variant_skyflow
332420 return variant_skyflow
0 commit comments