@@ -41,6 +41,7 @@ def __init__(self, mgr: 'CephadmOrchestrator',
4141 self .known_entities : Dict [str , Any ] = {key : {} for key in all_known_entities }
4242 self .per_service_name_tlsobjects = known_entities [TLSObjectScope .SERVICE ]
4343 self .per_host_tlsobjects = known_entities [TLSObjectScope .HOST ]
44+ self .global_tlsobjects = known_entities [TLSObjectScope .GLOBAL ]
4445 self .store_prefix = f'{ TLSOBJECT_STORE_PREFIX } { tlsobject_class .STORAGE_PREFIX } .'
4546
4647 def determine_tlsobject_target (self , entity : str , target : Optional [str ]) -> Tuple [Optional [str ], Optional [str ]]:
@@ -56,8 +57,10 @@ def get_tlsobject_scope_and_target(self, entity: str, service_name: Optional[str
5657 return TLSObjectScope .SERVICE , service_name
5758 elif entity in self .per_host_tlsobjects :
5859 return TLSObjectScope .HOST , host
59- else :
60+ elif entity in self . global_tlsobjects :
6061 return TLSObjectScope .GLOBAL , None
62+ else :
63+ return TLSObjectScope .UNKNOWN , None
6164
6265 def get_tlsobject (self , entity : str , service_name : Optional [str ] = None , host : Optional [str ] = None ) -> Optional [TLSObjectProtocol ]:
6366 self ._validate_tlsobject_entity (entity , service_name , host )
@@ -78,11 +81,13 @@ def save_tlsobject(self, entity: str, tlsobject: str, service_name: Optional[str
7881 key : self .tlsobject_class .to_json (self .known_entities [entity ][key ])
7982 for key in self .known_entities [entity ]
8083 }
81- else :
84+ self .mgr .set_store (self .store_prefix + entity , json .dumps (j ))
85+ elif scope == TLSObjectScope .GLOBAL :
8286 self .known_entities [entity ] = tlsobject
8387 j = self .tlsobject_class .to_json (tlsobject )
84-
85- self .mgr .set_store (self .store_prefix + entity , json .dumps (j ))
88+ self .mgr .set_store (self .store_prefix + entity , json .dumps (j ))
89+ else :
90+ logger .error (f'Trying to save entity { entity } with a not-supported/unknown TLSObjectScope scope { scope .value } ' )
8691
8792 def rm_tlsobject (self , entity : str , service_name : Optional [str ] = None , host : Optional [str ] = None ) -> None :
8893 """Remove a tlsobjectificate for a specific entity, service, or host."""
@@ -137,14 +142,19 @@ def list_tlsobjects(self) -> List[Tuple[str, Type[TLSObjectProtocol], Optional[s
137142 def load (self ) -> None :
138143 for k , v in self .mgr .get_store_prefix (self .store_prefix ).items ():
139144 entity = k [len (self .store_prefix ):]
145+ if entity not in self .known_entities :
146+ logger .warning (f"TLSObjectStore: Discarding unkown entity '{ entity } '" )
147+ continue
140148 entity_targets = json .loads (v )
141- self .known_entities [entity ] = {}
142149 if entity in self .per_service_name_tlsobjects or entity in self .per_host_tlsobjects :
150+ self .known_entities [entity ] = {}
143151 for target in entity_targets :
144152 tlsobject = self .tlsobject_class .from_json (entity_targets [target ])
145153 if tlsobject :
146154 self .known_entities [entity ][target ] = tlsobject
147- else :
155+ elif entity in self . global_tlsobjects :
148156 tlsobject = self .tlsobject_class .from_json (entity_targets )
149157 if tlsobject :
150158 self .known_entities [entity ] = tlsobject
159+ else :
160+ logger .error (f"TLSObjectStore: Found a known entity { entity } with unknown scope!" )
0 commit comments