def get_state_store(meta_configs, appname, collection_name="talib_states", use_kv_store=False): if util.is_true(use_kv_store): return StateStore(meta_configs, appname, collection_name) else: return FileStateStore(meta_configs, appname)
def get(self, stanza_name, return_acl=False): """ @return: dict object if sucess otherwise raise exception """ stanza = self._conf_mgr.get_stanza(self._conf_file, stanza_name, ret_metadata=return_acl) stanza = self._decrypt(stanza) stanza["disabled"] = utils.is_true(stanza.get("disabled")) return stanza
def build_http_connection(config, timeout=120, disable_ssl_validation=False): """ :config: dict like, proxy and account information are in the following format { "username": xx, "password": yy, "proxy_url": zz, "proxy_port": aa, "proxy_username": bb, "proxy_password": cc, "proxy_type": http,http_no_tunnel,sock4,sock5, "proxy_rdns": 0 or 1, } :return: Http2.Http object """ proxy_type_to_code = { "http": socks.PROXY_TYPE_HTTP, "http_no_tunnel": socks.PROXY_TYPE_HTTP_NO_TUNNEL, "socks4": socks.PROXY_TYPE_SOCKS4, "socks5": socks.PROXY_TYPE_SOCKS5, } if config.get("proxy_type") in proxy_type_to_code: proxy_type = proxy_type_to_code[config["proxy_type"]] else: proxy_type = socks.PROXY_TYPE_HTTP rdns = scu.is_true(config.get("proxy_rdns")) proxy_info = None if config.get("proxy_url") and config.get("proxy_port"): if config.get("proxy_username") and config.get("proxy_password"): proxy_info = ProxyInfo(proxy_type=proxy_type, proxy_host=config["proxy_url"], proxy_port=int(config["proxy_port"]), proxy_user=config["proxy_username"], proxy_pass=config["proxy_password"], proxy_rdns=rdns) else: proxy_info = ProxyInfo(proxy_type=proxy_type, proxy_host=config["proxy_url"], proxy_port=int(config["proxy_port"]), proxy_rdns=rdns) if proxy_info: http = Http(proxy_info=proxy_info, timeout=timeout, disable_ssl_certificate_validation=disable_ssl_validation) else: http = Http(timeout=timeout, disable_ssl_certificate_validation=disable_ssl_validation) if config.get("username") and config.get("password"): http.add_credentials(config["username"], config["password"]) return http
def all(self, filter_disabled=False, return_acl=True): """ @return: a dict of dict objects if success otherwise exception """ results = {} stanzas = self._conf_mgr.all_stanzas(self._conf_file, ret_metadata=return_acl) for stanza in stanzas: stanza = self._decrypt(stanza) stanza["disabled"] = utils.is_true(stanza.get("disabled")) if filter_disabled and stanza["disabled"]: continue results[stanza["name"]] = stanza return results
def get_customized_setting(self, key): customized_settings = self._parse_conf().get('customized_settings', None) if not customized_settings: self.__logger.error("Customized setting is not set") return None if not key in customized_settings: self.__logger.error("Customized key can not be found") return None customized_setting = customized_settings.get(key, {}) _type = customized_setting.get("type", None) if not _type: self.__logger.error("Type of this customized setting is not set") return None if _type == "bool": return utils.is_true(customized_setting.get("bool", '0')) elif _type == "text": return customized_setting.get("content", "") elif _type == "password": return customized_setting.get("password", "") else: raise Exception("Type of this customized setting is corrupted")