def set(self, key: str, value: Any) -> None: if not self.is_setup: return if not self.can_handle(key=key): raise ConfException( 'Conf service request an unknown key `{}`.'.format(key)) if value is None: raise ConfException( 'Conf service requires a value for key `{}` to set.'.format( key)) option = self.get_option(key=key) store = self.get_store(option=option) store.set(option=option, value=value)
def get(self, key: str) -> Any: if hasattr(self._settings, key): return getattr(self._settings, key) else: raise ConfException( 'The configuration option `{}` was not found or not correctly set.' .format(key))
def clear_namespace(self, namespace: str, store: str) -> None: if store not in OptionStores.VALUES: raise ConfException('`{}` is an invalid store.'.format(store)) marker_namespace = '{}{}'.format(namespace, store) for key in self._state: if key.startswith[marker_namespace]: del self._state[key]
def get(self, option: 'Option') -> Any: if hasattr(self.settings, option.key): return getattr(self.settings, option.key) if not option.is_optional: raise ConfException( 'The config option `{}` was not found or not correctly ' 'set on the settings backend.'.format(option.key)) return option.default
def delete(self, key: str) -> None: if not self.is_setup: return if not self.can_handle(key=key): raise ConfException( 'Conf service request an unknown key `{}`.'.format(key)) option = self.get_option(key=key) store = self.get_store(option=option) store.delete(option=option)
def set(self, key: str, value: Any) -> None: if not self.is_setup: return if not self.can_handle(key=key): raise ConfException('{} service request an unknown key `{}`.'.format( self.service_name, key)) if value is None: raise ConfException('{} service requires a value for key `{}` to set.'.format( self.service_name, key)) option = self.get_option(key=key) # Convert value try: value = option.parse(value=value) except RheaError as e: raise ConfException(e) store = self.get_store(option=option) store.set(option=option, value=value) # Cache value self.cache_manager.set_to_cache(key=key, value=value, ttl=option.cache_ttl)
def delete(self, key: str) -> None: if not self.is_setup: return if not self.can_handle(key=key): raise ConfException('{} service request an unknown key `{}`.'.format( self.service_name, key)) option = self.get_option(key=key) store = self.get_store(option=option) store.delete(option=option) # Clear Cache key self.cache_manager.clear_key(key=key)
def get(self, option: 'Option') -> Any: try: config_option = self.model.objects.get(owner=self.owner, key=option.key) return config_option.secret if option.is_secret else config_option.value except (self.model.DoesNotExist, InterfaceError, ProgrammingError, OperationalError): if not option.is_optional: raise ConfException( 'The configuration option `{}` was not found or ' 'not correctly set.'.format(option.key)) return option.default
def get(self, key: str) -> Any: if not self.is_setup: return if not self.can_handle(key=key): raise ConfException( 'Conf service request an unknown key `{}`.'.format(key)) value = self.cache_manager.get_from_cache(key=key) if self.cache_manager.is_valid_value(value=value): return value option = self.get_option(key=key) store = self.get_store(option=option) return store.get(option=option)
def get(self, key: str, to_dict=False) -> Any: if not self.is_setup: return if not self.can_handle(key=key): raise ConfException( '{} service request an unknown key `{}`.'.format( self.service_name, key)) value = self.cache_manager.get_from_cache(key=key) if self.cache_manager.is_valid_value(value=value): return value option = self.get_option(key=key) store = self.get_store(option=option) value = store.get(option=option) if not to_dict: return value option_dict = option.to_dict(value=value) return option_dict
def get(self, key: str, check_cache=True, to_dict=False) -> Any: if not self.is_setup: return if not self.can_handle(key=key): raise ConfException('{} service request an unknown key `{}`.'.format( self.service_name, key)) option = self.get_option(key=key) if check_cache: value = self.cache_manager.get_from_cache(key=key) if self.cache_manager.is_valid_value(value=value): return self._get_value(option=option, value=value, to_dict=to_dict) store = self.get_store(option=option) value = store.get(option=option) # Cache value self.cache_manager.set_to_cache(key=key, value=value, ttl=option.cache_ttl) return self._get_value(option=option, value=value, to_dict=to_dict)
def get_store(self, option: 'Option') -> Any: if option.store not in self.stores: raise ConfException('Option `{}` has an invalid store.'.format(option.key)) return self.stores[option.store]
def delete(self, option: 'Option') -> None: raise ConfException( 'The settings backend does not allow to delete values, ' 'are you sure the key `{}` was correctly defined.'.format(option.key))