本文整理汇总了Python中threatconnect.RequestObject.RequestObject.set_resource_object_id方法的典型用法代码示例。如果您正苦于以下问题:Python RequestObject.set_resource_object_id方法的具体用法?Python RequestObject.set_resource_object_id怎么用?Python RequestObject.set_resource_object_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类threatconnect.RequestObject.RequestObject
的用法示例。
在下文中一共展示了RequestObject.set_resource_object_id方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add
# 需要导入模块: from threatconnect.RequestObject import RequestObject [as 别名]
# 或者: from threatconnect.RequestObject.RequestObject import set_resource_object_id [as 别名]
def add(self, resource_name):
"""add resource using writable api"""
# switch any multiple resource request to single result request
if self._resource_type.value % 10:
self._resource_type = ResourceType(self._resource_type.value - 5)
# get properties for the object
properties = ResourceProperties[self._resource_type.name].value(
base_uri=self._tc.base_uri, http_method=PropertiesAction.POST)
# generate unique temporary id
resource_id = uuid.uuid4().int
# resource object
resource_object = properties.resource_object
# set resource id
resource_object.set_id(resource_id)
# set resource name
resource_object.set_name(resource_name)
# set resource api action
resource_object.set_phase('add')
# build request object
request_object = RequestObject(self._resource_type.name, resource_id)
request_object.set_description(
'Adding {0} resource ({1})'.format(self._resource_type.name.lower(), resource_name))
request_object.set_http_method(properties.http_method)
request_object.set_request_uri(properties.post_path)
request_object.set_owner_allowed(True)
request_object.set_resource_pagination(False)
request_object.set_resource_type(self._resource_type)
# add to temporary object storage
self.add_master_resource_obj(resource_object, resource_id)
res = self.get_resource_by_id(resource_id)
request_object.set_resource_object_id(id(res))
res.set_request_object(request_object)
# add resource object to parent object
self.add_obj(res)
# return object for modification
return res
示例2: add
# 需要导入模块: from threatconnect.RequestObject import RequestObject [as 别名]
# 或者: from threatconnect.RequestObject.RequestObject import set_resource_object_id [as 别名]
def add(self, file_hash):
""" """
# set properties
properties = FileOccurrencesProperties(
base_uri=self.base_uri, http_method=PropertiesAction.POST)
# generate unique temporary id
resource_id = uuid.uuid4().int
# resource object
resource_object = properties.resource_object
# set resource id
resource_object.set_id(resource_id)
# set resource api action
resource_object.set_phase('add')
# build request object
request_object = RequestObject(self._resource_type.name, resource_id)
request_object.set_description(
'Adding file occurrence for file hash {0}'.format(file_hash))
request_object.set_http_method(properties.http_method)
request_object.set_request_uri(properties.post_path.format(file_hash))
request_object.set_owner_allowed(True)
request_object.set_resource_pagination(False)
request_object.set_resource_type(self._resource_type)
# add to temporary object storage
self.add_master_resource_obj(resource_object, resource_id)
res = self.get_resource_by_id(resource_id)
request_object.set_resource_object_id(id(res))
res.set_request_object(request_object)
# add resource object to parent object
self.add_obj(res)
# return object for modification
return res
示例3: add
# 需要导入模块: from threatconnect.RequestObject import RequestObject [as 别名]
# 或者: from threatconnect.RequestObject.RequestObject import set_resource_object_id [as 别名]
def add(self, indicator):
""" """
# indicator set method
indicator_set_methods = {
'ADDRESS': 'set_ip',
'EMAIL_ADDRESS': 'set_address',
'MD5': 'set_md5',
'SHA1': 'set_sha1',
'SHA256': 'set_sha256',
'HOST': 'set_hostname',
'URL': 'set_text'}
# validate indicator
if validate_indicator(indicator):
# get indicator type
resource_type = get_resource_type(indicator)
# get properties for the object
if resource_type.value % 10:
resource_type = ResourceType(resource_type.value - 5)
properties = ResourceProperties[resource_type.name].value(http_method=PropertiesAction.POST)
# generate unique temporary id
resource_id = uuid.uuid4().int
# resource object
resource_object = properties.resource_object
# set resource id
resource_object.set_id(resource_id)
# set indicator
if resource_type == ResourceType.FILE:
set_method_name = indicator_set_methods[get_hash_type(indicator)]
else:
set_method_name = indicator_set_methods[resource_type.name]
# if resource_type == ResourceType.URL:
# set_indicator = urllib.quote(indicator, safe='~')
# else:
# set_indicator = indicator
set_method = getattr(resource_object, set_method_name)
set_method(indicator)
# set resource api action
resource_object.set_phase('add')
# build request object
request_object = RequestObject(self._resource_type.name, indicator)
request_object.set_description(
'Adding indicator ({0}).'.format(indicator))
request_object.set_http_method(properties.http_method)
request_object.set_request_uri(properties.post_path)
request_object.set_owner_allowed(True)
request_object.set_resource_pagination(False)
request_object.set_resource_type(resource_type)
# add to temporary object storage
roi = self.add_master_resource_obj(resource_object, resource_id)
res = self.get_resource_by_identity(roi)
request_object.set_resource_object_id(id(res))
res.set_request_object(request_object)
# add resource object to parent object
self.add_obj(res)
# return object for modification
return res
else:
print('({0}) is an invalid indicator.'.format(indicator))
return None