本文整理汇总了Python中RequestObject.RequestObject类的典型用法代码示例。如果您正苦于以下问题:Python RequestObject类的具体用法?Python RequestObject怎么用?Python RequestObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RequestObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: upload
def upload(self, body):
""" upload document """
if self._resource_type == ResourceType.DOCUMENTS:
prop = self._resource_properties['document_upload']
elif self._resource_type == ResourceType.SIGNATURES:
prop = self._resource_properties['signature_upload']
else:
self._tc.tcl.error('Upload requested for wrong resource type.')
raise AttributeError(ErrorCodes.e10330.value)
ro = RequestObject()
ro.set_body(body)
ro.set_content_type('application/octet-stream')
ro.set_description('upload document for "{0}"'.format(self._name))
# determine whether the file contents exist using phase (not 100%)
if self.phase == 1:
ro.set_http_method(prop['http_method'])
else:
ro.set_http_method('PUT')
ro.set_owner_allowed(prop['owner_allowed'])
ro.set_request_uri(prop['uri'].format(self._id))
ro.set_resource_pagination(prop['pagination'])
ro.set_resource_type(self._resource_type)
success_callback = lambda request, response: self.set_contents(request.body)
ro.set_success_callback(success_callback)
self._resource_container.add_commit_queue(self.id, ro)
示例2: add_security_label
def add_security_label(self, security_label_name):
""" retrieve attributes for this indicator """
prop = self._resource_properties['add_security_label']
ro = RequestObject()
ro.set_description('deleting security label {0} for attribute {1} of object {2}'.format(security_label_name,
self.id,
self._container.id))
ro.set_http_method(prop['http_method'])
ro.set_owner_allowed(prop['owner_allowed'])
resource_uri = self._container._resource_properties['id']['uri']
try:
resource_uri = resource_uri.format(self._container.indicator)
except AttributeError:
resource_uri = resource_uri.format(self._container.id)
ro.set_request_uri(prop['uri'].format(resource_uri, self.id, security_label_name))
ro.set_resource_pagination(prop['pagination'])
callback = lambda status: self.__failed_add_security_label(security_label_name)
ro.set_failure_callback(callback)
self._container._resource_container.add_commit_queue(self._container.id, ro)
security_label = SecurityLabelObject()
security_label.set_name(security_label_name)
self.__add_security_label(security_label)
示例3: upload
def upload(self, body):
""" upload batch job """
prop = self._resource_properties['batch_job_upload']
ro = RequestObject()
ro.set_body(body)
ro.set_content_type('application/octet-stream')
ro.set_description('upload batch job for "{0}"'.format(self._id))
ro.set_http_method(prop['http_method'])
ro.set_owner_allowed(prop['owner_allowed'])
ro.set_request_uri(prop['uri'].format(self._id))
ro.set_resource_pagination(prop['pagination'])
ro.set_resource_type(self._resource_type)
ro.empty_payload()
self._resource_container.add_commit_queue(self.id, ro)
示例4: load_tags
def load_tags(self):
""" retrieve tags for this victim """
prop = self._resource_properties['tags_load']
ro = RequestObject()
ro.set_description('load tags for {0}'.format(self._name))
ro.set_http_method(prop['http_method'])
ro.set_owner(self.owner_name)
ro.set_owner_allowed(prop['owner_allowed'])
ro.set_request_uri(prop['uri'].format(self._id))
ro.set_resource_pagination(prop['pagination'])
ro.set_resource_type(self._resource_type)
api_response = self._tc.api_request(ro)
if api_response.headers['content-type'] == 'application/json':
api_response_dict = api_response.json()
if api_response_dict['status'] == 'Success':
data = api_response_dict['data']['tag']
for item in data:
self._resource_obj.add_tag(parse_tag(item)) # add to main resource object
示例5: update_attribute
def update_attribute(self, attr_id, attr_value):
""" update victim attribute by id """
prop = self._resource_properties['attribute_update']
ro = RequestObject()
ro.set_body(json.dumps({'value': attr_value}))
ro.set_description('update attribute id {0} with value "{1}" on "{2}"'.format(
attr_id, attr_value, self._name))
ro.set_http_method(prop['http_method'])
ro.set_owner_allowed(prop['owner_allowed'])
ro.set_request_uri(prop['uri'].format(self._id, attr_id))
ro.set_resource_pagination(prop['pagination'])
ro.set_resource_type(self._resource_type)
self._resource_container.add_commit_queue(self.id, ro)
示例6: delete_tag
def delete_tag(self, tag):
""" delete tag from victim """
prop = self._resource_properties['tag_delete']
ro = RequestObject()
ro.set_description('delete tag "{0}" from "{1}"'.format(tag, self._name))
ro.set_http_method(prop['http_method'])
ro.set_owner_allowed(prop['owner_allowed'])
ro.set_request_uri(prop['uri'].format(
self._id, self._urlsafe(tag)))
ro.set_resource_pagination(prop['pagination'])
ro.set_resource_type(self._resource_type)
self._resource_container.add_commit_queue(self.id, ro)
示例7: indicator_associations
def indicator_associations(self):
""" retrieve associations for this victim. associations are not stored within the object """
prop = self._resource_properties['association_indicators']
ro = RequestObject()
ro.set_description('retrieve indicator associations for {0}'.format(self._name))
ro.set_http_method(prop['http_method'])
# ro.set_owner(self.owner_name)
ro.set_owner_allowed(prop['owner_allowed'])
ro.set_request_uri(prop['uri'].format(self._id))
ro.set_resource_pagination(prop['pagination'])
ro.set_resource_type(self._resource_type)
for item in self._tc.result_pagination(ro, 'indicator'):
yield threatconnect.IndicatorObject.parse_indicator(
item, api_filter=ro.description, request_uri=ro.request_uri)
示例8: add_id
def add_id(self, data_int):
""" """
# validation of data input
if not isinstance(data_int, int):
raise AttributeError(ErrorCodes.e4030.value.format(data_int))
prop = self._resource_properties['id']
ro = RequestObject()
ro.set_description('api filter by id {0}'.format(data_int))
ro.set_http_method(prop['http_method'])
ro.set_owner_allowed(prop['owner_allowed'])
ro.set_request_uri(prop['uri'], [data_int])
ro.set_resource_pagination(prop['pagination'])
ro.set_resource_type(self._resource_type)
self._add_request_objects(ro)
示例9: add_indicator
def add_indicator(self, data):
""" filter api results by indicator """
# validation indicator
if not SharedMethods.validate_indicator(self.tc._indicators_regex, data):
raise AttributeError(ErrorCodes.e5010.value.format(data))
# get indicator uri attribute
indicator_type = SharedMethods.get_resource_type(self.tc._indicators_regex, data)
indicator_uri_attribute = ApiProperties.api_properties[indicator_type.name]['uri_attribute']
prop = self._resource_properties['indicators']
ro = RequestObject()
ro.set_description('api filter by indicator id {0}'.format(data))
ro.set_owner_allowed(prop['owner_allowed'])
ro.set_request_uri(prop['uri'], [indicator_uri_attribute, SharedMethods.urlsafe(data)])
ro.set_resource_pagination(prop['pagination'])
ro.set_resource_type(self._resource_type)
self._add_request_objects(ro)
示例10: associate_victim
def associate_victim(self, resource_id):
""" associate victim from group """
prop = self._resource_properties['association_victim_add']
ro = RequestObject()
ro.set_description('associate victim id {0} from "{1}"'.format(
resource_id, self._name))
ro.set_http_method(prop['http_method'])
ro.set_owner_allowed(prop['owner_allowed'])
ro.set_request_uri(prop['uri'].format(
self._id, resource_id))
ro.set_resource_pagination(prop['pagination'])
ro.set_resource_type(self._resource_type)
self._resource_container.add_commit_queue(self.id, ro)
示例11: commit
def commit(self):
# phase 0 (no action) -> don't validate and don't POST group, only POST items in commit queue.
# phase 1 (add) -> validate before POST group, only POST items in commit queue if group POST succeeded.
# phase 2 (update) -> don't validate before PUT group, POST/PUT items in commit queue.
""" commit group and related associations, attributes, security labels and tags """
r_id = self.id
ro = RequestObject()
ro.set_body(self.gen_body)
if self.owner_name is not None:
ro.set_owner(self.owner_name)
ro.set_resource_type(self.resource_type)
if self.phase == 1:
prop = self._resource_properties['add']
ro.set_description('adding group "{0}".'.format(self._name))
ro.set_http_method(prop['http_method'])
ro.set_owner_allowed(prop['owner_allowed'])
ro.set_request_uri(prop['uri'].format(self._id))
ro.set_resource_pagination(prop['pagination'])
if self.validate:
api_response = self._tc.api_request(ro)
if api_response.headers['content-type'] == 'application/json':
api_response_dict = api_response.json()
if api_response_dict['status'] == 'Success':
resource_key = ApiProperties.api_properties[self.resource_type.name]['resource_key']
r_id = api_response_dict['data'][resource_key]['id']
else:
self._tc.tcl.debug('Resource Object'.format(self))
raise AttributeError(ErrorCodes.e10040.value)
elif self.phase == 2:
prop = self._resource_properties['update']
ro.set_description('update group "{0}".'.format(self._name))
ro.set_http_method(prop['http_method'])
ro.set_owner_allowed(prop['owner_allowed'])
ro.set_request_uri(prop['uri'].format(self._id))
ro.set_resource_pagination(prop['pagination'])
api_response = self._tc.api_request(ro)
if api_response.headers['content-type'] == 'application/json':
api_response_dict = api_response.json()
if api_response_dict['status'] != 'Success':
self._tc.tcl.error('API Request Failure: [{0}]'.format(ro.description))
# validate all required fields are present
if r_id is not None:
#
# commit all associations, attributes, tags, etc
#
for ro in self._resource_container.commit_queue(self.id):
if self.owner_name is not None:
ro.set_owner(self.owner_name)
# replace the id
if self.phase == 1 and self.id != r_id:
request_uri = str(ro.request_uri.replace(str(self.id), str(r_id)))
ro.set_request_uri(request_uri)
self._tc.tcl.debug('Replacing {0} with {1}'.format(self.id, str(r_id)))
api_response2 = self._tc.api_request(ro)
if 'content-type' in api_response2.headers:
if api_response2.headers['content-type'] == 'application/json':
api_response_dict2 = api_response2.json()
if api_response_dict2['status'] != 'Success':
self._tc.tcl.error('API Request Failure: [{0}]'.format(ro.description))
else:
if ro.success_callback is not None:
ro.success_callback(ro, api_response2)
elif api_response2.headers['content-type'] == 'application/octet-stream':
if api_response2.status_code in [200, 201, 202]:
self.set_contents(ro.body)
if ro.success_callback is not None:
ro.success_callback(ro, api_response2)
else:
# upload PUT response
if api_response2.status_code in [200, 201, 202]:
self.set_contents(ro.body)
if ro.success_callback is not None:
ro.success_callback(ro, api_response2)
# clear the commit queue
self._resource_container.clear_commit_queue_id(self.id)
self.set_id(r_id)
# clear phase
self.set_phase(0)
if self._reload_attributes:
self.load_attributes(automatically_reload=True)
# return object
return self
示例12: associate_indicator
def associate_indicator(self, indicator_type, indicator):
""" associate a indicator to group by id """
prop = self._resource_properties['association_indicator_add']
ro = RequestObject()
ro.set_description('associate indicator {0} to "{1}"'.format(
indicator, self._name))
ro.set_http_method(prop['http_method'])
ro.set_owner_allowed(prop['owner_allowed'])
ro.set_resource_pagination(prop['pagination'])
indicator_uri_attribute = ApiProperties.api_properties[indicator_type.name]['uri_attribute']
ro.set_request_uri(prop['uri'].format(indicator_uri_attribute, self._urlsafe(indicator), self.id))
ro.set_resource_type(self._resource_type)
self._resource_container.add_commit_queue(self.id, ro)
示例13: add_tag
def add_tag(self, tag):
""" add a tag to an group """
prop = self._resource_properties['tag_add']
ro = RequestObject()
ro.set_description('add tag "{0}" to "{1}"'.format(tag, self._name))
ro.set_http_method(prop['http_method'])
ro.set_owner_allowed(prop['owner_allowed'])
ro.set_request_uri(prop['uri'].format(self._id, self._urlsafe(tag)))
ro.set_resource_pagination(prop['pagination'])
ro.set_resource_type(self._resource_type)
self._resource_container.add_commit_queue(self.id, ro)
示例14: victim_associations
def victim_associations(self):
""" retrieve associations for this group. associations are not stored within the object """
prop = self._resource_properties['association_victims']
ro = RequestObject()
ro.set_description('retrieve victim associations for {0}'.format(self._name))
ro.set_http_method(prop['http_method'])
ro.set_owner_allowed(prop['owner_allowed'])
ro.set_owner(self.owner_name)
ro.set_request_uri(prop['uri'].format(self._id))
ro.set_resource_pagination(prop['pagination'])
ro.set_resource_type(self._resource_type)
for item in self._tc.result_pagination(ro, 'victim'):
yield VictimObject.parse_victim(item, api_filter=ro.description, request_uri=ro.request_uri)
示例15: delete_attribute
def delete_attribute(self, attr_id):
""" delete attribute from victim by id """
prop = self._resource_properties['attribute_delete']
ro = RequestObject()
ro.set_description('delete attribute id {0} from "{1}"'.format(attr_id, self._name))
ro.set_http_method(prop['http_method'])
ro.set_owner_allowed(prop['owner_allowed'])
ro.set_request_uri(prop['uri'].format(
self._id, attr_id))
ro.set_resource_pagination(prop['pagination'])
ro.set_resource_type(self._resource_type)
self._resource_container.add_commit_queue(self.id, ro)