Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# Only the default stanza. In this case, modinput should exit.
self.log_warning("No stanza found for input type: " + self.input_type)
sys.exit(0)
account_fields = self.get_account_fields()
checkbox_fields = self.get_checkbox_fields()
self.input_stanzas = {}
for stanza in all_stanzas:
full_stanza_name = '{}://{}'.format(self.input_type, stanza.get('name'))
if full_stanza_name in inputs.inputs:
if stanza.get('disabled', False):
raise RuntimeError("Running disabled data input!")
stanza_params = {}
for k, v in stanza.iteritems():
if k in checkbox_fields:
stanza_params[k] = sutils.is_true(v)
elif k in account_fields:
stanza_params[k] = copy.deepcopy(v)
else:
stanza_params[k] = v
self.input_stanzas[stanza.get('name')] = stanza_params
def _get_hec_config(self, hec_input_name, session_key,
scheme, host, port, **context):
hc = HECConfig(
session_key, scheme=scheme, host=host, port=port, **context)
settings = hc.get_settings()
if utils.is_true(settings.get('disabled')):
# Enable HEC input
logging.info('Enabling HEC')
settings['disabled'] = '0'
settings['enableSSL'] = context.get('hec_enablessl', '1')
settings['port'] = context.get('hec_port', '8088')
hc.update_settings(settings)
hec_input = hc.get_input(hec_input_name)
if not hec_input:
# Create HEC input
logging.info('Create HEC datainput, name=%s', hec_input_name)
hinput = {
'index': context.get('index', 'main'),
}
if context.get('sourcetype'):
Usage::
>>> serverinfo = solnlib.server_info.ServerInfo(session_key)
>>> while 1:
>>> if serverinfo.is_captain_ready():
>>> break
>>> time.sleep(2)
>>>
>>> # If do_stuff can only be executed in SH captain
>>> if serverinfo.is_captain():
>>> do_stuff()
'''
cap_info = self.captain_info()
return utils.is_true(cap_info["service_ready_flag"]) and \
utils.is_false(cap_info["maintenance_mode"])
def __init__(self, uri, session_key, logger=None):
self.__uri = uri
self.__session_key = session_key
self.__logger = logger
self.scheme, self.host, self.port = utils.extract_http_scheme_host_port(
self.__uri)
self.__cached_global_settings = {}
self.__global_config = None
def __init__(self, uri, session_key, logger=None):
self.__uri = uri
self.__session_key = session_key
self.__logger = logger
self.scheme, self.host, self.port = utils.extract_http_scheme_host_port(
self.__uri)
self.encrypt_fields_credential = (setup_const.password,)
self.encrypt_fields_customized = (setup_const.password,)
self.cred_confs = (
(setup_const.myta_credential_settings, setup_const.myta_credential_conf),)
self.__cached_global_settings = None
def handleList(self, confInfo):
logger.info("start list setup configure.")
scheme, host, port = utils.extract_http_scheme_host_port(scc.getMgmtUri())
conf_mgr = conf.ConfManager(self.getSessionKey(), self.appName, scheme=scheme, host=host, port=port)
ta_conf_file = get_or_create_conf_file(conf_mgr, setup_const.myta_conf)
# read globala and proxy settings
all_settings = ta_conf_file.get_all()
if not all_settings:
all_settings = {}
self._setNoneValues(all_settings.get(setup_const.global_settings, {}))
# read account credential settings
for cred, cred_conf in self.cred_confs:
cred_conf_file = get_or_create_conf_file(conf_mgr, cred_conf)
creds = cred_conf_file.get_all()
if creds:
self._setNoneValues(creds)
all_settings.update({cred: creds})
# customized conf
customized_conf_file = get_or_create_conf_file(conf_mgr, setup_const.myta_customized_conf)
def get_proxy_settings(self):
proxy_settings = self._parse_conf().get('proxy_settings', None)
if not proxy_settings:
self.log_info("Proxy is not set!")
return {}
proxy_enabled = utils.is_true(proxy_settings.get("proxy_enabled", '0'))
if not proxy_enabled:
return {}
proxy_settings = {
"proxy_url": proxy_settings.get("proxy_url", ""),
"proxy_port": proxy_settings.get("proxy_port", ""),
"proxy_username": proxy_settings.get("proxy_username", ""),
"proxy_password": proxy_settings.get("proxy_password", ""),
"proxy_type": proxy_settings.get("proxy_type", ""),
"proxy_rdns": utils.is_true(proxy_settings.get("proxy_rdns", '0'))
}
return proxy_settings
def _init_ckpt(self):
if self.ckpt is None:
if 'AOB_TEST' in os.environ:
ckpt_dir = self.context_meta.get('checkpoint_dir', tempfile.mkdtemp())
if not os.path.exists(ckpt_dir):
os.makedirs(ckpt_dir)
self.ckpt = checkpointer.FileCheckpointer(ckpt_dir)
else:
if 'server_uri' not in self.context_meta:
raise ValueError('server_uri not found in input meta.')
if 'session_key' not in self.context_meta:
raise ValueError('session_key not found in input meta.')
dscheme, dhost, dport = sutils.extract_http_scheme_host_port(self.context_meta[
'server_uri'])
self.ckpt = checkpointer.KVStoreCheckpointer(self.app + "_checkpointer", self.context_meta['session_key'], self.app,
scheme=dscheme, host=dhost, port=dport)
Usage::
>>> serverinfo = solnlib.server_info.ServerInfo(session_key)
>>> while 1:
>>> if serverinfo.is_captain_ready():
>>> break
>>> time.sleep(2)
>>>
>>> # If do_stuff can only be executed in SH captain
>>> if serverinfo.is_captain():
>>> do_stuff()
'''
cap_info = self.captain_info()
return utils.is_true(cap_info["service_ready_flag"]) and \
utils.is_false(cap_info["maintenance_mode"])