def add_attribute(self, attr_type, attr_value, attr_displayed='true'): """ add an attribute to an indicator """ attr_type = uni(attr_type) attr_value = uni(attr_value) ro = self._create_basic_request_object('attribute_add') ro.set_body( json.dumps({ 'type': attr_type, 'value': attr_value, 'displayed': attr_displayed })) try: ro.set_description( 'add attribute type "{0}" with value "{1}" to {2}'.format( attr_type, attr_value.encode('ascii', 'ignore'), self._reference_indicator.encode('utf-8', 'ignore'))) except: ro.set_description( 'add attribute type "{0}" with value "unencodable" to {1}'. format(attr_type, self._reference_indicator.encode('utf-8', 'ignore'))) callback = lambda status: self.__add_attribute_failure( attr_type, attr_value) ro.set_failure_callback(callback) self._resource_container.add_commit_queue(self.id, ro) attribute = AttributeObject(self) attribute.set_type(attr_type) attribute.set_value(attr_value) attribute.set_displayed(attr_displayed) self._resource_obj.add_attribute(attribute)
def set_custom_fields(self, data): if self.resource_type == ResourceType.CUSTOM_INDICATORS: # data = data if isinstance(data, list) else [data] if isinstance(self._custom_fields, OrderedDict): self._custom_fields = uni(data) else: raise AttributeError(ErrorCodes.e10100.value)
def set_whois_active(self, data, update=True): """ """ if self._resource_type == ResourceType.HOSTS: self._whois_active = uni(data) else: raise AttributeError(ErrorCodes.e10140.value) if update and self._phase == 0: self._phase = 2
def set_size(self, data, update=True): """ """ if self._resource_type == ResourceType.FILES: self._size = uni(str(data)) else: raise AttributeError(ErrorCodes.e10130.value) if update and self._phase == 0: self._phase = 2
def update_attribute(self, attr_id, attr_value): """ update indicator attribute by id """ ro = self._create_basic_request_object('attribute_update', attr_id) attr_value = uni(attr_value) ro.set_body(json.dumps({'value': attr_value})) try: ro.set_description( 'update attribute id {0} with value "{1}" on {2}'.format( attr_id, attr_value, self._reference_indicator)) except: ro.set_description( 'update attribute id {0} with value "unencodable" on {1}'. format(attr_id, self._reference_indicator)) self._resource_container.add_commit_queue(self.id, ro)
def set_weblink(self, data): """ """ self._weblink = uni(data)
def set_type(self, data): """ """ self._type = uni(data) self._resource_type = get_resource_indicator_type(self._type)
def set_source(self, data, update=True): """ """ self._source = uni(data) if update and self._phase == 0: self._phase = 2
def set_owner_name(self, data): """Read-Only indicator metadata""" self._owner_name = uni(data)
def set_name(self, name): self._name = uni(name)
def set_indicator(self, data, resource_type=None, update=True): """Read-Write indicator metadata""" _type = self.resource_type if self.resource_type is not None else resource_type if _type == ResourceType.ADDRESSES: self._ip = uni(data) self._reference_indicator = urlsafe(self._ip) # additional resource type specific attributes self._properties['_ip'] = { 'api_field': 'ip', 'method': 'set_indicator', 'required': True, } elif _type == ResourceType.EMAIL_ADDRESSES: self._address = uni(data) self._reference_indicator = urlsafe(self._address) # additional resource type specific attributes self._properties['_address'] = { 'api_field': 'address', 'method': 'set_indicator', 'required': True, } elif _type == ResourceType.FILES: # handle different hash type hash_type = get_hash_type(data) if hash_type == 'MD5': self._md5 = data if self._reference_indicator is None: # reference indicator for attr, tag, etc adds self._reference_indicator = urlsafe(self._md5) elif hash_type == 'SHA1': self._sha1 = data if self._reference_indicator is None: # reference indicator for attr, tag, etc adds self._reference_indicator = urlsafe(self._sha1) elif hash_type == 'SHA256': self._sha256 = data if self._reference_indicator is None: # reference indicator for attr, tag, etc adds self._reference_indicator = urlsafe(self._sha256) self._properties['_md5'] = { 'api_field': 'md5', 'method': 'set_indicator', 'required': True, } self._properties['_sha1'] = { 'api_field': 'sha1', 'method': 'set_indicator', 'required': True, } self._properties['_sha256'] = { 'api_field': 'sha256', 'method': 'set_indicator', 'required': True, } self._properties['_size'] = { 'api_field': 'size', 'method': 'set_size', 'required': False, } if update and self._phase == 0: self._phase = 2 elif _type == ResourceType.HOSTS: self._hostname = uni(data) self._reference_indicator = urlsafe(self._hostname) # additional resource type specific attributes self._properties['_hostname'] = { 'api_field': 'hostName', 'method': 'set_indicator', 'required': True, } self._properties['_dns_active'] = { 'api_field': 'dnsActive', 'method': 'set_dns_active', 'required': False, } self._properties['_whois_active'] = { 'api_field': 'whoisActive', 'method': 'set_whois_active', 'required': False, } elif _type == ResourceType.URLS: self._text = uni(data) self._reference_indicator = urlsafe(self._text) # additional resource type specific attributes self._properties['_text'] = { 'api_field': 'text', 'method': 'set_indicator', 'required': True, } elif _type == ResourceType.CUSTOM_INDICATORS: # make sure they're in the right order if not isinstance(data, OrderedDict): raise AttributeError("Custom Indicator must be an OrderedDict") self._custom_fields = uni(data) self._reference_indicator = urlsafe(' : '.join( self._custom_fields.values())) # additional resource type specific attributes self._properties['_custom_fields'] = { 'api_field': self.api_entity, 'method': 'set_indicator', 'required': True, }
def set_description(self, data, update=True): """Read-Write indicator metadata""" self._description = uni(data) if update and self._phase == 0: self._phase = 2
def set_custom_type(self, data): if self.resource_type == ResourceType.CUSTOM_INDICATORS: self._custom_type = uni(data) else: raise AttributeError(ErrorCodes.e10100.value)