Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setUpClass(cls):
cls.st2client = st2.Client(base_url='http://127.0.0.1')
def __init__(self, config=None, action_service=None):
super(FormatResultAction, self).__init__(config=config, action_service=action_service)
api_url = os.environ.get('ST2_ACTION_API_URL', None)
token = os.environ.get('ST2_ACTION_AUTH_TOKEN', None)
self.client = Client(api_url=api_url, token=token)
self.jinja = jinja_utils.get_jinja_environment(allow_undefined=True)
self.jinja.tests['in'] = lambda item, list: item in list
path = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(path, 'templates/default.j2'), 'r') as f:
self.default_template = f.read()
def run(self, identifier, identifier_type, lc_type_id, additional_changes):
st2client = Client(base_url='http://localhost')
# search st2 datastore for value stored under the lifecycle event id
# in the datastore, the IDs are stored under the format
# lc_{lc event id} so prepend 'lc_'
key = "lc_%s" % lc_type_id
lc_type_name = st2client.keys.get_by_name(name=key)
# add device identifier to payload
payload = {identifier_type: identifier}
# change obj cat with the LC name (as a basic example)
changes = {
"new_object_category": "%s" % (lc_type_name.value),
}
payload.update(changes)
def __init__(self, config=None):
super(MistralDSLTransformer, self).__init__(config)
self.st2client = client.Client()
def run(self, key, action, st2host='localhost', value=""):
st2_endpoints = {
'action': "http://%s:9101" % st2host,
'reactor': "http://%s:9102" % st2host,
'datastore': "http://%s:9103" % st2host
}
try:
client = Client(st2_endpoints)
except Exception as e:
return e
if action == 'get':
kvp = client.keys.get_by_name(key)
if not kvp:
raise Exception('Key error with %s.' % key)
return kvp.value
else:
instance = KeyValuePair()
if action == 'set':
instance.id = key
else:
instance.id = client.keys.get_by_name(key).id
def select(self, query, data, key):
q = query
if data:
values = self._list_to_string(data)
q = q.format(values)
c = self.db.cursor()
try:
c.execute(q)
output = self._format_results(c)
if key is not None:
client = Client(base_url='http://localhost')
client.keys.update(KeyValuePair(name=key, value=str(output)))
return key
else:
return output
except MySQLdb.Error as e: # pylint: disable=no-member
raise Exception(e)
def match(self, text, st2token):
auth_kwargs = st2token.st2client()
if LOG.level <= logging.DEBUG:
auth_kwargs['debug'] = True
base_url = self._baseurl(self.cfg.api_url)
LOG.debug("Create st2 client with {} {} {}".format(
base_url,
self.cfg.api_url,
auth_kwargs)
)
st2_client = Client(
base_url=base_url,
api_url=self.cfg.api_url,
**auth_kwargs
)
alias_match = ActionAliasMatch()
alias_match.command = text
resp = ResultSet()
try:
resp.OK(st2_client.managers['ActionAlias'].match(alias_match))
except HTTPError as e:
if e.response is not None and e.response.status_code == 400:
resp.error(
1,
"st2 command '{}' not found. View available commands with {}st2help.".format(
def __init__(self, config):
super(St2RegisterAction, self).__init__(config)
self._client = Client
self._kvp = KeyValuePair
self.client = self._get_client()
try:
resp = RoutesInfoRequest(dest_host,
listen_web_port,
api_token,
ip_version,
command_parameters).execute()
except BIRDProxyError as e:
return (False, str(e))
response = resp.get("outcome")
data = resp.get("message")
if response and store_results:
api_base_url = self.config.get('st2_base_url')
st_client = Client(base_url=api_base_url)
key = "routes_info_{}_{}".format(
router_id, ip_version)
value = json.dumps(data)
pair = KeyValuePair(name=key,
value=value)
if ttl is not None:
pair.ttl = ttl
try:
st_client.keys.update(pair)
except Exception as e:
return (False, str(e))
return(response, key)
else:
return (response, data)
def __init__(self, config=None):
super(ExecuteActionAliasAction, self).__init__(config=config)
api_url = os.environ.get('ST2_ACTION_API_URL', None)
token = os.environ.get('ST2_ACTION_AUTH_TOKEN', None)
self.client = Client(api_url=api_url, token=token)