def _get_display_value(self, config): dv = config.get("display_value", "") if utils.is_false(dv): return "false" if utils.is_true(dv): return "true" if dv and dv in self._SUPPORTED_DISPLAY_VALUES: return dv return sc.DEFAULT_DISPLAY_VALUE
def _get_default_configs(self): """ Get default configuration of this TA If default/service_now.conf doesn't contain the default config assign the default configuration """ defaults = {} self.conf_manager.reload_confs(("service_now", )) snow_conf = self.conf_manager.get_conf("nobody", self.appname, "service_now") if not snow_conf: _LOGGER.error("Failed to get service_now.conf") raise Exception("Failed to get service_now.conf") snow_conf = {stanza["stanza"]: stanza for stanza in snow_conf} for stanza in ("snow_account", "snow_default", "snow_proxy"): defaults.update(snow_conf[stanza]) if defaults["proxy_port"]: defaults["proxy_port"] = int(defaults["proxy_port"]) if defaults["proxy_rdns"]: defaults["proxy_rdns"] = utils.is_true(defaults["proxy_rdns"]) if defaults.get("proxy_type"): valid_proxy_types = ("http", "http_no_tunnel", "socks4", "socks5") if defaults["proxy_type"] not in valid_proxy_types: msg = "Invalid proxy type={}, only {} are supported".format( defaults["proxy_type"], valid_proxy_types) _LOGGER.error(msg) raise Exception(msg) else: defaults["proxy_type"] = "http" if utils.is_false(defaults["proxy_enabled"]): defaults["proxy_url"] = "" defaults["proxy_port"] = "" conf_copy = copy.deepcopy(defaults) self._decrypt_existing_credentials(conf_copy) keys = (("collection_interval", 60), ("priority", 10), ("loglevel", "INFO"), ("since_when", "now"), ("display_value", consts.DEFAULT_DISPLAY_VALUE)) for k, v in keys: if k not in defaults: defaults[k] = v return defaults
def _get_service_now_account(self): app = snow_consts.app_name snow_conf = scc.getMergedConf("service_now") snow_account = {} for stanza in ("snow_default", "snow_account", "snow_proxy"): snow_account.update(snow_conf[stanza]) mgr = cred.CredentialManager(self.getSessionKey(), scc.getMgmtUri()) accs = (("url", "username", "password"), ("proxy_url", "proxy_username", "proxy_password")) for (url_k, user_k, pass_k) in accs: url = snow_account[url_k] username = snow_account[user_k] password = snow_account[pass_k] if url and username == snow_consts.encrypted \ and password == snow_consts.encrypted: userpass = mgr.get_clear_password(url, snow_consts.dummy, app) if not userpass: msg = "Failed to get clear credentials for %s" % url _LOGGER.error(msg) raise Exception(msg) username, password = userpass.split(snow_consts.userpass_sep) snow_account[user_k] = username snow_account[pass_k] = password if snow_account["proxy_port"]: snow_account["proxy_port"] = int(snow_account["proxy_port"]) if utils.is_false(snow_account["proxy_enabled"]): snow_account["proxy_url"] = "" snow_account["proxy_port"] = "" snow_url = snow_account["url"] if not snow_url: raise Exception("ServiceNow account has not been setup.") if not snow_url.startswith("https://"): snow_url = "https://%s" % snow_url if not snow_url.endswith("/"): snow_url = "%s/" % snow_url snow_account["url"] = snow_url return snow_account
def _get_service_now_account(self): app = snow_consts.app_name snow_conf = scc.getMergedConf("service_now") snow_account = {} for stanza in ("snow_default", "snow_account", "snow_proxy"): snow_account.update(snow_conf[stanza]) mgr = cred.CredentialManager(self.session_key, scc.getMgmtUri()) accs = (("url", "username", "password"), ("proxy_url", "proxy_username", "proxy_password")) for (url_k, user_k, pass_k) in accs: url = snow_account[url_k] username = snow_account[user_k] password = snow_account[pass_k] if url and username == "<encrypted>" and password == "<encrypted>": userpass = mgr.get_clear_password(url, "dummy", app) if not userpass: self.logger.error("Failed to get clear credentials for %s", url) raise Exception("Failed to get clear credentials" " for {}".format(url)) username, password = userpass.split("``") snow_account[user_k] = username snow_account[pass_k] = password if snow_account["proxy_port"]: snow_account["proxy_port"] = int(snow_account["proxy_port"]) if utils.is_false(snow_account["proxy_enabled"]): snow_account["proxy_url"] = "" snow_account["proxy_port"] = "" snow_url = snow_account["url"] if not snow_url: raise Exception("ServiceNow account has not been setup.") if not snow_url.startswith("https://"): snow_url = "https://{}".format(snow_url) if not snow_url.endswith("/"): snow_url = "{}/".format(snow_url) snow_account["url"] = snow_url return snow_account