def add_indicator(self, data, indicator_type=None): """ 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 if indicator_type is None: 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['indicator'] ro = RequestObject() ro.set_description('api filter by indicator id {0}'.format(data)) ro.set_owner_allowed(prop['owner_allowed']) # TODO: Check this logic if self._resource_type == ResourceType.INDICATORS: ro.set_request_uri( prop['uri'], [indicator_uri_attribute, SharedMethods.urlsafe(data)]) else: ro.set_request_uri(prop['uri'], [SharedMethods.urlsafe(data)]) ro.set_resource_pagination(prop['pagination']) ro.set_resource_type(indicator_type) self._add_request_objects(ro)
def add_indicator(self, data, indicator_type = None): """ 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 if indicator_type is None: 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['indicator'] ro = RequestObject() ro.set_description('api filter by indicator id {0}'.format(data)) ro.set_owner_allowed(prop['owner_allowed']) # TODO: Check this logic if self._resource_type == ResourceType.INDICATORS: ro.set_request_uri(prop['uri'], [indicator_uri_attribute, SharedMethods.urlsafe(data)]) else: ro.set_request_uri(prop['uri'], [SharedMethods.urlsafe(data)]) ro.set_resource_pagination(prop['pagination']) ro.set_resource_type(indicator_type) self._add_request_objects(ro)
def add(self, indicator, owner=None, type=None, api_entity=None): """ add indicator to resource container """ if type is not None: if isinstance(type, IndicatorType): if type == IndicatorType.CUSTOM_INDICATORS and not isinstance(indicator, OrderedDict): # change dicts to be Ordered before calling set_indicator field_names = self.tc.indicator_parser.get_field_labels_by_api_entity(api_entity) ordered_indicator = OrderedDict() for field_name in field_names: ordered_indicator[field_name] = indicator.get(field_name) indicator = ordered_indicator # generate unique temporary id resource_id = uuid.uuid4().int # resource object resource_obj = self.tc.indicator_parser.construct_typed_indicator(ResourceType(type.value), api_entity=api_entity) resource_obj.set_id(int(resource_id)) # set temporary resource id resource_obj.set_indicator(indicator, ResourceType(type.value), False) resource_obj.set_owner_name(owner) resource_obj.set_phase(1) # set resource api phase (1 = add) return self._method_wrapper(resource_obj) else: raise AttributeError(ErrorCodes.e10060.name.format(indicator)) elif SharedMethods.validate_indicator(self.tc._indicators_regex, indicator): # validate indicator # generate unique temporary id resource_id = uuid.uuid4().int resource_type = get_resource_type(self.tc._indicators_regex, indicator) # resource object resource_obj = self.tc.indicator_parser.construct_typed_indicator(resource_type) resource_obj.set_id(int(resource_id)) # set temporary resource id resource_obj.set_indicator(indicator, resource_type, False) resource_obj.set_owner_name(owner) resource_obj.set_phase(1) # set resource api phase (1 = add) # return object for modification return self._method_wrapper(resource_obj) else: raise AttributeError(ErrorCodes.e10050.name.format(indicator))
def add_indicator(self, data): """ """ # validation indicator if not SharedMethods.validate_indicator(data): raise AttributeError(ErrorCodes.e5010.value.format(data)) # get indicator uri attribute indicator_type = SharedMethods.get_resource_type(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)
def add_indicator(self, data): """ """ # 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)
def add(self, indicator, owner=None, type=None): """ add indicator to resource container """ if type is not None: if isinstance(type, IndicatorType): # generate unique temporary id resource_id = uuid.uuid4().int # resource object resource_obj = IndicatorObject() resource_obj.set_id(int(resource_id)) # set temporary resource id # resource_obj.set_resource_type(ResourceType(type.value)) # set this before indicator resource_obj.set_indicator(indicator, ResourceType(type.value), False) resource_obj.set_owner_name(owner) resource_obj.set_phase(1) # set resource api phase (1 = add) # return object for modification return self._method_wrapper(resource_obj) else: raise AttributeError(ErrorCodes.e10060.name.format(indicator)) elif SharedMethods.validate_indicator(self.tc._indicators_regex, indicator): # validate indicator # generate unique temporary id resource_id = uuid.uuid4().int # resource object resource_obj = IndicatorObject() resource_obj.set_id(int(resource_id)) # set temporary resource id resource_type = get_resource_type(self.tc._indicators_regex, indicator) resource_obj.set_indicator(indicator, resource_type, False) resource_obj.set_owner_name(owner) resource_obj.set_phase(1) # set resource api phase (1 = add) # return object for modification return self._method_wrapper(resource_obj) else: raise AttributeError(ErrorCodes.e10050.name.format(indicator))