Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Update st2.inquiry.respond action
Update st2client respond command to use this?
"""
url = '/%s/%s' % (self.resource.get_url_path_name(), inquiry_id)
payload = {"id": inquiry_id, "response": inquiry_response}
response = self.client.put(url, payload, **kwargs)
if response.status_code != http_client.OK:
self.handle_error(response)
return self.resource.deserialize(response.json())
class TriggerInstanceResourceManager(ResourceManager):
@add_auth_token_to_kwargs_from_env
def re_emit(self, trigger_instance_id, **kwargs):
url = '/%s/%s/re_emit' % (self.resource.get_url_path_name(), trigger_instance_id)
response = self.client.post(url, None, **kwargs)
if response.status_code != http_client.OK:
self.handle_error(response)
return response.json()
class AsyncRequest(Resource):
pass
class PackResourceManager(ResourceManager):
@add_auth_token_to_kwargs_from_env
def install(self, packs, force=False, python3=False, **kwargs):
class TriggerInstanceResourceManager(ResourceManager):
@add_auth_token_to_kwargs_from_env
def re_emit(self, trigger_instance_id, **kwargs):
url = '/%s/%s/re_emit' % (self.resource.get_url_path_name(), trigger_instance_id)
response = self.client.post(url, None, **kwargs)
if response.status_code != http_client.OK:
self.handle_error(response)
return response.json()
class AsyncRequest(Resource):
pass
class PackResourceManager(ResourceManager):
@add_auth_token_to_kwargs_from_env
def install(self, packs, force=False, python3=False, **kwargs):
url = '/%s/install' % (self.resource.get_url_path_name())
payload = {'packs': packs, 'force': force, 'python3': python3}
response = self.client.post(url, payload, **kwargs)
if response.status_code != http_client.OK:
self.handle_error(response)
instance = AsyncRequest.deserialize(response.json())
return instance
@add_auth_token_to_kwargs_from_env
def remove(self, packs, **kwargs):
url = '/%s/uninstall' % (self.resource.get_url_path_name())
response = self.client.post(url, {'packs': packs}, **kwargs)
if response.status_code != http_client.OK:
self.handle_error(response)
url = '/%s/%s/children' % (self.resource.get_url_path_name(), execution_id)
depth = kwargs.pop('depth', -1)
params = kwargs.pop('params', {})
if depth:
params['depth'] = depth
response = self.client.get(url=url, params=params, **kwargs)
if response.status_code != http_client.OK:
self.handle_error(response)
return [self.resource.deserialize(item) for item in response.json()]
class InquiryResourceManager(ResourceManager):
@add_auth_token_to_kwargs_from_env
def respond(self, inquiry_id, inquiry_response, **kwargs):
"""
Update st2.inquiry.respond action
Update st2client respond command to use this?
"""
url = '/%s/%s' % (self.resource.get_url_path_name(), inquiry_id)
payload = {"id": inquiry_id, "response": inquiry_response}
response = self.client.put(url, payload, **kwargs)
if response.status_code != http_client.OK:
self.handle_error(response)
return self.resource.deserialize(response.json())
return (self.resource.deserialize(match['actionalias']), match['representation'])
class ActionAliasExecutionManager(ResourceManager):
@add_auth_token_to_kwargs_from_env
def match_and_execute(self, instance, **kwargs):
url = '/%s/match_and_execute' % self.resource.get_url_path_name()
response = self.client.post(url, instance.serialize(), **kwargs)
if response.status_code != http_client.OK:
self.handle_error(response)
instance = self.resource.deserialize(response.json())
return instance
class ExecutionResourceManager(ResourceManager):
@add_auth_token_to_kwargs_from_env
def re_run(self, execution_id, parameters=None, tasks=None, no_reset=None, delay=0, **kwargs):
url = '/%s/%s/re_run' % (self.resource.get_url_path_name(), execution_id)
tasks = tasks or []
no_reset = no_reset or []
if list(set(no_reset) - set(tasks)):
raise ValueError('List of tasks to reset does not match the tasks to rerun.')
data = {
'parameters': parameters or {},
'tasks': tasks,
'reset': list(set(tasks) - set(no_reset)),
'delay': delay,
}
@add_auth_token_to_kwargs_from_env
def register(self, packs=None, types=None, **kwargs):
url = '/%s/register' % (self.resource.get_url_path_name())
payload = {}
if types:
payload['types'] = types
if packs:
payload['packs'] = packs
response = self.client.post(url, payload, **kwargs)
if response.status_code != http_client.OK:
self.handle_error(response)
instance = self.resource.deserialize(response.json())
return instance
class ConfigManager(ResourceManager):
@add_auth_token_to_kwargs_from_env
def update(self, instance, **kwargs):
url = '/%s/%s' % (self.resource.get_url_path_name(), instance.pack)
response = self.client.put(url, instance.values, **kwargs)
if response.status_code != http_client.OK:
self.handle_error(response)
instance = self.resource.deserialize(response.json())
return instance
class WebhookManager(ResourceManager):
def __init__(self, resource, endpoint, cacert=None, debug=False):
self.resource = resource
self.debug = debug
self.client = httpclient.HTTPClient(root=endpoint, cacert=cacert, debug=debug)
raise TypeError('Workflow definition is not type of string.')
if 'headers' not in kwargs:
kwargs['headers'] = {}
kwargs['headers']['content-type'] = 'text/plain'
response = self.client.post_raw(url, definition, **kwargs)
if response.status_code != http_client.OK:
self.handle_error(response)
return response.json()
class ServiceRegistryGroupsManager(ResourceManager):
@add_auth_token_to_kwargs_from_env
def list(self, **kwargs):
url = '/service_registry/groups'
headers = {}
response = self.client.get(url, headers=headers, **kwargs)
if response.status_code != http_client.OK:
self.handle_error(response)
groups = response.json()['groups']
result = []
for group in groups:
item = self.resource.deserialize({'group_id': group})
result.append(item)
instance = self.resource.deserialize(response.json())
return instance
class ConfigManager(ResourceManager):
@add_auth_token_to_kwargs_from_env
def update(self, instance, **kwargs):
url = '/%s/%s' % (self.resource.get_url_path_name(), instance.pack)
response = self.client.put(url, instance.values, **kwargs)
if response.status_code != http_client.OK:
self.handle_error(response)
instance = self.resource.deserialize(response.json())
return instance
class WebhookManager(ResourceManager):
def __init__(self, resource, endpoint, cacert=None, debug=False):
self.resource = resource
self.debug = debug
self.client = httpclient.HTTPClient(root=endpoint, cacert=cacert, debug=debug)
@add_auth_token_to_kwargs_from_env
def post_generic_webhook(self, trigger, payload=None, trace_tag=None, **kwargs):
url = '/webhooks/st2'
headers = {}
data = {'trigger': trigger, 'payload': payload or {}}
if trace_tag:
headers['St2-Trace-Tag'] = trace_tag
response = self.client.post(url, data=data, headers=headers, **kwargs)
def __init__(self, resource, endpoint, cacert=None, debug=False):
self.resource = resource
self.debug = debug
self.client = httpclient.HTTPClient(root=endpoint, cacert=cacert, debug=debug)
@add_auth_token_to_kwargs_from_env
def match(self, instance, **kwargs):
url = '/%s/match' % self.resource.get_url_path_name()
response = self.client.post(url, instance.serialize(), **kwargs)
if response.status_code != http_client.OK:
self.handle_error(response)
match = response.json()
return (self.resource.deserialize(match['actionalias']), match['representation'])
class ActionAliasExecutionManager(ResourceManager):
@add_auth_token_to_kwargs_from_env
def match_and_execute(self, instance, **kwargs):
url = '/%s/match_and_execute' % self.resource.get_url_path_name()
response = self.client.post(url, instance.serialize(), **kwargs)
if response.status_code != http_client.OK:
self.handle_error(response)
instance = self.resource.deserialize(response.json())
return instance
class ExecutionResourceManager(ResourceManager):
@add_auth_token_to_kwargs_from_env
def re_run(self, execution_id, parameters=None, tasks=None, no_reset=None, delay=0, **kwargs):
url = '/%s/%s/re_run' % (self.resource.get_url_path_name(), execution_id)
response = self.client.get(url, headers=headers, **kwargs)
if response.status_code != http_client.OK:
self.handle_error(response)
groups = response.json()['groups']
result = []
for group in groups:
item = self.resource.deserialize({'group_id': group})
result.append(item)
return result
class ServiceRegistryMembersManager(ResourceManager):
@add_auth_token_to_kwargs_from_env
def list(self, group_id, **kwargs):
url = '/service_registry/groups/%s/members' % (group_id)
headers = {}
response = self.client.get(url, headers=headers, **kwargs)
if response.status_code != http_client.OK:
self.handle_error(response)
members = response.json()['members']
result = []
for member in members:
data = {
'group_id': group_id,
http_client.OK,
http_client.NO_CONTENT,
http_client.NOT_FOUND,
]:
self.handle_error(response)
return False
try:
resp_json = response.json()
if resp_json:
return resp_json
except:
pass
return True
class ActionAliasResourceManager(ResourceManager):
def __init__(self, resource, endpoint, cacert=None, debug=False):
self.resource = resource
self.debug = debug
self.client = httpclient.HTTPClient(root=endpoint, cacert=cacert, debug=debug)
@add_auth_token_to_kwargs_from_env
def match(self, instance, **kwargs):
url = '/%s/match' % self.resource.get_url_path_name()
response = self.client.post(url, instance.serialize(), **kwargs)
if response.status_code != http_client.OK:
self.handle_error(response)
match = response.json()
return (self.resource.deserialize(match['actionalias']), match['representation'])
class ActionAliasExecutionManager(ResourceManager):